Skip to content

Commit 541ec50

Browse files
committed
computeConstantRange() based sharpening
1 parent 9ca9c2c commit 541ec50

File tree

11 files changed

+158
-115
lines changed

11 files changed

+158
-115
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,74 +1364,74 @@ Instruction *InstCombinerImpl::foldICmpWithConstant(ICmpInst &Cmp) {
13641364

13651365
/// Canonicalize icmp instructions based on dominating conditions.
13661366
Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) {
1367+
// We already checked simple implication in InstSimplify, only handle complex
1368+
// cases here.
1369+
const APInt *C;
1370+
if (!match(Cmp.getOperand(1), m_APInt(C)))
1371+
return nullptr;
1372+
1373+
CmpInst::Predicate Pred = Cmp.getPredicate();
1374+
ConstantRange CR = ConstantRange::makeExactICmpRegion(Pred, *C);
1375+
1376+
Value *X = Cmp.getOperand(0);
1377+
ConstantRange InputCR = computeConstantRange(X, Cmp.isSigned());
1378+
13671379
// This is a cheap/incomplete check for dominance - just match a single
13681380
// predecessor with a conditional branch.
13691381
BasicBlock *CmpBB = Cmp.getParent();
13701382
BasicBlock *DomBB = CmpBB->getSinglePredecessor();
1371-
if (!DomBB)
1372-
return nullptr;
1373-
1374-
Value *DomCond;
1375-
BasicBlock *TrueBB, *FalseBB;
1376-
if (!match(DomBB->getTerminator(), m_Br(m_Value(DomCond), TrueBB, FalseBB)))
1377-
return nullptr;
1383+
if (DomBB) {
1384+
Value *DomCond;
1385+
BasicBlock *TrueBB, *FalseBB;
1386+
if (match(DomBB->getTerminator(),
1387+
m_Br(m_Value(DomCond), TrueBB, FalseBB))) {
1388+
assert((TrueBB == CmpBB || FalseBB == CmpBB) &&
1389+
"Predecessor block does not point to successor?");
1390+
1391+
// The branch should get simplified. Don't bother simplifying this
1392+
// condition.
1393+
if (TrueBB != FalseBB) {
1394+
ICmpInst::Predicate DomPred;
1395+
const APInt *DomC;
1396+
if (match(DomCond, m_ICmp(DomPred, m_Specific(X), m_APInt(DomC))))
1397+
InputCR = InputCR.intersectWith(
1398+
(CmpBB == TrueBB)
1399+
? ConstantRange::makeExactICmpRegion(DomPred, *DomC)
1400+
: ConstantRange::makeExactICmpRegion(
1401+
CmpInst::getInversePredicate(DomPred), *DomC));
1402+
}
1403+
}
1404+
}
13781405

1379-
assert((TrueBB == CmpBB || FalseBB == CmpBB) &&
1380-
"Predecessor block does not point to successor?");
1406+
ConstantRange Intersection = InputCR.intersectWith(CR);
1407+
ConstantRange Difference = InputCR.difference(CR);
1408+
if (Intersection.isEmptySet())
1409+
return replaceInstUsesWith(Cmp, Builder.getFalse());
1410+
if (Difference.isEmptySet())
1411+
return replaceInstUsesWith(Cmp, Builder.getTrue());
13811412

1382-
// The branch should get simplified. Don't bother simplifying this condition.
1383-
if (TrueBB == FalseBB)
1413+
// Canonicalizing a sign bit comparison that gets used in a branch,
1414+
// pessimizes codegen by generating branch on zero instruction instead
1415+
// of a test and branch. So we avoid canonicalizing in such situations
1416+
// because test and branch instruction has better branch displacement
1417+
// than compare and branch instruction.
1418+
bool UnusedBit;
1419+
bool IsSignBit = isSignBitCheck(Pred, *C, UnusedBit);
1420+
if (Cmp.isEquality() || (IsSignBit && hasBranchUse(Cmp)))
13841421
return nullptr;
13851422

1386-
// We already checked simple implication in InstSimplify, only handle complex
1387-
// cases here.
1388-
1389-
CmpInst::Predicate Pred = Cmp.getPredicate();
1390-
Value *X = Cmp.getOperand(0), *Y = Cmp.getOperand(1);
1391-
ICmpInst::Predicate DomPred;
1392-
const APInt *C, *DomC;
1393-
if (match(DomCond, m_ICmp(DomPred, m_Specific(X), m_APInt(DomC))) &&
1394-
match(Y, m_APInt(C))) {
1395-
// We have 2 compares of a variable with constants. Calculate the constant
1396-
// ranges of those compares to see if we can transform the 2nd compare:
1397-
// DomBB:
1398-
// DomCond = icmp DomPred X, DomC
1399-
// br DomCond, CmpBB, FalseBB
1400-
// CmpBB:
1401-
// Cmp = icmp Pred X, C
1402-
ConstantRange CR = ConstantRange::makeExactICmpRegion(Pred, *C);
1403-
ConstantRange DominatingCR =
1404-
(CmpBB == TrueBB) ? ConstantRange::makeExactICmpRegion(DomPred, *DomC)
1405-
: ConstantRange::makeExactICmpRegion(
1406-
CmpInst::getInversePredicate(DomPred), *DomC);
1407-
ConstantRange Intersection = DominatingCR.intersectWith(CR);
1408-
ConstantRange Difference = DominatingCR.difference(CR);
1409-
if (Intersection.isEmptySet())
1410-
return replaceInstUsesWith(Cmp, Builder.getFalse());
1411-
if (Difference.isEmptySet())
1412-
return replaceInstUsesWith(Cmp, Builder.getTrue());
1413-
1414-
// Canonicalizing a sign bit comparison that gets used in a branch,
1415-
// pessimizes codegen by generating branch on zero instruction instead
1416-
// of a test and branch. So we avoid canonicalizing in such situations
1417-
// because test and branch instruction has better branch displacement
1418-
// than compare and branch instruction.
1419-
bool UnusedBit;
1420-
bool IsSignBit = isSignBitCheck(Pred, *C, UnusedBit);
1421-
if (Cmp.isEquality() || (IsSignBit && hasBranchUse(Cmp)))
1422-
return nullptr;
1423-
1424-
// Avoid an infinite loop with min/max canonicalization.
1425-
// TODO: This will be unnecessary if we canonicalize to min/max intrinsics.
1426-
if (Cmp.hasOneUse() &&
1427-
match(Cmp.user_back(), m_MaxOrMin(m_Value(), m_Value())))
1428-
return nullptr;
1423+
// Avoid an infinite loop with min/max canonicalization.
1424+
// TODO: This will be unnecessary if we canonicalize to min/max intrinsics.
1425+
if (Cmp.hasOneUse() &&
1426+
match(Cmp.user_back(), m_MaxOrMin(m_Value(), m_Value())))
1427+
return nullptr;
14291428

1430-
if (const APInt *EqC = Intersection.getSingleElement())
1431-
return new ICmpInst(ICmpInst::ICMP_EQ, X, Builder.getInt(*EqC));
1432-
if (const APInt *NeC = Difference.getSingleElement())
1433-
return new ICmpInst(ICmpInst::ICMP_NE, X, Builder.getInt(*NeC));
1434-
}
1429+
if (const APInt *EqC = Intersection.getSingleElement())
1430+
return new ICmpInst(ICmpInst::ICMP_EQ, X,
1431+
ConstantInt::get(X->getType(), *EqC));
1432+
if (const APInt *NeC = Difference.getSingleElement())
1433+
return new ICmpInst(ICmpInst::ICMP_NE, X,
1434+
ConstantInt::get(X->getType(), *NeC));
14351435

14361436
return nullptr;
14371437
}

