Skip to content

Commit 6da4ecd

Browse files
authored
[InstCombine] Infer shift flags with unknown shamt (llvm#72535)
Alive2: https://alive2.llvm.org/ce/z/82Wr3q Related patch: llvm@2dd52b4
1 parent 424c424 commit 6da4ecd

File tree

34 files changed

+204
-217
lines changed

34 files changed

+204
-217
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -964,30 +964,26 @@ static bool setShiftFlags(BinaryOperator &I, const SimplifyQuery &Q) {
964964
// Compute what we know about shift count.
965965
KnownBits KnownCnt =
966966
computeKnownBits(I.getOperand(1), Q.DL, /*Depth*/ 0, Q.AC, Q.CxtI, Q.DT);
967-
// If we know nothing about shift count or its a poison shift, we won't be
968-
// able to prove anything so return before computing shift amount.
969-
if (KnownCnt.isUnknown())
970-
return false;
971967
unsigned BitWidth = KnownCnt.getBitWidth();
972-
APInt MaxCnt = KnownCnt.getMaxValue();
973-
if (MaxCnt.uge(BitWidth))
974-
return false;
968+
// Since shift produces a poison value if RHS is equal to or larger than the
969+
// bit width, we can safely assume that RHS is less than the bit width.
970+
uint64_t MaxCnt = KnownCnt.getMaxValue().getLimitedValue(BitWidth - 1);
975971

976972
KnownBits KnownAmt =
977973
computeKnownBits(I.getOperand(0), Q.DL, /*Depth*/ 0, Q.AC, Q.CxtI, Q.DT);
978974
bool Changed = false;
979975

980976
if (I.getOpcode() == Instruction::Shl) {
981977
// If we have as many leading zeros than maximum shift cnt we have nuw.
982-
if (!I.hasNoUnsignedWrap() && MaxCnt.ule(KnownAmt.countMinLeadingZeros())) {
978+
if (!I.hasNoUnsignedWrap() && MaxCnt <= KnownAmt.countMinLeadingZeros()) {
983979
I.setHasNoUnsignedWrap();
984980
Changed = true;
985981
}
986982
// If we have more sign bits than maximum shift cnt we have nsw.
987983
if (!I.hasNoSignedWrap()) {
988-
if (MaxCnt.ult(KnownAmt.countMinSignBits()) ||
989-
MaxCnt.ult(ComputeNumSignBits(I.getOperand(0), Q.DL, /*Depth*/ 0,
990-
Q.AC, Q.CxtI, Q.DT))) {
984+
if (MaxCnt < KnownAmt.countMinSignBits() ||
985+
MaxCnt < ComputeNumSignBits(I.getOperand(0), Q.DL, /*Depth*/ 0, Q.AC,
986+
Q.CxtI, Q.DT)) {
991987
I.setHasNoSignedWrap();
992988
Changed = true;
993989
}
@@ -997,7 +993,7 @@ static bool setShiftFlags(BinaryOperator &I, const SimplifyQuery &Q) {
997993

998994
// If we have at least as many trailing zeros as maximum count then we have
999995
// exact.
1000-
Changed = MaxCnt.ule(KnownAmt.countMinTrailingZeros());
996+
Changed = MaxCnt <= KnownAmt.countMinTrailingZeros();
1001997
I.setIsExact(Changed);
1002998

1003999
return Changed;
@@ -1225,15 +1221,6 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
12251221
Value *NegX = Builder.CreateNeg(X, "neg");
12261222
return BinaryOperator::CreateAnd(NegX, X);
12271223
}
1228-
1229-
// The only way to shift out the 1 is with an over-shift, so that would
1230-
// be poison with or without "nuw". Undef is excluded because (undef << X)
1231-
// is not undef (it is zero).
1232-
Constant *ConstantOne = cast<Constant>(Op0);
1233-
if (!I.hasNoUnsignedWrap() && !ConstantOne->containsUndefElement()) {
1234-
I.setHasNoUnsignedWrap();
1235-
return &I;
1236-
}
12371224
}
12381225

12391226
return nullptr;

llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ define i8 @lshr_add_fail(i8 %x) {
150150
define i8 @ashr_add_fail(i8 %x) {
151151
; CHECK-LABEL: define i8 @ashr_add_fail
152152
; CHECK-SAME: (i8 [[X:%.*]]) {
153-
; CHECK-NEXT: [[SHIFT:%.*]] = ashr i8 -128, [[X]]
153+
; CHECK-NEXT: [[SHIFT:%.*]] = ashr exact i8 -128, [[X]]
154154
; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X]], 1
155-
; CHECK-NEXT: [[SHIFT2:%.*]] = ashr i8 -128, [[ADD]]
155+
; CHECK-NEXT: [[SHIFT2:%.*]] = ashr exact i8 -128, [[ADD]]
156156
; CHECK-NEXT: [[BINOP:%.*]] = add i8 [[SHIFT]], [[SHIFT2]]
157157
; CHECK-NEXT: ret i8 [[BINOP]]
158158
;

llvm/test/Transforms/InstCombine/canonicalize-ashr-shl-to-masking.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
define i8 @positive_samevar(i8 %x, i8 %y) {
1717
; CHECK-LABEL: @positive_samevar(
18-
; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]]
18+
; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]
1919
; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]
2020
; CHECK-NEXT: ret i8 [[RET]]
2121
;
@@ -62,7 +62,7 @@ define i8 @positive_biggershl(i8 %x) {
6262

6363
define i8 @positive_samevar_shlnuw(i8 %x, i8 %y) {
6464
; CHECK-LABEL: @positive_samevar_shlnuw(
65-
; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]]
65+
; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]
6666
; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]
6767
; CHECK-NEXT: ret i8 [[RET]]
6868
;
@@ -109,7 +109,7 @@ define i8 @positive_biggershl_shlnuw(i8 %x) {
109109

110110
define i8 @positive_samevar_shlnsw(i8 %x, i8 %y) {
111111
; CHECK-LABEL: @positive_samevar_shlnsw(
112-
; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]]
112+
; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]
113113
; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]
114114
; CHECK-NEXT: ret i8 [[RET]]
115115
;
@@ -156,7 +156,7 @@ define i8 @positive_biggershl_shlnsw(i8 %x) {
156156

157157
define i8 @positive_samevar_shlnuwnsw(i8 %x, i8 %y) {
158158
; CHECK-LABEL: @positive_samevar_shlnuwnsw(
159-
; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]]
159+
; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]
160160
; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]
161161
; CHECK-NEXT: ret i8 [[RET]]
162162
;
@@ -371,7 +371,7 @@ define i8 @positive_biggershl_shlnuwnsw_ashrexact(i8 %x) {
371371

372372
define <2 x i8> @positive_samevar_vec(<2 x i8> %x, <2 x i8> %y) {
373373
; CHECK-LABEL: @positive_samevar_vec(
374-
; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]]
374+
; CHECK-NEXT: [[TMP1:%.*]] = shl nsw <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]]
375375
; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], [[X:%.*]]
376376
; CHECK-NEXT: ret <2 x i8> [[RET]]
377377
;

llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v2-and-icmp-eq-to-icmp-ule.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ declare void @use8(i8)
142142

143143
define i1 @oneuse0(i8 %x, i8 %y) {
144144
; CHECK-LABEL: @oneuse0(
145-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
145+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
146146
; CHECK-NEXT: call void @use8(i8 [[T0]])
147147
; CHECK-NEXT: [[X_HIGHBITS:%.*]] = lshr i8 [[X:%.*]], [[Y]]
148148
; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[X_HIGHBITS]], 0
@@ -158,7 +158,7 @@ define i1 @oneuse0(i8 %x, i8 %y) {
158158

159159
define i1 @oneuse1(i8 %x, i8 %y) {
160160
; CHECK-LABEL: @oneuse1(
161-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
161+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
162162
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
163163
; CHECK-NEXT: call void @use8(i8 [[T1]])
164164
; CHECK-NEXT: [[RET:%.*]] = icmp uge i8 [[T1]], [[X:%.*]]
@@ -174,7 +174,7 @@ define i1 @oneuse1(i8 %x, i8 %y) {
174174

175175
define i1 @oneuse2(i8 %x, i8 %y) {
176176
; CHECK-LABEL: @oneuse2(
177-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
177+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
178178
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
179179
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
180180
; CHECK-NEXT: call void @use8(i8 [[T2]])
@@ -191,7 +191,7 @@ define i1 @oneuse2(i8 %x, i8 %y) {
191191

192192
define i1 @oneuse3(i8 %x, i8 %y) {
193193
; CHECK-LABEL: @oneuse3(
194-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
194+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
195195
; CHECK-NEXT: call void @use8(i8 [[T0]])
196196
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
197197
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -209,7 +209,7 @@ define i1 @oneuse3(i8 %x, i8 %y) {
209209

210210
define i1 @oneuse4(i8 %x, i8 %y) {
211211
; CHECK-LABEL: @oneuse4(
212-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
212+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
213213
; CHECK-NEXT: call void @use8(i8 [[T0]])
214214
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
215215
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
@@ -228,7 +228,7 @@ define i1 @oneuse4(i8 %x, i8 %y) {
228228

229229
define i1 @oneuse5(i8 %x, i8 %y) {
230230
; CHECK-LABEL: @oneuse5(
231-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
231+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
232232
; CHECK-NEXT: call void @use8(i8 [[T0]])
233233
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
234234
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -253,7 +253,7 @@ define i1 @oneuse5(i8 %x, i8 %y) {
253253

254254
define i1 @n0(i8 %x, i8 %y, i8 %notx) {
255255
; CHECK-LABEL: @n0(
256-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
256+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
257257
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
258258
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
259259
; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[T2]], [[NOTX:%.*]]
@@ -283,7 +283,7 @@ define i1 @n1(i8 %x, i8 %y) {
283283

284284
define i1 @n2(i8 %x, i8 %y) {
285285
; CHECK-LABEL: @n2(
286-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
286+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
287287
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], 1
288288
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
289289
; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[T2]], [[X]]

llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v2-and-icmp-ne-to-icmp-ugt.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ declare void @use8(i8)
142142

143143
define i1 @oneuse0(i8 %x, i8 %y) {
144144
; CHECK-LABEL: @oneuse0(
145-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
145+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
146146
; CHECK-NEXT: call void @use8(i8 [[T0]])
147147
; CHECK-NEXT: [[X_HIGHBITS:%.*]] = lshr i8 [[X:%.*]], [[Y]]
148148
; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[X_HIGHBITS]], 0
@@ -158,7 +158,7 @@ define i1 @oneuse0(i8 %x, i8 %y) {
158158

159159
define i1 @oneuse1(i8 %x, i8 %y) {
160160
; CHECK-LABEL: @oneuse1(
161-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
161+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
162162
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
163163
; CHECK-NEXT: call void @use8(i8 [[T1]])
164164
; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[T1]], [[X:%.*]]
@@ -174,7 +174,7 @@ define i1 @oneuse1(i8 %x, i8 %y) {
174174

175175
define i1 @oneuse2(i8 %x, i8 %y) {
176176
; CHECK-LABEL: @oneuse2(
177-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
177+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
178178
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
179179
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
180180
; CHECK-NEXT: call void @use8(i8 [[T2]])
@@ -191,7 +191,7 @@ define i1 @oneuse2(i8 %x, i8 %y) {
191191

192192
define i1 @oneuse3(i8 %x, i8 %y) {
193193
; CHECK-LABEL: @oneuse3(
194-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
194+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
195195
; CHECK-NEXT: call void @use8(i8 [[T0]])
196196
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
197197
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -209,7 +209,7 @@ define i1 @oneuse3(i8 %x, i8 %y) {
209209

210210
define i1 @oneuse4(i8 %x, i8 %y) {
211211
; CHECK-LABEL: @oneuse4(
212-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
212+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
213213
; CHECK-NEXT: call void @use8(i8 [[T0]])
214214
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
215215
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
@@ -228,7 +228,7 @@ define i1 @oneuse4(i8 %x, i8 %y) {
228228

229229
define i1 @oneuse5(i8 %x, i8 %y) {
230230
; CHECK-LABEL: @oneuse5(
231-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
231+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
232232
; CHECK-NEXT: call void @use8(i8 [[T0]])
233233
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
234234
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -253,7 +253,7 @@ define i1 @oneuse5(i8 %x, i8 %y) {
253253

254254
define i1 @n0(i8 %x, i8 %y, i8 %notx) {
255255
; CHECK-LABEL: @n0(
256-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
256+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
257257
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], -1
258258
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
259259
; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[T2]], [[NOTX:%.*]]
@@ -283,7 +283,7 @@ define i1 @n1(i8 %x, i8 %y) {
283283

284284
define i1 @n2(i8 %x, i8 %y) {
285285
; CHECK-LABEL: @n2(
286-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
286+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
287287
; CHECK-NEXT: [[T1:%.*]] = xor i8 [[T0]], 1
288288
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
289289
; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[T2]], [[X]]

llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v3-and-icmp-eq-to-icmp-ule.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ define i1 @n0(i8 %x, i8 %y, i8 %notx) {
249249

250250
define i1 @n1(i8 %x, i8 %y) {
251251
; CHECK-LABEL: @n1(
252-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
252+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
253253
; CHECK-NEXT: call void @use8(i8 [[T0]])
254254
; CHECK-NEXT: [[T1:%.*]] = add i8 [[T0]], -1
255255
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]

llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v3-and-icmp-ne-to-icmp-ugt.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ define i1 @n0(i8 %x, i8 %y, i8 %notx) {
249249

250250
define i1 @n1(i8 %x, i8 %y) {
251251
; CHECK-LABEL: @n1(
252-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
252+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
253253
; CHECK-NEXT: call void @use8(i8 [[T0]])
254254
; CHECK-NEXT: [[T1:%.*]] = add i8 [[T0]], -1
255255
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]

llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v4-and-icmp-eq-to-icmp-ule.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare void @use3i8(<3 x i8>)
2020

2121
define i1 @p0(i8 %x, i8 %y) {
2222
; CHECK-LABEL: @p0(
23-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
23+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
2424
; CHECK-NEXT: call void @use8(i8 [[T0]])
2525
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
2626
; CHECK-NEXT: [[RET:%.*]] = icmp uge i8 [[T1]], [[X:%.*]]
@@ -40,7 +40,7 @@ define i1 @p0(i8 %x, i8 %y) {
4040

4141
define <2 x i1> @p1_vec(<2 x i8> %x, <2 x i8> %y) {
4242
; CHECK-LABEL: @p1_vec(
43-
; CHECK-NEXT: [[T0:%.*]] = shl <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]]
43+
; CHECK-NEXT: [[T0:%.*]] = shl nsw <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]]
4444
; CHECK-NEXT: call void @use2i8(<2 x i8> [[T0]])
4545
; CHECK-NEXT: [[T1:%.*]] = lshr exact <2 x i8> [[T0]], [[Y]]
4646
; CHECK-NEXT: [[RET:%.*]] = icmp uge <2 x i8> [[T1]], [[X:%.*]]
@@ -78,7 +78,7 @@ declare i8 @gen8()
7878

7979
define i1 @c0(i8 %y) {
8080
; CHECK-LABEL: @c0(
81-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
81+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
8282
; CHECK-NEXT: call void @use8(i8 [[T0]])
8383
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
8484
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
@@ -96,7 +96,7 @@ define i1 @c0(i8 %y) {
9696

9797
define i1 @c1(i8 %y) {
9898
; CHECK-LABEL: @c1(
99-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
99+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
100100
; CHECK-NEXT: call void @use8(i8 [[T0]])
101101
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
102102
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
@@ -114,7 +114,7 @@ define i1 @c1(i8 %y) {
114114

115115
define i1 @c2(i8 %y) {
116116
; CHECK-LABEL: @c2(
117-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
117+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
118118
; CHECK-NEXT: call void @use8(i8 [[T0]])
119119
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
120120
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
@@ -136,7 +136,7 @@ define i1 @c2(i8 %y) {
136136

137137
define i1 @oneuse0(i8 %x, i8 %y) {
138138
; CHECK-LABEL: @oneuse0(
139-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
139+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
140140
; CHECK-NEXT: call void @use8(i8 [[T0]])
141141
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
142142
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -154,7 +154,7 @@ define i1 @oneuse0(i8 %x, i8 %y) {
154154

155155
define i1 @oneuse1(i8 %x, i8 %y) {
156156
; CHECK-LABEL: @oneuse1(
157-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
157+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
158158
; CHECK-NEXT: call void @use8(i8 [[T0]])
159159
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
160160
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
@@ -173,7 +173,7 @@ define i1 @oneuse1(i8 %x, i8 %y) {
173173

174174
define i1 @oneuse2(i8 %x, i8 %y) {
175175
; CHECK-LABEL: @oneuse2(
176-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
176+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
177177
; CHECK-NEXT: call void @use8(i8 [[T0]])
178178
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
179179
; CHECK-NEXT: call void @use8(i8 [[T1]])
@@ -198,7 +198,7 @@ define i1 @oneuse2(i8 %x, i8 %y) {
198198

199199
define i1 @n0(i8 %x, i8 %y, i8 %notx) {
200200
; CHECK-LABEL: @n0(
201-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y:%.*]]
201+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]
202202
; CHECK-NEXT: call void @use8(i8 [[T0]])
203203
; CHECK-NEXT: [[T1:%.*]] = lshr exact i8 [[T0]], [[Y]]
204204
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]
@@ -230,7 +230,7 @@ define i1 @n1(i8 %x, i8 %y) {
230230

231231
define i1 @n2(i8 %x, i8 %y1, i8 %y2) {
232232
; CHECK-LABEL: @n2(
233-
; CHECK-NEXT: [[T0:%.*]] = shl i8 -1, [[Y1:%.*]]
233+
; CHECK-NEXT: [[T0:%.*]] = shl nsw i8 -1, [[Y1:%.*]]
234234
; CHECK-NEXT: call void @use8(i8 [[T0]])
235235
; CHECK-NEXT: [[T1:%.*]] = lshr i8 [[T0]], [[Y2:%.*]]
236236
; CHECK-NEXT: [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]

0 commit comments

Comments
 (0)