diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 12eec99e7d22b..6c3fc987d9add 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5015,18 +5015,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I, } } - // (icmp eq/ne (X, -P2), INT_MIN) - // -> (icmp slt/sge X, INT_MIN + P2) - if (ICmpInst::isEquality(Pred) && BO0 && - match(I.getOperand(1), m_SignMask()) && - match(BO0, m_And(m_Value(), m_NegatedPower2OrZero()))) { - // Will Constant fold. - Value *NewC = Builder.CreateSub(I.getOperand(1), BO0->getOperand(1)); - return new ICmpInst(Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_SLT - : ICmpInst::ICMP_SGE, - BO0->getOperand(0), NewC); - } - { // Similar to above: an unsigned overflow comparison may use offset + mask: // ((Op1 + C) & C) u< Op1 --> Op1 != 0 diff --git a/llvm/test/Transforms/InstCombine/icmp-signmask.ll b/llvm/test/Transforms/InstCombine/icmp-signmask.ll index 5424f7d7e8021..bea8da2074ab0 100644 --- a/llvm/test/Transforms/InstCombine/icmp-signmask.ll +++ b/llvm/test/Transforms/InstCombine/icmp-signmask.ll @@ -3,7 +3,8 @@ define i1 @cmp_x_and_negp2_with_eq(i8 %x) { ; CHECK-LABEL: @cmp_x_and_negp2_with_eq( -; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], -126 +; CHECK-NEXT: [[ANDX:%.*]] = and i8 [[X:%.*]], -2 +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ANDX]], -128 ; CHECK-NEXT: ret i1 [[R]] ; %andx = and i8 %x, -2 @@ -24,7 +25,8 @@ define i1 @cmp_x_and_negp2_with_eq_fail_not_signmask(i8 %x) { define <2 x i1> @cmp_x_and_negp2_with_ne(<2 x i8> %x) { ; CHECK-LABEL: @cmp_x_and_negp2_with_ne( -; CHECK-NEXT: [[R:%.*]] = icmp sgt <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], ; CHECK-NEXT: ret <2 x i1> [[R]] ; %andx = and <2 x i8> %x, @@ -34,7 +36,8 @@ define <2 x i1> @cmp_x_and_negp2_with_ne(<2 x i8> %x) { define <2 x i1> @cmp_x_and_negp2_with_ne_or_z(<2 x i8> %x) { ; CHECK-LABEL: @cmp_x_and_negp2_with_ne_or_z( -; CHECK-NEXT: [[R:%.*]] = icmp sge <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], ; CHECK-NEXT: ret <2 x i1> [[R]] ; %andx = and <2 x i8> %x, diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index 17ed64b6e04d9..ecf21b8a42cf5 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -1116,7 +1116,8 @@ define i1 @test53(i32 %a, i32 %b) { define i1 @test54(i8 %a) { ; CHECK-LABEL: @test54( -; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[A:%.*]], -64 +; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A:%.*]], -64 +; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP1]], -128 ; CHECK-NEXT: ret i1 [[RET]] ; %ext = zext i8 %a to i32