Skip to content

Commit 574266c

Browse files
authored
Revert "[InstCombine] Folding (icmp eq/ne (and X, -P2), INT_MIN)" (#111236)
Reverts #110880 because of exposed issue is Msan instrumentation #111212. This reverts commit a646436.
1 parent f6fd7b2 commit 574266c

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5015,18 +5015,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
50155015
}
50165016
}
50175017

5018-
// (icmp eq/ne (X, -P2), INT_MIN)
5019-
// -> (icmp slt/sge X, INT_MIN + P2)
5020-
if (ICmpInst::isEquality(Pred) && BO0 &&
5021-
match(I.getOperand(1), m_SignMask()) &&
5022-
match(BO0, m_And(m_Value(), m_NegatedPower2OrZero()))) {
5023-
// Will Constant fold.
5024-
Value *NewC = Builder.CreateSub(I.getOperand(1), BO0->getOperand(1));
5025-
return new ICmpInst(Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_SLT
5026-
: ICmpInst::ICMP_SGE,
5027-
BO0->getOperand(0), NewC);
5028-
}
5029-
50305018
{
50315019
// Similar to above: an unsigned overflow comparison may use offset + mask:
50325020
// ((Op1 + C) & C) u< Op1 --> Op1 != 0

llvm/test/Transforms/InstCombine/icmp-signmask.ll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
define i1 @cmp_x_and_negp2_with_eq(i8 %x) {
55
; CHECK-LABEL: @cmp_x_and_negp2_with_eq(
6-
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], -126
6+
; CHECK-NEXT: [[ANDX:%.*]] = and i8 [[X:%.*]], -2
7+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ANDX]], -128
78
; CHECK-NEXT: ret i1 [[R]]
89
;
910
%andx = and i8 %x, -2
@@ -24,7 +25,8 @@ define i1 @cmp_x_and_negp2_with_eq_fail_not_signmask(i8 %x) {
2425

2526
define <2 x i1> @cmp_x_and_negp2_with_ne(<2 x i8> %x) {
2627
; CHECK-LABEL: @cmp_x_and_negp2_with_ne(
27-
; CHECK-NEXT: [[R:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -121, i8 -113>
28+
; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 -8, i8 -16>
29+
; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], <i8 -128, i8 -128>
2830
; CHECK-NEXT: ret <2 x i1> [[R]]
2931
;
3032
%andx = and <2 x i8> %x, <i8 -8, i8 -16>
@@ -34,7 +36,8 @@ define <2 x i1> @cmp_x_and_negp2_with_ne(<2 x i8> %x) {
3436

3537
define <2 x i1> @cmp_x_and_negp2_with_ne_or_z(<2 x i8> %x) {
3638
; CHECK-LABEL: @cmp_x_and_negp2_with_ne_or_z(
37-
; CHECK-NEXT: [[R:%.*]] = icmp sge <2 x i8> [[X:%.*]], <i8 -128, i8 -112>
39+
; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 0, i8 -16>
40+
; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], <i8 -128, i8 -128>
3841
; CHECK-NEXT: ret <2 x i1> [[R]]
3942
;
4043
%andx = and <2 x i8> %x, <i8 0, i8 -16>

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,8 @@ define i1 @test53(i32 %a, i32 %b) {
11161116

11171117
define i1 @test54(i8 %a) {
11181118
; CHECK-LABEL: @test54(
1119-
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[A:%.*]], -64
1119+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A:%.*]], -64
1120+
; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP1]], -128
11201121
; CHECK-NEXT: ret i1 [[RET]]
11211122
;
11221123
%ext = zext i8 %a to i32

0 commit comments

Comments
 (0)