llvm/test/Transforms/InstCombine/abs_abs.ll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ define <2 x i32> @abs_abs_x03_vec(<2 x i32> %x, <2 x i32> %y) {
305305
; CHECK-LABEL: @abs_abs_x03_vec(
306306
; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
307307
; CHECK-NEXT: [[COND:%.*]] = call <2 x i32> @llvm.abs.v2i32(<2 x i32> [[A]], i1 false)
308-
; CHECK-NEXT: ret <2 x i32> [[COND]]
308+
; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp eq <2 x i32> [[A]], <i32 -2147483648, i32 -2147483648>
309+
; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]]
310+
; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1_NOT]], <2 x i32> [[SUB16]], <2 x i32> [[COND]]
311+
; CHECK-NEXT: ret <2 x i32> [[COND18]]
309312
;
310313
%a = sub nsw <2 x i32> %x, %y
311314
%b = sub nsw <2 x i32> %y, %x
@@ -1174,8 +1177,8 @@ define i32 @nabs_abs_x18(i32 %x, i32 %y) {
11741177
; CHECK-LABEL: @nabs_abs_x18(
11751178
; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
11761179
; CHECK-NEXT: [[COND:%.*]] = call i32 @llvm.abs.i32(i32 [[A]], i1 false)
1177-
; CHECK-NEXT: [[COND18:%.*]] = sub i32 0, [[COND]]
1178-
; CHECK-NEXT: ret i32 [[COND18]]
1180+
; CHECK-NEXT: [[SUB16:%.*]] = sub i32 0, [[COND]]
1181+
; CHECK-NEXT: ret i32 [[SUB16]]
11791182
;
11801183
%a = sub nsw i32 %x, %y
11811184
%b = sub nsw i32 %y, %x
@@ -1208,7 +1211,9 @@ define <2 x i32> @nabs_abs_x02_vec(<2 x i32> %x, <2 x i32> %y) {
12081211
; CHECK-LABEL: @nabs_abs_x02_vec(
12091212
; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
12101213
; CHECK-NEXT: [[COND:%.*]] = call <2 x i32> @llvm.abs.v2i32(<2 x i32> [[A]], i1 false)
1211-
; CHECK-NEXT: [[COND18:%.*]] = sub <2 x i32> zeroinitializer, [[COND]]
1214+
; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp eq <2 x i32> [[A]], <i32 -2147483648, i32 -2147483648>
1215+
; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]]
1216+
; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1_NOT]], <2 x i32> [[COND]], <2 x i32> [[SUB16]]
12121217
; CHECK-NEXT: ret <2 x i32> [[COND18]]
12131218
;
12141219
%a = sub nsw <2 x i32> %x, %y

