diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2690,6 +2690,9 @@ return nullptr; // A boolean compared to true/false can be simplified in 14 out of the 20 + + Value *X; + // (10 predicates * 2 constants) possible combinations. Cases not handled here // require a 'not' of the LHS, so those must be transformed in InstCombine. if (match(RHS, m_Zero())) { @@ -2699,6 +2702,13 @@ case CmpInst::ICMP_SLT: // X X return LHS; + case CmpInst::ICMP_EQ: + // (X ^ 1) == 0 -> X + if (match(LHS, m_Xor(m_Value(X), m_One()))) { + return X; + } + break; + case CmpInst::ICMP_ULT: // X false case CmpInst::ICMP_SGT: // X >s 0 -> false return getFalse(ITy); diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll --- a/llvm/test/Transforms/InstSimplify/icmp.ll +++ b/llvm/test/Transforms/InstSimplify/icmp.ll @@ -186,6 +186,16 @@ ret i1 %cmp } +define i1 @not_cmp_equal(i1 %x) { +; CHECK-LABEL: @not_cmp_equal( +; CHECK-NEXT: ret i1 %x +; + %not = xor i1 %x, true + %t0 = sext i1 %not to i32 + %cmp = icmp eq i32 %t0, 0 + ret i1 %cmp +} + ; Don't crash matching recurrences/invertible ops. define void @PR50191(i32 %x) {