@@ -132,22 +132,6 @@ static bool IsConstant(Definition* def, int64_t* val) {
132
132
return false ;
133
133
}
134
134
135
- // Helper method to trace back to original true definition, now
136
- // also ignoring constraints and (un)boxing operations, since
137
- // these are not relevant to the induction behavior.
138
- static Definition* OriginalDefinition (Definition* def) {
139
- while (true ) {
140
- Definition* orig;
141
- if (def->IsConstraint () || def->IsBox () || def->IsUnbox ()) {
142
- orig = def->InputAt (0 )->definition ();
143
- } else {
144
- orig = def->OriginalDefinition ();
145
- }
146
- if (orig == def) return def;
147
- def = orig;
148
- }
149
- }
150
-
151
135
void InductionVarAnalysis::VisitHierarchy (LoopInfo* loop) {
152
136
for (; loop != nullptr ; loop = loop->next_ ) {
153
137
VisitLoop (loop);
@@ -273,7 +257,7 @@ void InductionVarAnalysis::Classify(LoopInfo* loop, Definition* def) {
273
257
} else if (def->IsUnaryIntegerOp ()) {
274
258
induc = TransferUnary (loop, def);
275
259
} else {
276
- Definition* orig = OriginalDefinition ( def);
260
+ Definition* orig = def-> OriginalDefinitionIgnoreBoxingAndConstraints ( );
277
261
if (orig != def) {
278
262
induc = Lookup (loop, orig); // pass-through
279
263
}
@@ -316,7 +300,7 @@ void InductionVarAnalysis::ClassifySCC(LoopInfo* loop) {
316
300
} else if (def->IsConstraint ()) {
317
301
update = SolveConstraint (loop, def, init);
318
302
} else {
319
- Definition* orig = OriginalDefinition ( def);
303
+ Definition* orig = def-> OriginalDefinitionIgnoreBoxingAndConstraints ( );
320
304
if (orig != def) {
321
305
update = LookupCycle (orig); // pass-through
322
306
}
@@ -370,10 +354,14 @@ void InductionVarAnalysis::ClassifyControl(LoopInfo* loop) {
370
354
// Comparison against linear constant stride induction?
371
355
// Express the comparison such that induction appears left.
372
356
int64_t stride = 0 ;
373
- InductionVar* x =
374
- Lookup (loop, OriginalDefinition (compare->left ()->definition ()));
375
- InductionVar* y =
376
- Lookup (loop, OriginalDefinition (compare->right ()->definition ()));
357
+ auto left = compare->left ()
358
+ ->definition ()
359
+ ->OriginalDefinitionIgnoreBoxingAndConstraints ();
360
+ auto right = compare->right ()
361
+ ->definition ()
362
+ ->OriginalDefinitionIgnoreBoxingAndConstraints ();
363
+ InductionVar* x = Lookup (loop, left);
364
+ InductionVar* y = Lookup (loop, right);
377
365
if (InductionVar::IsLinear (x, &stride) && InductionVar::IsInvariant (y)) {
378
366
// ok as is
379
367
} else if (InductionVar::IsInvariant (x) &&
0 commit comments