llvm/test/Transforms/InstCombine/compare-udiv.ll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ define <2 x i1> @test7vec(<2 x i32> %d) {
140140

141141
define i1 @test8(i32 %d) {
142142
; CHECK-LABEL: @test8(
143-
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[D:%.*]], 2
143+
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 4, [[D:%.*]]
144+
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[DIV]], 4
144145
; CHECK-NEXT: ret i1 [[CMP1]]
145146
;
146147
%div = udiv i32 4, %d
@@ -150,7 +151,8 @@ define i1 @test8(i32 %d) {
150151

151152
define <2 x i1> @test8vec(<2 x i32> %d) {
152153
; CHECK-LABEL: @test8vec(
153-
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult <2 x i32> [[D:%.*]], <i32 2, i32 2>
154+
; CHECK-NEXT: [[DIV:%.*]] = udiv <2 x i32> <i32 4, i32 4>, [[D:%.*]]
155+
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq <2 x i32> [[DIV]], <i32 4, i32 4>
154156
; CHECK-NEXT: ret <2 x i1> [[CMP1]]
155157
;
156158
%div = udiv <2 x i32> <i32 4, i32 4>, %d
@@ -260,7 +262,8 @@ define <2 x i1> @test13vec(<2 x i32> %d) {
260262

261263
define i1 @test14(i32 %d) {
262264
; CHECK-LABEL: @test14(
263-
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[D:%.*]], 1
265+
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 4, [[D:%.*]]
266+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[DIV]], 4
264267
; CHECK-NEXT: ret i1 [[CMP1]]
265268
;
266269
%div = udiv i32 4, %d
@@ -270,7 +273,8 @@ define i1 @test14(i32 %d) {
270273

271274
define <2 x i1> @test14vec(<2 x i32> %d) {
272275
; CHECK-LABEL: @test14vec(
273-
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt <2 x i32> [[D:%.*]], <i32 1, i32 1>
276+
; CHECK-NEXT: [[DIV:%.*]] = udiv <2 x i32> <i32 4, i32 4>, [[D:%.*]]
277+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne <2 x i32> [[DIV]], <i32 4, i32 4>
274278
; CHECK-NEXT: ret <2 x i1> [[CMP1]]
275279
;
276280
%div = udiv <2 x i32> <i32 4, i32 4>, %d

llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ declare void @use_i1_vec(<2 x i1>)
1010

1111
define i1 @pow2_or_zero_is_negative(i8 %x) {
1212
; CHECK-LABEL: @pow2_or_zero_is_negative(
13-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], -128
14-
; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq i8 [[X]], -128
13+
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X:%.*]]
14+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
15+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[POW2_OR_ZERO]], -128
16+
; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq i8 [[POW2_OR_ZERO]], -128
1517
; CHECK-NEXT: call void @use_i1(i1 [[CMP_2]])
1618
; CHECK-NEXT: ret i1 [[CMP]]
1719
;
@@ -26,7 +28,9 @@ define i1 @pow2_or_zero_is_negative(i8 %x) {
2628
define i1 @pow2_or_zero_is_negative_commute(i8 %A) {
2729
; CHECK-LABEL: @pow2_or_zero_is_negative_commute(
2830
; CHECK-NEXT: [[X:%.*]] = mul i8 [[A:%.*]], 42
29-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], -128
31+
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]]
32+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[X]], [[NEG]]
33+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[POW2_OR_ZERO]], -128
3034
; CHECK-NEXT: ret i1 [[CMP]]
3135
;
3236
%x = mul i8 42, %A ; thwart complexity-based canonicalization
@@ -38,8 +42,10 @@ define i1 @pow2_or_zero_is_negative_commute(i8 %A) {
3842

3943
define <2 x i1> @pow2_or_zero_is_negative_vec(<2 x i8> %x) {
4044
; CHECK-LABEL: @pow2_or_zero_is_negative_vec(
41-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
42-
; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq <2 x i8> [[X]], <i8 -128, i8 -128>
45+
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
46+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[NEG]], [[X]]
47+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
48+
; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
4349
; CHECK-NEXT: call void @use_i1_vec(<2 x i1> [[CMP_2]])
4450
; CHECK-NEXT: ret <2 x i1> [[CMP]]
4551
;
@@ -54,7 +60,9 @@ define <2 x i1> @pow2_or_zero_is_negative_vec(<2 x i8> %x) {
5460
define <2 x i1> @pow2_or_zero_is_negative_vec_commute(<2 x i8> %A) {
5561
; CHECK-LABEL: @pow2_or_zero_is_negative_vec_commute(
5662
; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[A:%.*]], <i8 42, i8 42>
57-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X]], <i8 -128, i8 -128>
63+
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
64+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[X]], [[NEG]]
65+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
5866
; CHECK-NEXT: ret <2 x i1> [[CMP]]
5967
;
6068
%x = mul <2 x i8> <i8 42, i8 42>, %A ; thwart complexity-based canonicalization
@@ -66,8 +74,10 @@ define <2 x i1> @pow2_or_zero_is_negative_vec_commute(<2 x i8> %A) {
6674

6775
define i1 @pow2_or_zero_is_not_negative(i8 %x) {
6876
; CHECK-LABEL: @pow2_or_zero_is_not_negative(
69-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], -128
70-
; CHECK-NEXT: [[CMP_2:%.*]] = icmp ne i8 [[X]], -128
77+
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X:%.*]]
78+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
79+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[POW2_OR_ZERO]], -128
80+
; CHECK-NEXT: [[CMP_2:%.*]] = icmp ne i8 [[POW2_OR_ZERO]], -128
7181
; CHECK-NEXT: call void @use_i1(i1 [[CMP_2]])
7282
; CHECK-NEXT: ret i1 [[CMP]]
7383
;
@@ -82,7 +92,9 @@ define i1 @pow2_or_zero_is_not_negative(i8 %x) {
8292
define i1 @pow2_or_zero_is_not_negative_commute(i8 %A) {
8393
; CHECK-LABEL: @pow2_or_zero_is_not_negative_commute(
8494
; CHECK-NEXT: [[X:%.*]] = mul i8 [[A:%.*]], 42
85-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], -128
95+
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]]
96+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[X]], [[NEG]]
97+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[POW2_OR_ZERO]], -128
8698
; CHECK-NEXT: ret i1 [[CMP]]
8799
;
88100
%x = mul i8 42, %A ; thwart complexity-based canonicalization
@@ -94,8 +106,10 @@ define i1 @pow2_or_zero_is_not_negative_commute(i8 %A) {
94106

95107
define <2 x i1> @pow2_or_zero_is_not_negative_vec(<2 x i8> %x) {
96108
; CHECK-LABEL: @pow2_or_zero_is_not_negative_vec(
97-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
98-
; CHECK-NEXT: [[CMP_2:%.*]] = icmp ne <2 x i8> [[X]], <i8 -128, i8 -128>
109+
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
110+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[NEG]], [[X]]
111+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
112+
; CHECK-NEXT: [[CMP_2:%.*]] = icmp ne <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
99113
; CHECK-NEXT: call void @use_i1_vec(<2 x i1> [[CMP_2]])
100114
; CHECK-NEXT: ret <2 x i1> [[CMP]]
101115
;
@@ -110,7 +124,9 @@ define <2 x i1> @pow2_or_zero_is_not_negative_vec(<2 x i8> %x) {
110124
define <2 x i1> @pow2_or_zero_is_not_negative_vec_commute(<2 x i8> %A) {
111125
; CHECK-LABEL: @pow2_or_zero_is_not_negative_vec_commute(
112126
; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[A:%.*]], <i8 42, i8 42>
113-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[X]], <i8 -128, i8 -128>
127+
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
128+
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[X]], [[NEG]]
129+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[POW2_OR_ZERO]], <i8 -128, i8 -128>
114130
; CHECK-NEXT: ret <2 x i1> [[CMP]]
115131
;
116132
%x = mul <2 x i8> <i8 42, i8 42>, %A ; thwart complexity-based canonicalization
@@ -126,7 +142,7 @@ define i1 @pow2_or_zero_is_negative_extra_use(i8 %x) {
126142
; CHECK-NEXT: call void @use(i8 [[NEG]])
127143
; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
128144
; CHECK-NEXT: call void @use(i8 [[POW2_OR_ZERO]])
129-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], -128
145+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[POW2_OR_ZERO]], -128
130146
; CHECK-NEXT: ret i1 [[CMP]]
131147
;
132148
%neg = sub i8 0, %x

llvm/test/Transforms/InstCombine/icmp-div-constant.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ target datalayout = "n32"
55

66
define i1 @is_rem2_neg_i8(i8 %x) {
77
; CHECK-LABEL: @is_rem2_neg_i8(
8-
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -127
9-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP1]], -127
8+
; CHECK-NEXT: [[S:%.*]] = srem i8 [[X:%.*]], 2
9+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], -1
1010
; CHECK-NEXT: ret i1 [[R]]
1111
;
1212
%s = srem i8 %x, 2
@@ -118,8 +118,8 @@ define i32 @icmp_div(i16 %a, i16 %c) {
118118
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0
119119
; CHECK-NEXT: br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]]
120120
; CHECK: then:
121-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0
122-
; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP]] to i32
121+
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i16 [[C:%.*]], 0
122+
; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP_NOT]] to i32
123123
; CHECK-NEXT: br label [[EXIT]]
124124
; CHECK: exit:
125125
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[TMP0]], [[THEN]] ]
@@ -173,8 +173,8 @@ define i32 @icmp_div3(i16 %a, i16 %c) {
173173
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0
174174
; CHECK-NEXT: br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]]
175175
; CHECK: then:
176-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0
177-
; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP]] to i32
176+
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i16 [[C:%.*]], 0
177+
; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP_NOT]] to i32
178178
; CHECK-NEXT: br label [[EXIT]]
179179
; CHECK: exit:
180180
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[TMP0]], [[THEN]] ]

