-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. #120749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… collecting loop guards.
@llvm/pr-subscribers-llvm-analysis Author: Julian Nagele (juliannagele) ChangesWhen Fixes #120615. Full diff: https://github.com/llvm/llvm-project/pull/120749.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 1e4bb1d606cd39..91bbe92a94c210 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15754,6 +15754,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
// original header.
// TODO: share this logic with isLoopEntryGuardedByCond.
unsigned NumCollectedConditions = 0;
+ VisitedBlocks.insert(Block);
std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block);
for (; Pair.first;
Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
diff --git a/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll b/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll
index 81fe96a2f30c09..46dccf454f21ac 100644
--- a/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll
+++ b/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll
@@ -310,3 +310,29 @@ inner.header:
exit:
ret void
}
+
+; Checks correct traversal for loops without a unique predecessor
+; outside the loop.
+define void @pr120615() {
+; CHECK-LABEL: pr120615
+; CHECK-NEXT: Determining loop execution counts for: @pr120615
+; CHECK-NEXT: Loop %header: backedge-taken count is i32 0
+; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 0
+; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is i32 0
+; CHECK-NEXT: Loop %header: Trip multiple is 1
+entry:
+ br label %header
+
+bb:
+ br label %header
+
+header:
+ %0 = phi i32 [ %1, %header ], [ 0, %bb ], [ 0, %entry ]
+ %1 = add i32 %0, 1
+ %icmp = icmp slt i32 %0, 0
+ br i1 %icmp, label %header, label %exit
+
+exit:
+ ret void
+
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks
LGTM as well. Can we merge this? |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/10995 Here is the relevant piece of the build log for the reference
|
… collecting loop guards. (llvm#120749) When `collectFromBlock` is called without a predecessor (in particular for loops that don't have a unique predecessor outside the loop) we never start climbing the predecessor chain, and thus don't mark the starting block as visited. Fixes llvm#120615. (cherry picked from commit f035351)
…9797) * [SCEV] Fix exit condition for recursive loop guard collection (llvm#120442) When assumptions are present `Terms.size()` does not actually count the number of conditions collected from dominating branches; introduce a separate counter. Fixes llvm#120237 (cherry picked from commit acfd26a) * [SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. (llvm#120749) When `collectFromBlock` is called without a predecessor (in particular for loops that don't have a unique predecessor outside the loop) we never start climbing the predecessor chain, and thus don't mark the starting block as visited. Fixes llvm#120615. (cherry picked from commit f035351)
When
collectFromBlock
is called without a predecessor (in particular for loops that don't have a unique predecessor outside the loop) we never start climbing the predecessor chain, and thus don't mark the starting block as visited.Fixes #120615.