[llvm] [ConstraintElim] Use cond from header as upper bound on IV in exit BB. (PR #94610)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 02:43:13 PDT 2024
================
@@ -1031,6 +1031,27 @@ void State::addInfoForInductions(BasicBlock &BB) {
WorkList.push_back(FactOrCheck::getConditionFact(
DTN, CmpInst::ICMP_SLT, PN, B,
ConditionTy(CmpInst::ICMP_SLE, StartValue, B)));
+
+ assert(!StepOffset.isNegative() && "induction must be increasing");
+ // Try to add condition from header to the unique exit block, if there is one.
+ // When exiting either with EQ or NE, we know that the induction value must be
+ // u<= B, as a different exit may exit earlier.
+ ConditionTy Precond;
+ if (!MonotonicallyIncreasingUnsigned)
+ Precond = {CmpInst::ICMP_ULE, StartValue, B};
+ if (Pred == CmpInst::ICMP_EQ) {
+ BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(0);
+ if (L->getUniqueExitBlock() == EB) {
+ WorkList.emplace_back(FactOrCheck::getConditionFact(
+ DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
+ }
+ }
+ if (Pred == CmpInst::ICMP_NE) {
+ BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(1);
+ if (L->getUniqueExitBlock() == EB)
----------------
fhahn wrote:
It's not needed I think, removed the restriction (for the case where each exit block only has a single predecessor in the loop, the patch isn't needed). Tests added in 798754f6c6fe19d19984ca8370806cbcdf5f8294
https://github.com/llvm/llvm-project/pull/94610
More information about the llvm-commits
mailing list