llvm/test/Transforms/InstCombine/icmp-shl-nsw.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ define i1 @icmp_sgt9(i8 %x) {
172172

173173
define i1 @icmp_sgt10(i8 %x) {
174174
; CHECK-LABEL: @icmp_sgt10(
175-
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
175+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0
176176
; CHECK-NEXT: ret i1 [[CMP]]
177177
;
178178
%shl = shl nsw i8 %x, 7
@@ -182,7 +182,7 @@ define i1 @icmp_sgt10(i8 %x) {
182182

183183
define i1 @icmp_sgt11(i8 %x) {
184184
; CHECK-LABEL: @icmp_sgt11(
185-
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
185+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0
186186
; CHECK-NEXT: ret i1 [[CMP]]
187187
;
188188
%shl = shl nsw i8 %x, 7
@@ -194,7 +194,7 @@ define i1 @icmp_sgt11(i8 %x) {
194194

195195
define <2 x i1> @icmp_sgt11_vec(<2 x i8> %x) {
196196
; CHECK-LABEL: @icmp_sgt11_vec(
197-
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
197+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], zeroinitializer
198198
; CHECK-NEXT: ret <2 x i1> [[CMP]]
199199
;
200200
%shl = shl nsw <2 x i8> %x, <i8 7, i8 7>
@@ -313,7 +313,7 @@ define i1 @icmp_sle9(i8 %x) {
313313

314314
define i1 @icmp_sle10(i8 %x) {
315315
; CHECK-LABEL: @icmp_sle10(
316-
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
316+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 0
317317
; CHECK-NEXT: ret i1 [[CMP]]
318318
;
319319
%shl = shl nsw i8 %x, 7
@@ -323,7 +323,7 @@ define i1 @icmp_sle10(i8 %x) {
323323

324324
define i1 @icmp_sle11(i8 %x) {
325325
; CHECK-LABEL: @icmp_sle11(
326-
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
326+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 0
327327
; CHECK-NEXT: ret i1 [[CMP]]
328328
;
329329
%shl = shl nsw i8 %x, 7

0 commit comments

Comments
 (0)