[llvm] [SCEV] Fix exit condition for recursive loop guard collection (PR #120442)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 07:44:48 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Julian Nagele (juliannagele)
<details>
<summary>Changes</summary>
When assumptions are present `Terms.size()` does not actually count the number of conditions collected from dominating branches; introduce a separate counter.
---
Full diff: https://github.com/llvm/llvm-project/pull/120442.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+2-1)
``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index d55d09020fc147..6ba91c4417f724 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15753,6 +15753,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
// predecessors that can be found that have unique successors leading to the
// original header.
// TODO: share this logic with isLoopEntryGuardedByCond.
+ unsigned NumCollectedConditions = 0;
std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block);
for (; Pair.first;
Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
@@ -15767,7 +15768,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
// If we are recursively collecting guards stop after 2
// predecessors to limit compile-time impact for now.
- if (Depth > 0 && Terms.size() == 2)
+ if (Depth > 0 && ++NumCollectedConditions == 2)
break;
}
// Finally, if we stopped climbing the predecessor chain because
``````````
</details>
https://github.com/llvm/llvm-project/pull/120442
More information about the llvm-commits
mailing list