Skip to content

Commit f5d24e6

Browse files
authored
SCEV: teach isImpliedViaOperations about samesign (#124270)
Use CmpPredicate::getMatching in isImpliedCondBalancedTypes to pass samesign information to isImpliedViaOperations, and teach it to call CmpPredicate::getPreferredSignedPredicate, effectively making it optimize with samesign information.
1 parent dcb124e commit f5d24e6

File tree

4 files changed

+166
-59
lines changed

4 files changed

+166
-59
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11860,15 +11860,13 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
1186011860
}
1186111861

1186211862
// Check whether the found predicate is the same as the desired predicate.
11863-
// FIXME: use CmpPredicate::getMatching here.
11864-
if (FoundPred == static_cast<CmpInst::Predicate>(Pred))
11865-
return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI);
11863+
if (auto P = CmpPredicate::getMatching(FoundPred, Pred))
11864+
return isImpliedCondOperands(*P, LHS, RHS, FoundLHS, FoundRHS, CtxI);
1186611865

1186711866
// Check whether swapping the found predicate makes it the same as the
1186811867
// desired predicate.
11869-
// FIXME: use CmpPredicate::getMatching here.
11870-
if (ICmpInst::getSwappedCmpPredicate(FoundPred) ==
11871-
static_cast<CmpInst::Predicate>(Pred)) {
11868+
if (auto P = CmpPredicate::getMatching(
11869+
ICmpInst::getSwappedCmpPredicate(FoundPred), Pred)) {
1187211870
// We can write the implication
1187311871
// 0. LHS Pred RHS <- FoundLHS SwapPred FoundRHS
1187411872
// using one of the following ways:
@@ -11879,22 +11877,23 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
1187911877
// Forms 1. and 2. require swapping the operands of one condition. Don't
1188011878
// do this if it would break canonical constant/addrec ordering.
1188111879
if (!isa<SCEVConstant>(RHS) && !isa<SCEVAddRecExpr>(LHS))
11882-
return isImpliedCondOperands(FoundPred, RHS, LHS, FoundLHS, FoundRHS,
11883-
CtxI);
11880+
return isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P), RHS,
11881+
LHS, FoundLHS, FoundRHS, CtxI);
1188411882
if (!isa<SCEVConstant>(FoundRHS) && !isa<SCEVAddRecExpr>(FoundLHS))
11885-
return isImpliedCondOperands(Pred, LHS, RHS, FoundRHS, FoundLHS, CtxI);
11883+
return isImpliedCondOperands(*P, LHS, RHS, FoundRHS, FoundLHS, CtxI);
1188611884

1188711885
// There's no clear preference between forms 3. and 4., try both. Avoid
1188811886
// forming getNotSCEV of pointer values as the resulting subtract is
1188911887
// not legal.
1189011888
if (!LHS->getType()->isPointerTy() && !RHS->getType()->isPointerTy() &&
11891-
isImpliedCondOperands(FoundPred, getNotSCEV(LHS), getNotSCEV(RHS),
11892-
FoundLHS, FoundRHS, CtxI))
11889+
isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P),
11890+
getNotSCEV(LHS), getNotSCEV(RHS), FoundLHS,
11891+
FoundRHS, CtxI))
1189311892
return true;
1189411893

