diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -4350,9 +4350,6 @@ // Cannot do anything for any other EFLAG changes. return false; } - - if (Inst.readsRegister(X86::EFLAGS, TRI)) - return false; } if (MI || Sub) diff --git a/llvm/test/CodeGen/X86/optimize-compare.mir b/llvm/test/CodeGen/X86/optimize-compare.mir --- a/llvm/test/CodeGen/X86/optimize-compare.mir +++ b/llvm/test/CodeGen/X86/optimize-compare.mir @@ -151,3 +151,23 @@ CMP32rr %1, %0, implicit-def $eflags $bl = SETCCr 3, implicit $eflags ... +--- +name: opt_redundant_flags_2 +body: | + bb.0: + ; CHECK-LABEL: name: opt_redundant_flags_2 + ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi + ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags + ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags + ; CHECK-NEXT: $eax = COPY [[SUB32rr]] + ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags + %0:gr32 = COPY $esi + %1:gr32 = COPY $edi + %2:gr32 = SUB32rr %0, %1, implicit-def $eflags + ; an extra eflags reader shouldn't stop optimization. + $cl = SETCCr 2, implicit $eflags + $eax = COPY %2 + CMP32rr %0, %1, implicit-def $eflags + $bl = SETCCr 2, implicit $eflags +...