Skip to content

Commit a80c878

Browse files
committed
handle compile time "s % m != 0" in isKnownMultipleOf
Do not check for symbolic names, just handle all possible SCEV expressions with compile time tests and record runtime predicates when compile time fails.
1 parent 8c69ebf commit a80c878

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10991,45 +10991,30 @@ bool ScalarEvolution::isKnownMultipleOf(
1099110991
}
1099210992

1099310993
// Basic tests have failed.
10994-
// Record "S % M == 0" in the runtime Assumptions.
10995-
auto recordRuntimePredicate = [&](const SCEV *S) -> void {
10996-
auto *STy = dyn_cast<IntegerType>(S->getType());
10997-
const SCEV *SmodM =
10998-
getURemExpr(S, getConstant(ConstantInt::get(STy, M, false)));
10999-
const SCEV *Zero = getZero(STy);
11000-
11001-
// Check whether "S % M == 0" is known at compile time.
11002-
if (isKnownPredicate(ICmpInst::ICMP_EQ, SmodM, Zero))
11003-
return;
11004-
11005-
const SCEVPredicate *P =
11006-
getComparePredicate(ICmpInst::ICMP_EQ, SmodM, Zero);
10994+
// Check "S % M == 0" at compile time and record runtime Assumptions.
10995+
auto *STy = dyn_cast<IntegerType>(S->getType());
10996+
const SCEV *SmodM =
10997+
getURemExpr(S, getConstant(ConstantInt::get(STy, M, false)));
10998+
const SCEV *Zero = getZero(STy);
10999+
11000+
// Check whether "S % M == 0" is known at compile time.
11001+
if (isKnownPredicate(ICmpInst::ICMP_EQ, SmodM, Zero))
11002+
return true;
1100711003

11008-
// Detect redundant predicates.
11009-
for (auto *A : Assumptions)
11010-
if (A->implies(P, *this))
11011-
return;
11004+
// Check whether "S % M != 0" is known at compile time.
11005+
if (isKnownPredicate(ICmpInst::ICMP_NE, SmodM, Zero))
11006+
return false;
1101211007

11013-
Assumptions.push_back(P);
11014-
return;
11015-
};
11008+
const SCEVPredicate *P = getComparePredicate(ICmpInst::ICMP_EQ, SmodM, Zero);
1101611009

11017-
// Expressions like "n".
11018-
if (isa<SCEVUnknown>(S)) {
11019-
recordRuntimePredicate(S);
11020-
return true;
11021-
}
11022-
11023-
// Expressions like "n + 1" and "n * 3".
11024-
if (isa<SCEVAddExpr>(S) || isa<SCEVMulExpr>(S)) {
11025-
if (SCEVExprContains(S, [](const SCEV *X) { return isa<SCEVUnknown>(X); }))
11026-
recordRuntimePredicate(S);
11027-
return true;
11028-
}
11010+
// Detect redundant predicates.
11011+
for (auto *A : Assumptions)
11012+
if (A->implies(P, *this))
11013+
return true;
1102911014

11030-
LLVM_DEBUG(dbgs() << "SCEV node not handled yet in isKnownMultipleOf: " << *S
11031-
<< "\n");
11032-
return false;
11015+
// Only record non-redundant predicates.
11016+
Assumptions.push_back(P);
11017+
return true;
1103311018
}
1103411019

1103511020
std::pair<const SCEV *, const SCEV *>

0 commit comments

Comments
 (0)