1189511894
if (!FoundLHS->getType()->isPointerTy() &&
1189611895
!FoundRHS->getType()->isPointerTy() &&
11897-
isImpliedCondOperands(Pred, LHS, RHS, getNotSCEV(FoundLHS),
11896+
isImpliedCondOperands(*P, LHS, RHS, getNotSCEV(FoundLHS),
1189811897
getNotSCEV(FoundRHS), CtxI))
1189911898
return true;
1190011899

@@ -12564,14 +12563,16 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
1256412563
return false;
1256512564

1256612565
// We only want to work with GT comparison so far.
12567-
if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_SLT) {
12566+
if (ICmpInst::isLT(Pred)) {
1256812567
Pred = ICmpInst::getSwappedCmpPredicate(Pred);
1256912568
std::swap(LHS, RHS);
1257012569
std::swap(FoundLHS, FoundRHS);
1257112570
}
1257212571

12572+
CmpInst::Predicate P = Pred.getPreferredSignedPredicate();
12573+
1257312574
// For unsigned, try to reduce it to corresponding signed comparison.
12574-
if (Pred == ICmpInst::ICMP_UGT)
12575+
if (P == ICmpInst::ICMP_UGT)
1257512576
// We can replace unsigned predicate with its signed counterpart if all
1257612577
// involved values are non-negative.
1257712578
// TODO: We could have better support for unsigned.
@@ -12584,10 +12585,10 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
1258412585
FoundRHS) &&
1258512586
isImpliedCondOperands(ICmpInst::ICMP_SGT, RHS, MinusOne, FoundLHS,
1258612587
FoundRHS))
12587-
Pred = ICmpInst::ICMP_SGT;
12588+
P = ICmpInst::ICMP_SGT;
1258812589
}
1258912590

12590-
if (Pred != ICmpInst::ICMP_SGT)
12591+
if (P != ICmpInst::ICMP_SGT)
1259112592
return false;
1259212593

1259312594
auto GetOpFromSExt = [&](const SCEV *S) {

llvm/test/Analysis/ScalarEvolution/exit-count-samesign.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
define i32 @exit_count_samesign(i32 %iter.count, ptr %ptr) {
66
; CHECK-LABEL: 'exit_count_samesign'
77
; CHECK-NEXT: Determining loop execution counts for: @exit_count_samesign
8-
; CHECK-NEXT: Loop %inner.loop: backedge-taken count is (-1 + (1 smax {(-1 + %iter.count)<nsw>,+,-1}<nsw><%outer.loop>))<nsw>
8+
; CHECK-NEXT: Loop %inner.loop: backedge-taken count is {(-2 + %iter.count),+,-1}<nw><%outer.loop>
99
; CHECK-NEXT: Loop %inner.loop: constant max backedge-taken count is i32 2147483646
10-
; CHECK-NEXT: Loop %inner.loop: symbolic max backedge-taken count is (-1 + (1 smax {(-1 + %iter.count)<nsw>,+,-1}<nsw><%outer.loop>))<nsw>
10+
; CHECK-NEXT: Loop %inner.loop: symbolic max backedge-taken count is {(-2 + %iter.count),+,-1}<nw><%outer.loop>
1111
; CHECK-NEXT: Loop %inner.loop: Trip multiple is 1
1212
; CHECK-NEXT: Loop %outer.loop: <multiple exits> Unpredictable backedge-taken count.
1313
; CHECK-NEXT: Loop %outer.loop: Unpredictable constant max backedge-taken count.

llvm/test/Analysis/ScalarEvolution/implied-via-division.ll

Lines changed: 131 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
; RUN: opt < %s -disable-output -passes="print<scalar-evolution>" \
33
; RUN: -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
44

5-
declare void @llvm.experimental.guard(i1, ...)
6-
7-
define void @test_1(i32 %n) nounwind {
8-
; Prove that (n > 1) ===> (n / 2 > 0).
9-
; CHECK-LABEL: 'test_1'
10-
; CHECK-NEXT: Determining loop execution counts for: @test_1
5+
define void @implied1(i32 %n) {
6+
; Prove that (n s> 1) ===> (n / 2 s> 0).
7+
; CHECK-LABEL: 'implied1'
8+
; CHECK-NEXT: Determining loop execution counts for: @implied1
119
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + %n.div.2)<nsw>
1210
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
1311
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + %n.div.2)<nsw>
@@ -29,10 +27,35 @@ exit:
2927
ret void
3028
}
3129

32-
define void @test_1neg(i32 %n) nounwind {
33-
; Prove that (n > 0) =\=> (n / 2 > 0).
34-
; CHECK-LABEL: 'test_1neg'
35-
; CHECK-NEXT: Determining loop execution counts for: @test_1neg
30+
define void @implied1_samesign(i32 %n) {
31+
; Prove that (n > 1) ===> (n / 2 s> 0).
32+
; CHECK-LABEL: 'implied1_samesign'
33+
; CHECK-NEXT: Determining loop execution counts for: @implied1_samesign
34+
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + %n.div.2)<nsw>
35+
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
36+
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + %n.div.2)<nsw>
37+
; CHECK-NEXT: Loop %header: Trip multiple is 1
38+
;
39+
entry:
40+
%cmp1 = icmp samesign ugt i32 %n, 1
41+
%n.div.2 = sdiv i32 %n, 2
42+
call void @llvm.assume(i1 %cmp1)
43+
br label %header
44+
45+
header:
46+
%indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
47+
%indvar.next = add i32 %indvar, 1
48+
%exitcond = icmp sgt i32 %n.div.2, %indvar.next
49+
br i1 %exitcond, label %header, label %exit
50+
51+
exit:
52+
ret void
53+
}
54+
55+
define void @implied1_neg(i32 %n) {
56+
; Prove that (n s> 0) =\=> (n / 2 s> 0).
57+
; CHECK-LABEL: 'implied1_neg'
58+
; CHECK-NEXT: Determining loop execution counts for: @implied1_neg
3659
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
3760
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
3861
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
@@ -54,10 +77,10 @@ exit:
5477
ret void
5578
}
5679

