@@ -145,7 +145,7 @@ class InductiveRangeCheck {
145
145
Use *CheckUse = nullptr ;
146
146
147
147
static bool parseRangeCheckICmp (Loop *L, ICmpInst *ICI, ScalarEvolution &SE,
148
- Value *&Index, Value *&Length );
148
+ const SCEV *&Index, const SCEV *&End );
149
149
150
150
static void
151
151
extractRangeChecksFromCond (Loop *L, ScalarEvolution &SE, Use &ConditionUse,
@@ -284,13 +284,13 @@ INITIALIZE_PASS_END(IRCELegacyPass, "irce", "Inductive range check elimination",
284
284
false , false )
285
285
286
286
// / Parse a single ICmp instruction, `ICI`, into a range check. If `ICI` cannot
287
- // / be interpreted as a range check, return false and set `Index` and `Length `
288
- // / to `nullptr`. Otherwise set `Index` to the value being range checked, and
289
- // / set `Length ` to the upper limit `Index` is being range checked.
290
- bool
291
- InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI ,
292
- ScalarEvolution &SE, Value *&Index,
293
- Value *&Length ) {
287
+ // / be interpreted as a range check, return false and set `Index` and `End `
288
+ // / to `nullptr`. Otherwise set `Index` to the SCEV being range checked, and
289
+ // / set `End ` to the upper limit `Index` is being range checked.
290
+ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
291
+ ScalarEvolution &SE ,
292
+ const SCEV *&Index,
293
+ const SCEV *&End ) {
294
294
auto IsLoopInvariant = [&SE, L](Value *V) {
295
295
return SE.isLoopInvariant (SE.getSCEV (V), L);
296
296
};
@@ -308,7 +308,7 @@ InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
308
308
[[fallthrough]];
309
309
case ICmpInst::ICMP_SGE:
310
310
if (match (RHS, m_ConstantInt<0 >())) {
311
- Index = LHS;
311
+ Index = SE. getSCEV ( LHS) ;
312
312
return true ; // Lower.
313
313
}
314
314
return false ;
@@ -318,13 +318,13 @@ InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
318
318
[[fallthrough]];
319
319
case ICmpInst::ICMP_SGT:
320
320
if (match (RHS, m_ConstantInt<-1 >())) {
321
- Index = LHS;
321
+ Index = SE. getSCEV ( LHS) ;
322
322
return true ; // Lower.
323
323
}
324
324
325
325
if (IsLoopInvariant (LHS)) {
326
- Index = RHS;
327
- Length = LHS;
326
+ Index = SE. getSCEV ( RHS) ;
327
+ End = SE. getSCEV ( LHS) ;
328
328
return true ; // Upper.
329
329
}
330
330
return false ;
@@ -334,8 +334,8 @@ InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
334
334
[[fallthrough]];
335
335
case ICmpInst::ICMP_UGT:
336
336
if (IsLoopInvariant (LHS)) {
337
- Index = RHS;
338
- Length = LHS;
337
+ Index = SE. getSCEV ( RHS) ;
338
+ End = SE. getSCEV ( LHS) ;
339
339
return true ; // Both lower and upper.
340
340
}
341
341
return false ;
@@ -365,23 +365,20 @@ void InductiveRangeCheck::extractRangeChecksFromCond(
365
365
if (!ICI)
366
366
return ;
367
367
368
- Value *Length = nullptr , *Index;
369
- if (!parseRangeCheckICmp (L, ICI, SE, Index, Length ))
368
+ const SCEV *End = nullptr , *Index = nullptr ;
369
+ if (!parseRangeCheckICmp (L, ICI, SE, Index, End ))
370
370
return ;
371
371
372
- const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(SE. getSCEV ( Index) );
372
+ const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(Index);
373
373
bool IsAffineIndex =
374
374
IndexAddRec && (IndexAddRec->getLoop () == L) && IndexAddRec->isAffine ();
375
375
376
376
if (!IsAffineIndex)
377
377
return ;
378
378
379
- const SCEV *End = nullptr ;
380
379
// We strengthen "0 <= I" to "0 <= I < INT_SMAX" and "I < L" to "0 <= I < L".
381
380
// We can potentially do much better here.
382
- if (Length)
383
- End = SE.getSCEV (Length);
384
- else {
381
+ if (!End) {
385
382
// So far we can only reach this point for Signed range check. This may
386
383
// change in future. In this case we will need to pick Unsigned max for the
387
384
// unsigned range check.
0 commit comments