Skip to content

Commit 785d00e

Browse files
committed
IRCE: Fix '"Instruction does not dominate all uses!" after IRCE pass #63984'
1 parent 842e591 commit 785d00e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,13 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
265265
ScalarEvolution &SE,
266266
const SCEVAddRecExpr *&Index,
267267
const SCEV *&End) {
268-
auto IsLoopInvariant = [&SE, L](Value *V) {
269-
return SE.isLoopInvariant(SE.getSCEV(V), L);
268+
auto IsLoopInvariantAndNotUndef = [&SE, L](Value *V) {
269+
const SCEV *S = SE.getSCEV(V);
270+
271+
if (isa<SCEVCouldNotCompute>(S))
272+
return false;
273+
274+
return SE.isLoopInvariant(SE.getSCEV(V), L) && !SE.containsUndefs(S);
270275
};
271276

272277
ICmpInst::Predicate Pred = ICI->getPredicate();
@@ -277,10 +282,10 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
277282
return false;
278283

279284
// Canonicalize to the `Index Pred Invariant` comparison
280-
if (IsLoopInvariant(LHS)) {
285+
if (IsLoopInvariantAndNotUndef(LHS)) {
281286
std::swap(LHS, RHS);
282287
Pred = CmpInst::getSwappedPredicate(Pred);
283-
} else if (!IsLoopInvariant(RHS))
288+
} else if (!IsLoopInvariantAndNotUndef(RHS))
284289
// Both LHS and RHS are loop variant
285290
return false;
286291

0 commit comments

Comments
 (0)