[llvm] [LSR] Optimize lsr-term-fold if the operand of condition is PHINode (PR #96048)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 19 08:31:50 PDT 2024
================
@@ -6830,15 +6830,18 @@ canFoldTermCondOfLoop(Loop *L, ScalarEvolution &SE, DominatorTree &DT,
return std::nullopt;
}
- if (!SE.hasLoopInvariantBackedgeTakenCount(L)) {
- LLVM_DEBUG(dbgs() << "Cannot fold on backedge that is loop variant\n");
- return std::nullopt;
- }
-
BasicBlock *LoopLatch = L->getLoopLatch();
BranchInst *BI = dyn_cast<BranchInst>(LoopLatch->getTerminator());
if (!BI || BI->isUnconditional())
return std::nullopt;
+
+ if (!SE.hasLoopInvariantBackedgeTakenCount(L)) {
+ if (isa<SCEVCouldNotCompute>(SE.getExitCount(L, BI->getParent()))) {
----------------
preames wrote:
This change has nothing to do with the patch description. Extending term folding to multiple exit loops is quite subtle, and will absolutely require it's own review.
https://github.com/llvm/llvm-project/pull/96048
More information about the llvm-commits
mailing list