57-
define void @test_2(i32 %n) nounwind {
58-
; Prove that (n >= 2) ===> (n / 2 > 0).
59-
; CHECK-LABEL: 'test_2'
60-
; CHECK-NEXT: Determining loop execution counts for: @test_2
80+
define void @implied2(i32 %n) {
81+
; Prove that (n s>= 2) ===> (n / 2 s> 0).
82+
; CHECK-LABEL: 'implied2'
83+
; CHECK-NEXT: Determining loop execution counts for: @implied2
6184
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + %n.div.2)<nsw>
6285
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
6386
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + %n.div.2)<nsw>
@@ -79,10 +102,35 @@ exit:
79102
ret void
80103
}
81104

82-
define void @test_2neg(i32 %n) nounwind {
83-
; Prove that (n >= 1) =\=> (n / 2 > 0).
84-
; CHECK-LABEL: 'test_2neg'
85-
; CHECK-NEXT: Determining loop execution counts for: @test_2neg
105+
define void @implied2_samesign(i32 %n) {
106+
; Prove that (n >= 2) ===> (n / 2 s> 0).
107+
; CHECK-LABEL: 'implied2_samesign'
108+
; CHECK-NEXT: Determining loop execution counts for: @implied2_samesign
109+
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
110+
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
111+
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
112+
; CHECK-NEXT: Loop %header: Trip multiple is 1
113+
;
114+
entry:
115+
%cmp1 = icmp samesign uge i32 %n, 2
116+
%n.div.2 = sdiv i32 %n, 2
117+
call void @llvm.assume(i1 %cmp1)
118+
br label %header
119+
120+
header:
121+
%indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
122+
%indvar.next = add i32 %indvar, 1
123+
%exitcond = icmp sgt i32 %n.div.2, %indvar.next
124+
br i1 %exitcond, label %header, label %exit
125+
126+
exit:
127+
ret void
128+
}
129+
130+
define void @implied2_neg(i32 %n) {
131+
; Prove that (n s>= 1) =\=> (n / 2 s> 0).
132+
; CHECK-LABEL: 'implied2_neg'
133+
; CHECK-NEXT: Determining loop execution counts for: @implied2_neg
86134
; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
87135
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741822
88136
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
@@ -104,10 +152,10 @@ exit:
104152
ret void
105153
}
106154

107-
define void @test_3(i32 %n) nounwind {
108-
; Prove that (n > -2) ===> (n / 2 >= 0).
109-
; CHECK-LABEL: 'test_3'
110-
; CHECK-NEXT: Determining loop execution counts for: @test_3
155+
define void @implied3(i32 %n) {
156+
; Prove that (n s> -2) ===> (n / 2 s>= 0).
157+
; CHECK-LABEL: 'implied3'
158+
; CHECK-NEXT: Determining loop execution counts for: @implied3
111159
; CHECK-NEXT: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
112160
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741824
113161
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (1 + %n.div.2)<nsw>
@@ -129,10 +177,35 @@ exit:
129177
ret void
130178
}
131179

132-
define void @test_3neg(i32 %n) nounwind {
180+
define void @implied3_samesign(i32 %n) {
181+
; Prove that (n > -2) ===> (n / 2 s>= 0).
182+
; CHECK-LABEL: 'implied3_samesign'
183+
; CHECK-NEXT: Determining loop execution counts for: @implied3_samesign
184+
; CHECK-NEXT: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
185+
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1
186+
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (1 + %n.div.2)<nsw>
187+
; CHECK-NEXT: Loop %header: Trip multiple is 1
188+
;
189+
entry:
190+
%cmp1 = icmp samesign ugt i32 %n, -2
191+
%n.div.2 = sdiv i32 %n, 2
192+
call void @llvm.assume(i1 %cmp1)
193+
br label %header
194+
195+
header:
196+
%indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
197+
%indvar.next = add i32 %indvar, 1
198+
%exitcond = icmp sge i32 %n.div.2, %indvar
199+
br i1 %exitcond, label %header, label %exit
200+
201+
exit:
202+
ret void
203+
}
204+
205+
define void @implied3_neg(i32 %n) {
133206
; Prove that (n > -3) =\=> (n / 2 >= 0).
134-
; CHECK-LABEL: 'test_3neg'
135-
; CHECK-NEXT: Determining loop execution counts for: @test_3neg
207+
; CHECK-LABEL: 'implied3_neg'
208+
; CHECK-NEXT: Determining loop execution counts for: @implied3_neg
136209
; CHECK-NEXT: Loop %header: backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)
137210
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741824
138211
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)
@@ -154,10 +227,10 @@ exit:
154227
ret void
155228
}
156229

157-
define void @test_4(i32 %n) nounwind {
158-
; Prove that (n >= -1) ===> (n / 2 >= 0).
159-
; CHECK-LABEL: 'test_4'
160-
; CHECK-NEXT: Determining loop execution counts for: @test_4
230+
define void @implied4(i32 %n) {
231+
; Prove that (n s>= -1) ===> (n / 2 s>= 0).
232+
; CHECK-LABEL: 'implied4'
233+
; CHECK-NEXT: Determining loop execution counts for: @implied4
161234
; CHECK-NEXT: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
162235
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741824
163236
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (1 + %n.div.2)<nsw>
@@ -179,10 +252,35 @@ exit:
179252
ret void
180253
}
181254

182-
define void @test_4neg(i32 %n) nounwind {
183-
; Prove that (n >= -2) =\=> (n / 2 >= 0).
184-
; CHECK-LABEL: 'test_4neg'
185-
; CHECK-NEXT: Determining loop execution counts for: @test_4neg
255+
define void @implied4_samesign(i32 %n) {
256+
; Prove that (n >= -1) ===> (n / 2 s>= 0).
257+
; CHECK-LABEL: 'implied4_samesign'
258+
; CHECK-NEXT: Determining loop execution counts for: @implied4_samesign
259+
; CHECK-NEXT: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
260+
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1
261+
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (1 + %n.div.2)<nsw>
262+
; CHECK-NEXT: Loop %header: Trip multiple is 1
263+
;
264+
entry:
265+
%cmp1 = icmp samesign uge i32 %n, -1
266+
%n.div.2 = sdiv i32 %n, 2
267+
call void @llvm.assume(i1 %cmp1)
268+
br label %header
269+
270+
header:
271+
%indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
272+
%indvar.next = add i32 %indvar, 1
273+
%exitcond = icmp sge i32 %n.div.2, %indvar
274+
br i1 %exitcond, label %header, label %exit
275+
276+
exit:
277+
ret void
278+
}
279+
280+
define void @implied4_neg(i32 %n) {
281+
; Prove that (n s>= -2) =\=> (n / 2 s>= 0).
282+
; CHECK-LABEL: 'implied4_neg'
283+
; CHECK-NEXT: Determining loop execution counts for: @implied4_neg
186284
; CHECK-NEXT: Loop %header: backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)
187285
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 1073741824
188286
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)

llvm/test/Transforms/IndVarSimplify/iv-ext-samesign.ll

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,32 @@ define i32 @iv_zext_zext_gt_slt(i32 %iter.count, ptr %ptr) {
6868
; CHECK-LABEL: define i32 @iv_zext_zext_gt_slt(
6969
; CHECK-SAME: i32 [[ITER_COUNT:%.*]], ptr [[PTR:%.*]]) {
7070
; CHECK-NEXT: [[ENTRY:.*]]:
71-
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[ITER_COUNT]] to i64
71+
; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[ITER_COUNT]], -1
7272
; CHECK-NEXT: br label %[[OUTER_LOOP:.*]]
7373
; CHECK: [[PH_LOOPEXIT:.*]]:
7474
; CHECK-NEXT: br label %[[PH:.*]]
7575
; CHECK: [[PH]]:
76+
; CHECK-NEXT: [[INDVARS_IV_NEXT3:%.*]] = add i32 [[INDVARS_IV1:%.*]], -1
7677
; CHECK-NEXT: br label %[[OUTER_LOOP]]
7778
; CHECK: [[OUTER_LOOP]]:
78-
; CHECK-NEXT: [[INDVARS_IV1:%.*]] = phi i64 [ [[INDVARS_IV_NEXT2:%.*]], %[[PH]] ], [ [[TMP0]], %[[ENTRY]] ]
79-
; CHECK-NEXT: [[INDVARS_IV_NEXT2]] = add nsw i64 [[INDVARS_IV1]], -1
79+
; CHECK-NEXT: [[INDVARS_IV1]] = phi i32 [ [[INDVARS_IV_NEXT3]], %[[PH]] ], [ [[TMP0]], %[[ENTRY]] ]
80+
; CHECK-NEXT: [[IV_OUTER:%.*]] = phi i32 [ [[IV_OUTER_1:%.*]], %[[PH]] ], [ [[ITER_COUNT]], %[[ENTRY]] ]
81+
; CHECK-NEXT: [[IV_OUTER_1]] = add nsw i32 [[IV_OUTER]], -1
82+
; CHECK-NEXT: [[INDVARS_IV_NEXT2:%.*]] = zext nneg i32 [[IV_OUTER_1]] to i64
8083
; CHECK-NEXT: [[GEP_OUTER:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[INDVARS_IV_NEXT2]]
8184
; CHECK-NEXT: store i8 0, ptr [[GEP_OUTER]], align 1
82-
; CHECK-NEXT: [[EXIT_COND_OUTER:%.*]] = icmp samesign ugt i64 [[INDVARS_IV1]], 1
85+
; CHECK-NEXT: [[EXIT_COND_OUTER:%.*]] = icmp samesign ugt i32 [[IV_OUTER]], 1
8386
; CHECK-NEXT: br i1 [[EXIT_COND_OUTER]], label %[[INNER_LOOP_PREHEADER:.*]], label %[[PH]]
8487
; CHECK: [[INNER_LOOP_PREHEADER]]:
88+
; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[INDVARS_IV1]] to i64
8589
; CHECK-NEXT: br label %[[INNER_LOOP:.*]]
8690
; CHECK: [[INNER_LOOP]]:
8791
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[INNER_LOOP_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[INNER_LOOP]] ]
8892
; CHECK-NEXT: [[GEP_INNER:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[INDVARS_IV]]
8993
; CHECK-NEXT: store i8 0, ptr [[GEP_INNER]], align 1
9094
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
91-
; CHECK-NEXT: [[EXIT_COND_INNER:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT]], [[INDVARS_IV_NEXT2]]
92-
; CHECK-NEXT: br i1 [[EXIT_COND_INNER]], label %[[INNER_LOOP]], label %[[PH_LOOPEXIT]]
95+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
96+
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[INNER_LOOP]], label %[[PH_LOOPEXIT]]
9397
; CHECK: [[EXIT:.*:]]
9498
; CHECK-NEXT: ret i32 0
9599
;
@@ -424,28 +428,32 @@ define i32 @iv_sext_sext_gt_slt(i32 %iter.count, ptr %ptr) {
424428
; CHECK-LABEL: define i32 @iv_sext_sext_gt_slt(
425429
; CHECK-SAME: i32 [[ITER_COUNT:%.*]], ptr [[PTR:%.*]]) {
426430
; CHECK-NEXT: [[ENTRY:.*]]:
431+
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[ITER_COUNT]], -1
427432
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[ITER_COUNT]] to i64
428433
; CHECK-NEXT: br label %[[OUTER_LOOP:.*]]
429434
; CHECK: [[PH_LOOPEXIT:.*]]:
430435
; CHECK-NEXT: br label %[[PH:.*]]
431436
; CHECK: [[PH]]:
437+
; CHECK-NEXT: [[INDVARS_IV_NEXT3:%.*]] = add i32 [[INDVARS_IV2:%.*]], -1
432438
; CHECK-NEXT: br label %[[OUTER_LOOP]]
433439
; CHECK: [[OUTER_LOOP]]:
434440
; CHECK-NEXT: [[INDVARS_IV1:%.*]] = phi i64 [ [[INDVARS_IV_NEXT2:%.*]], %[[PH]] ], [ [[TMP0]], %[[ENTRY]] ]
441+
; CHECK-NEXT: [[INDVARS_IV2]] = phi i32 [ [[INDVARS_IV_NEXT3]], %[[PH]] ], [ [[TMP1]], %[[ENTRY]] ]
435442
; CHECK-NEXT: [[INDVARS_IV_NEXT2]] = add nsw i64 [[INDVARS_IV1]], -1
436443
; CHECK-NEXT: [[GEP_OUTER:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[INDVARS_IV_NEXT2]]
437444
; CHECK-NEXT: store i8 0, ptr [[GEP_OUTER]], align 1
438445
; CHECK-NEXT: [[EXIT_COND_OUTER:%.*]] = icmp samesign ugt i64 [[INDVARS_IV1]], 1
439446
; CHECK-NEXT: br i1 [[EXIT_COND_OUTER]], label %[[INNER_LOOP_PREHEADER:.*]], label %[[PH]]
440447
; CHECK: [[INNER_LOOP_PREHEADER]]:
448+
; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[INDVARS_IV2]] to i64
441449
; CHECK-NEXT: br label %[[INNER_LOOP:.*]]
442450
; CHECK: [[INNER_LOOP]]:
443451
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[INNER_LOOP_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[INNER_LOOP]] ]
444452
; CHECK-NEXT: [[GEP_INNER:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[INDVARS_IV]]
445453
; CHECK-NEXT: store i8 0, ptr [[GEP_INNER]], align 1
446454
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
447-
; CHECK-NEXT: [[EXIT_COND_INNER:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT]], [[INDVARS_IV_NEXT2]]
448-
; CHECK-NEXT: br i1 [[EXIT_COND_INNER]], label %[[INNER_LOOP]], label %[[PH_LOOPEXIT]]
455+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
456+
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[INNER_LOOP]], label %[[PH_LOOPEXIT]]
449457
; CHECK: [[EXIT:.*:]]
450458
; CHECK-NEXT: ret i32 0
451459
;

0 commit comments

Comments
 (0)