[llvm] f035351 - [SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. (#120749)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 31 01:24:52 PST 2024
Author: Julian Nagele
Date: 2024-12-31T09:24:48Z
New Revision: f035351af785b7349ab7bcd55149c781ceca24cb
URL: https://github.com/llvm/llvm-project/commit/f035351af785b7349ab7bcd55149c781ceca24cb
DIFF: https://github.com/llvm/llvm-project/commit/f035351af785b7349ab7bcd55149c781ceca24cb.diff
LOG: [SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. (#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 https://github.com/llvm/llvm-project/issues/120615.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 8ab56025546e65..b5668a14a4a212 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15765,6 +15765,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
+
+}
More information about the llvm-commits
mailing list