Skip to content

Commit 1376301

Browse files
committed
[InstCombine] Canonicalize range test idiom
InstCombine converts range tests of the form (X > C1 && X < C2) or (X < C1 || X > C2) into checks of the form (X + C3 < C4) or (X + C3 > C4). It is possible to express all range tests in either of these forms (with different choices of constants), but currently neither of them is considered canonical. We may have equivalent range tests using either ult or ugt. This proposes to canonicalize all range tests to use ult. An alternative would be to canonicalize to either ult or ugt depending on the specific constants involved -- e.g. in practice we currently generate ult for && style ranges and ugt for || style ranges when going through the insertRangeTest() helper. In fact, the "clamp like" fold was relying on this, which is why I had to tweak it to not assume whether inversion is needed based on just the predicate. Proof: https://alive2.llvm.org/ce/z/_SP_rQ Differential Revision: https://reviews.llvm.org/D113366
1 parent 6d44387 commit 1376301

17 files changed

+119
-104
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,14 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
27482748
return new ICmpInst(ICmpInst::ICMP_NE, Builder.CreateAnd(X, ~C),
27492749
ConstantExpr::getNeg(cast<Constant>(Y)));
27502750

2751+
// The range test idiom can use either ult or ugt. Arbitrarily canonicalize
2752+
// to the ult form.
2753+
// X+C2 >u C -> X+(C2-C-1) <u ~C
2754+
if (Pred == ICmpInst::ICMP_UGT)
2755+
return new ICmpInst(ICmpInst::ICMP_ULT,
2756+
Builder.CreateAdd(X, ConstantInt::get(Ty, *C2 - C - 1)),
2757+
ConstantInt::get(Ty, ~C));
2758+
27512759
return nullptr;
27522760
}
27532761

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,15 +1298,23 @@ static Value *canonicalizeClampLike(SelectInst &Sel0, ICmpInst &Cmp0,
12981298
// Said condition must be one-use.
12991299
if (!Cmp0.hasOneUse())
13001300
return nullptr;
1301+
ICmpInst::Predicate Pred0 = Cmp0.getPredicate();
13011302
Value *Cmp00 = Cmp0.getOperand(0);
13021303
Constant *C0;
13031304
if (!match(Cmp0.getOperand(1),
13041305
m_CombineAnd(m_AnyIntegralConstant(), m_Constant(C0))))
13051306
return nullptr;
1306-
// Canonicalize Cmp0 into the form we expect.
1307+
1308+
if (!isa<SelectInst>(Sel1)) {
1309+
Pred0 = ICmpInst::getInversePredicate(Pred0);
1310+
std::swap(X, Sel1);
1311+
}
1312+
1313+
// Canonicalize Cmp0 into ult or uge.
13071314
// FIXME: we shouldn't care about lanes that are 'undef' in the end?
1308-
switch (Cmp0.getPredicate()) {
1315+
switch (Pred0) {
13091316
case ICmpInst::Predicate::ICMP_ULT:
1317+
case ICmpInst::Predicate::ICMP_UGE:
13101318
// Although icmp ult %x, 0 is an unusual thing to try and should generally
13111319
// have been simplified, it does not verify with undef inputs so ensure we
13121320
// are not in a strange state.
@@ -1316,25 +1324,16 @@ static Value *canonicalizeClampLike(SelectInst &Sel0, ICmpInst &Cmp0,
13161324
return nullptr;
13171325
break; // Great!
13181326
case ICmpInst::Predicate::ICMP_ULE:
1319-
// We'd have to increment C0 by one, and for that it must not have all-ones
1320-
// element, but then it would have been canonicalized to 'ult' before
1321-
// we get here. So we can't do anything useful with 'ule'.
1322-
return nullptr;
13231327
case ICmpInst::Predicate::ICMP_UGT:
1324-
// We want to canonicalize it to 'ult', so we'll need to increment C0,
1325-
// which again means it must not have any all-ones elements.
1328+
// We want to canonicalize it to 'ult' or 'uge', so we'll need to increment
1329+
// C0, which again means it must not have any all-ones elements.
13261330
if (!match(C0,
13271331
m_SpecificInt_ICMP(
13281332
ICmpInst::Predicate::ICMP_NE,
13291333
APInt::getAllOnes(C0->getType()->getScalarSizeInBits()))))
13301334
return nullptr; // Can't do, have all-ones element[s].
13311335
C0 = InstCombiner::AddOne(C0);
1332-
std::swap(X, Sel1);
13331336
break;
1334-
case ICmpInst::Predicate::ICMP_UGE:
1335-
// The only way we'd get this predicate if this `icmp` has extra uses,
1336-
// but then we won't be able to do this fold.
1337-
return nullptr;
13381337
default:
13391338
return nullptr; // Unknown predicate.
13401339
}
@@ -1407,6 +1406,8 @@ static Value *canonicalizeClampLike(SelectInst &Sel0, ICmpInst &Cmp0,
14071406
// The thresholds of this clamp-like pattern.
14081407
auto *ThresholdLowIncl = ConstantExpr::getNeg(C1);
14091408
auto *ThresholdHighExcl = ConstantExpr::getSub(C0, C1);
1409+
if (Pred0 == ICmpInst::Predicate::ICMP_UGE)
1410+
std::swap(ThresholdLowIncl, ThresholdHighExcl);
14101411

14111412
// The fold has a precondition 1: C2 s>= ThresholdLow
14121413
auto *Precond1 = ConstantExpr::getICmp(ICmpInst::Predicate::ICMP_SGE, C2,

llvm/test/CodeGen/BPF/adjust-opt-icmp1.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ entry:
3939
; CHECK: if [[REG2]] s> [[REG1]] goto
4040
; CHECK: if [[REG1]] s> 7 goto
4141

42-
; CHECK-DISABLE: [[REG1:r[0-9]+]] += -1
42+
; CHECK-DISABLE: [[REG1:r[0-9]+]] += -8
4343
; CHECK-DISABLE: [[REG1]] <<= 32
4444
; CHECK-DISABLE: [[REG1]] >>= 32
45-
; CHECK-DISABLE: if [[REG1]] > 6 goto
45+
; CHECK-DISABLE: [[REG2:r[0-9]+]] = 4294967289
46+
; CHECK-DISABLE: if [[REG2]] > [[REG1]] goto
4647

4748
lor.lhs.false: ; preds = %entry
4849
%2 = load i32, i32* %ret, align 4, !tbaa !2

llvm/test/CodeGen/BPF/adjust-opt-icmp2.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ entry:
3737
; CHECK: if [[REG2]] s> [[REG1]] goto
3838
; CHECK: if [[REG1]] s> 7 goto
3939

40-
; CHECK-DISABLE: [[REG1:r[0-9]+]] += -1
40+
; CHECK-DISABLE: [[REG1:r[0-9]+]] += -8
4141
; CHECK-DISABLE: [[REG1]] <<= 32
4242
; CHECK-DISABLE: [[REG1]] >>= 32
43-
; CHECK-DISABLE: if [[REG1]] > 6 goto
43+
; CHECK-DISABLE: [[REG2:r[0-9]+]] = 4294967289
44+
; CHECK-DISABLE: if [[REG2]] > [[REG1]] goto
4445

4546
if.then: ; preds = %entry
4647
store i32 0, i32* %retval, align 4

llvm/test/Transforms/InstCombine/2006-12-15-Range-Test.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ define i1 @print_pgm_cond_true(i32 %tmp12.reload, i32* %tmp16.out) {
1818
; CHECK: cond_true:
1919
; CHECK-NEXT: [[TMP15:%.*]] = getelementptr [17 x i32], [17 x i32]* @r, i32 0, i32 [[TMP12_RELOAD:%.*]]
2020
; CHECK-NEXT: [[TMP16]] = load i32, i32* [[TMP15]], align 4
21-
; CHECK-NEXT: [[TMP16_OFF:%.*]] = add i32 [[TMP16]], 31
22-
; CHECK-NEXT: [[TMP0:%.*]] = icmp ugt i32 [[TMP16_OFF]], 62
23-
; CHECK-NEXT: br i1 [[TMP0]], label [[BB27_EXITSTUB:%.*]], label [[COND_NEXT23_EXITSTUB:%.*]]
21+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[TMP16]], -32
22+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[TMP0]], -63
23+
; CHECK-NEXT: br i1 [[TMP1]], label [[BB27_EXITSTUB:%.*]], label [[COND_NEXT23_EXITSTUB:%.*]]
2424
;
2525
newFuncRoot:
2626
br label %cond_true
@@ -55,9 +55,9 @@ define i1 @print_pgm_cond_true_logical(i32 %tmp12.reload, i32* %tmp16.out) {
5555
; CHECK: cond_true:
5656
; CHECK-NEXT: [[TMP15:%.*]] = getelementptr [17 x i32], [17 x i32]* @r, i32 0, i32 [[TMP12_RELOAD:%.*]]
5757
; CHECK-NEXT: [[TMP16]] = load i32, i32* [[TMP15]], align 4
58-
; CHECK-NEXT: [[TMP16_OFF:%.*]] = add i32 [[TMP16]], 31
59-
; CHECK-NEXT: [[TMP0:%.*]] = icmp ugt i32 [[TMP16_OFF]], 62
60-
; CHECK-NEXT: br i1 [[TMP0]], label [[BB27_EXITSTUB:%.*]], label [[COND_NEXT23_EXITSTUB:%.*]]
58+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[TMP16]], -32
59+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[TMP0]], -63
60+
; CHECK-NEXT: br i1 [[TMP1]], label [[BB27_EXITSTUB:%.*]], label [[COND_NEXT23_EXITSTUB:%.*]]
6161
;
6262
newFuncRoot:
6363
br label %cond_true

llvm/test/Transforms/InstCombine/2007-03-21-SignedRangeTest.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
define i1 @test(i32 %tmp6) {
77
; CHECK-LABEL: @test(
8-
; CHECK-NEXT: [[TMP6_OFF:%.*]] = add i32 %tmp6, 83
9-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[TMP6_OFF]], 11
10-
; CHECK-NEXT: ret i1 [[TMP1]]
8+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[TMP6:%.*]], 71
9+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -12
10+
; CHECK-NEXT: ret i1 [[TMP2]]
1111
;
1212
%tmp7 = sdiv i32 %tmp6, 12
1313
icmp ne i32 %tmp7, -6
@@ -16,9 +16,9 @@ define i1 @test(i32 %tmp6) {
1616

1717
define <2 x i1> @test_vec(<2 x i32> %tmp6) {
1818
; CHECK-LABEL: @test_vec(
19-
; CHECK-NEXT: [[TMP6_OFF:%.*]] = add <2 x i32> %tmp6, <i32 83, i32 83>
20-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i32> [[TMP6_OFF]], <i32 11, i32 11>
21-
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
19+
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[TMP6:%.*]], <i32 71, i32 71>
20+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <2 x i32> [[TMP1]], <i32 -12, i32 -12>
21+
; CHECK-NEXT: ret <2 x i1> [[TMP2]]
2222
;
2323
%tmp7 = sdiv <2 x i32> %tmp6, <i32 12, i32 12>
2424
icmp ne <2 x i32> %tmp7, <i32 -6, i32 -6>

llvm/test/Transforms/InstCombine/2008-08-05-And.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ define void @f(i8* %x) nounwind {
88
; CHECK-NEXT: br label [[BB:%.*]]
99
; CHECK: bb:
1010
; CHECK-NEXT: [[L1:%.*]] = load i8, i8* [[X:%.*]], align 1
11-
; CHECK-NEXT: [[S1:%.*]] = add i8 [[L1]], -6
12-
; CHECK-NEXT: [[C1:%.*]] = icmp ugt i8 [[S1]], 2
13-
; CHECK-NEXT: [[S2:%.*]] = add i8 [[L1]], -10
14-
; CHECK-NEXT: [[C2:%.*]] = icmp ugt i8 [[S2]], 2
11+
; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[L1]], -9
12+
; CHECK-NEXT: [[C1:%.*]] = icmp ult i8 [[TMP0]], -3
13+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[L1]], -13
14+
; CHECK-NEXT: [[C2:%.*]] = icmp ult i8 [[TMP1]], -3
1515
; CHECK-NEXT: [[A1:%.*]] = and i1 [[C1]], [[C2]]
1616
; CHECK-NEXT: br i1 [[A1]], label [[INCOMPATIBLE:%.*]], label [[OKAY:%.*]]
1717
; CHECK: okay:
@@ -45,10 +45,10 @@ define void @f_logical(i8* %x) nounwind {
4545
; CHECK-NEXT: br label [[BB:%.*]]
4646
; CHECK: bb:
4747
; CHECK-NEXT: [[L1:%.*]] = load i8, i8* [[X:%.*]], align 1
48-
; CHECK-NEXT: [[S1:%.*]] = add i8 [[L1]], -6
49-
; CHECK-NEXT: [[C1:%.*]] = icmp ugt i8 [[S1]], 2
50-
; CHECK-NEXT: [[S2:%.*]] = add i8 [[L1]], -10
51-
; CHECK-NEXT: [[C2:%.*]] = icmp ugt i8 [[S2]], 2
48+
; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[L1]], -9
49+
; CHECK-NEXT: [[C1:%.*]] = icmp ult i8 [[TMP0]], -3
50+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[L1]], -13
51+
; CHECK-NEXT: [[C2:%.*]] = icmp ult i8 [[TMP1]], -3
5252
; CHECK-NEXT: [[A1:%.*]] = and i1 [[C1]], [[C2]]
5353
; CHECK-NEXT: br i1 [[A1]], label [[INCOMPATIBLE:%.*]], label [[OKAY:%.*]]
5454
; CHECK: okay:

llvm/test/Transforms/InstCombine/and-or-icmps.ll

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ define i1 @or_eq_with_diff_one_logical(i8 %x) {
257257

258258
define i1 @and_ne_with_diff_one(i32 %x) {
259259
; CHECK-LABEL: @and_ne_with_diff_one(
260-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -39
261-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 [[TMP1]], 1
260+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -41
261+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2
262262
; CHECK-NEXT: ret i1 [[TMP2]]
263263
;
264264
%cmp1 = icmp ne i32 %x, 40
@@ -269,8 +269,8 @@ define i1 @and_ne_with_diff_one(i32 %x) {
269269

270270
define i1 @and_ne_with_diff_one_logical(i32 %x) {
271271
; CHECK-LABEL: @and_ne_with_diff_one_logical(
272-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -39
273-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 [[TMP1]], 1
272+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -41
273+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2
274274
; CHECK-NEXT: ret i1 [[TMP2]]
275275
;
276276
%cmp1 = icmp ne i32 %x, 40
@@ -308,8 +308,8 @@ define i1 @or_eq_with_diff_one_signed_logical(i32 %x) {
308308

309309
define i1 @and_ne_with_diff_one_signed(i64 %x) {
310310
; CHECK-LABEL: @and_ne_with_diff_one_signed(
311-
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], 1
312-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i64 [[TMP1]], 1
311+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], -1
312+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i64 [[TMP1]], -2
313313
; CHECK-NEXT: ret i1 [[TMP2]]
314314
;
315315
%cmp1 = icmp ne i64 %x, -1
@@ -320,8 +320,8 @@ define i1 @and_ne_with_diff_one_signed(i64 %x) {
320320

321321
define i1 @and_ne_with_diff_one_signed_logical(i64 %x) {
322322
; CHECK-LABEL: @and_ne_with_diff_one_signed_logical(
323-
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], 1
324-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i64 [[TMP1]], 1
323+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], -1
324+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i64 [[TMP1]], -2
325325
; CHECK-NEXT: ret i1 [[TMP2]]
326326
;
327327
%cmp1 = icmp ne i64 %x, -1
@@ -346,8 +346,8 @@ define <2 x i1> @or_eq_with_one_bit_diff_constants2_splatvec(<2 x i32> %x) {
346346

347347
define <2 x i1> @and_ne_with_diff_one_splatvec(<2 x i32> %x) {
348348
; CHECK-LABEL: @and_ne_with_diff_one_splatvec(
349-
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[X:%.*]], <i32 -39, i32 -39>
350-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt <2 x i32> [[TMP1]], <i32 1, i32 1>
349+
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[X:%.*]], <i32 -41, i32 -41>
350+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <2 x i32> [[TMP1]], <i32 -2, i32 -2>
351351
; CHECK-NEXT: ret <2 x i1> [[TMP2]]
352352
;
353353
%cmp1 = icmp ne <2 x i32> %x, <i32 40, i32 40>
@@ -508,9 +508,9 @@ define i1 @PR42691_4_logical(i32 %x) {
508508

509509
define i1 @PR42691_5(i32 %x) {
510510
; CHECK-LABEL: @PR42691_5(
511-
; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -1
512-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X_OFF]], 2147483645
513-
; CHECK-NEXT: ret i1 [[TMP1]]
511+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -2147483647
512+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2147483646
513+
; CHECK-NEXT: ret i1 [[TMP2]]
514514
;
515515
%c1 = icmp slt i32 %x, 1
516516
%c2 = icmp eq i32 %x, 2147483647
@@ -520,9 +520,9 @@ define i1 @PR42691_5(i32 %x) {
520520

521521
define i1 @PR42691_5_logical(i32 %x) {
522522
; CHECK-LABEL: @PR42691_5_logical(
523-
; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -1
524-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X_OFF]], 2147483645
525-
; CHECK-NEXT: ret i1 [[TMP1]]
523+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -2147483647
524+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2147483646
525+
; CHECK-NEXT: ret i1 [[TMP2]]
526526
;
527527
%c1 = icmp slt i32 %x, 1
528528
%c2 = icmp eq i32 %x, 2147483647
@@ -532,9 +532,9 @@ define i1 @PR42691_5_logical(i32 %x) {
532532

533533
define i1 @PR42691_6(i32 %x) {
534534
; CHECK-LABEL: @PR42691_6(
535-
; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], 2147483647
536-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X_OFF]], 2147483645
537-
; CHECK-NEXT: ret i1 [[TMP1]]
535+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], 1
536+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2147483646
537+
; CHECK-NEXT: ret i1 [[TMP2]]
538538
;
539539
%c1 = icmp ult i32 %x, 2147483649
540540
%c2 = icmp eq i32 %x, 4294967295
@@ -544,9 +544,9 @@ define i1 @PR42691_6(i32 %x) {
544544

545545
define i1 @PR42691_6_logical(i32 %x) {
546546
; CHECK-LABEL: @PR42691_6_logical(
547-
; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], 2147483647
548-
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X_OFF]], 2147483645
549-
; CHECK-NEXT: ret i1 [[TMP1]]
547+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], 1
548+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], -2147483646
549+
; CHECK-NEXT: ret i1 [[TMP2]]
550550
;
551551
%c1 = icmp ult i32 %x, 2147483649
552552
%c2 = icmp eq i32 %x, 4294967295

llvm/test/Transforms/InstCombine/canonicalize-signed-truncation-check.ll

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

1616
define i1 @p0(i8 %x) {
1717
; CHECK-LABEL: @p0(
18-
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 4
19-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], 7
18+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], -4
19+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], -8
2020
; CHECK-NEXT: ret i1 [[TMP2]]
2121
;
2222
%tmp0 = shl i8 %x, 5
@@ -44,8 +44,8 @@ define i1 @pb(i65 %x) {
4444

4545
define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
4646
; CHECK-LABEL: @p1_vec_splat(
47-
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[X:%.*]], <i8 4, i8 4>
48-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt <2 x i8> [[TMP1]], <i8 7, i8 7>
47+
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[X:%.*]], <i8 -4, i8 -4>
48+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <2 x i8> [[TMP1]], <i8 -8, i8 -8>
4949
; CHECK-NEXT: ret <2 x i1> [[TMP2]]
5050
;
5151
%tmp0 = shl <2 x i8> %x, <i8 5, i8 5>
@@ -115,8 +115,8 @@ declare i8 @gen8()
115115
define i1 @c0() {
116116
; CHECK-LABEL: @c0(
117117
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
118-
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X]], 4
119-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], 7
118+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X]], -4
119+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], -8
120120
; CHECK-NEXT: ret i1 [[TMP2]]
121121
;
122122
%x = call i8 @gen8()
@@ -136,8 +136,8 @@ define i1 @n_oneuse0(i8 %x) {
136136
; CHECK-LABEL: @n_oneuse0(
137137
; CHECK-NEXT: [[TMP0:%.*]] = shl i8 [[X:%.*]], 5
138138
; CHECK-NEXT: call void @use8(i8 [[TMP0]])
139-
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X]], 4
140-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], 7
139+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X]], -4
140+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], -8
141141
; CHECK-NEXT: ret i1 [[TMP2]]
142142
;
143143
%tmp0 = shl i8 %x, 5

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ define i1 @ult_add_nonuw(i8 %in) {
363363

364364
define i1 @uge_add_nonuw(i32 %in) {
365365
; CHECK-LABEL: @uge_add_nonuw(
366-
; CHECK-NEXT: [[A6:%.*]] = add i32 [[IN:%.*]], 3
367-
; CHECK-NEXT: [[A18:%.*]] = icmp ugt i32 [[A6]], 11
366+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[IN:%.*]], -9
367+
; CHECK-NEXT: [[A18:%.*]] = icmp ult i32 [[TMP1]], -12
368368
; CHECK-NEXT: ret i1 [[A18]]
369369
;
370370
%a6 = add i32 %in, 3
@@ -785,8 +785,8 @@ define <2 x i1> @ugt_offset_splat(<2 x i5> %a) {
785785

786786
define i1 @ugt_wrong_offset(i8 %a) {
787787
; CHECK-LABEL: @ugt_wrong_offset(
788-
; CHECK-NEXT: [[T:%.*]] = add i8 [[A:%.*]], 123
789-
; CHECK-NEXT: [[OV:%.*]] = icmp ugt i8 [[T]], -5
788+
; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[A:%.*]], 127
789+
; CHECK-NEXT: [[OV:%.*]] = icmp ult i8 [[TMP1]], 4
790790
; CHECK-NEXT: ret i1 [[OV]]
791791
;
792792
%t = add i8 %a, 123

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ define i1 @test_negative_nuw_and_signed_pred(i64 %x) {
5757

5858
define i1 @test_negative_nsw_and_unsigned_pred(i64 %x) {
5959
; CHECK-LABEL: @test_negative_nsw_and_unsigned_pred(
60-
; CHECK-NEXT: [[NOTSUB:%.*]] = add nsw i64 [[X:%.*]], -11
61-
; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[NOTSUB]], -4
60+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], -8
61+
; CHECK-NEXT: [[Z:%.*]] = icmp ult i64 [[TMP1]], 3
6262
; CHECK-NEXT: ret i1 [[Z]]
6363
;
6464
%y = sub nsw i64 10, %x

0 commit comments

Comments
 (0)