[llvm] [SCEVExpander] Relax hoisting condition for AddRec start (PR #75916)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 12:37:28 PST 2023
================
@@ -980,11 +980,14 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
PostIncLoopSet SavedPostIncLoops = PostIncLoops;
PostIncLoops.clear();
- // Expand code for the start value into the loop preheader.
- assert(L->getLoopPreheader() &&
- "Can't expand add recurrences without a loop preheader!");
- Value *StartV =
- expand(Normalized->getStart(), L->getLoopPreheader()->getTerminator());
+ // Expand code for the start value into the loop predecessor. The loop is not
+ // necessarily in Loop Simplify Form, so assert it's legal to do so.
+ auto *LP = L->getLoopPredecessor();
----------------
averine wrote:
No: At that line 985, I cannot guarantee that `LP` dominates the loop body.
This is "checked" this in the `assert` line 986 (by definition of `getLoopPredecessor()`, `LP` is the unique predecessor of the header iff it's non-zero).
So the patch helps when `L` has no preheader but a unique predecessor (which is legal to hoist into), but leads to the same error when `L` has several predecessors.
https://github.com/llvm/llvm-project/pull/75916
More information about the llvm-commits
mailing list