Small repro here: https://godbolt.org/z/xPPGMv 11.0 and trunk both produce the "cmp edx, ecx" / "seta cl" / "test cl, 1" / "jne label" construction that serves no purpose I can discern; 10.0.1 and earlier used the expected "cmp edx, ecx" / "ja label". This function makes for a particularly simple reproducer but we're seeing instances of this in many places in our code base.
I think this has something to do with a freeze instruction being inserted in CodeGenPrepare.
Yes, it is due to CodeGenPrepare's select cond -> br freeze(cond): ``` %cmp = icmp ugt i32 %math, %1 %cond = select i1 %ov, i32 %0, i32 %1 %x.addr.0.frozen = freeze i1 %cmp br i1 %x.addr.0.frozen, label %select.end, label %select.false, !prof !7 select.false: ; preds = %entry br label %select.end select.end: ; preds = %entry, %select.false %x.addr.0 = phi i32 [ %cond, %entry ], [ %x, %select.false ] ret i32 %x.addr.0 ``` After X86 DAG->DAG Instruction Selection, it becomes: ``` bb.0.entry: ... %12:gr8 = SETCCr 7, implicit $eflags %13:gr8 = COPY killed %12:gr8 TEST8ri killed %13:gr8, 1, implicit-def $eflags JCC_1 %bb.2, 5, implicit $eflags JMP_1 %bb.1 ``` Without freeze: ``` ... JCC_1 %bb.2, 7, implicit $eflags JMP_1 %bb.1 ``` I'm seeing whether it can be addressed at instruction selection level.
Any progress?
The patch link is here: https://reviews.llvm.org/D92015
Should be fixed now