[llvm] 66a8341 - [VPlan] Skip disconnected exit blocks in hasEarlyExit. (#151718)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 03:31:03 PDT 2025
Author: Florian Hahn
Date: 2025-08-04T11:31:00+01:00
New Revision: 66a8341f6d89d562faad667986af8fa584ad7426
URL: https://github.com/llvm/llvm-project/commit/66a8341f6d89d562faad667986af8fa584ad7426
DIFF: https://github.com/llvm/llvm-project/commit/66a8341f6d89d562faad667986af8fa584ad7426.diff
LOG: [VPlan] Skip disconnected exit blocks in hasEarlyExit. (#151718)
Currently hasEarlyExit returns true, if there are multiple exit blocks.
ExitBlocks contains the wrapped original IR exit blocks. Without
checking the predecessors we incorrectly return true for loops with
multiple countable exits, that have been vectorized by requiring a
scalar epilogue. In that case, the exit blocks will get disconnected.
Fix this by filtering out disconnected exit blocks.
Currently this should only impact the 'early-exit vectorized' statistic.
PR: https://github.com/llvm/llvm-project/pull/151718
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/test/Transforms/LoopVectorize/vect.stats.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 6f547a31f4b9f..39f5e3651e9bb 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4228,7 +4228,10 @@ class VPlan {
/// block with multiple predecessors (one for the exit via the latch and one
/// via the other early exit).
bool hasEarlyExit() const {
- return ExitBlocks.size() > 1 ||
+ return count_if(ExitBlocks,
+ [](VPIRBasicBlock *EB) {
+ return EB->getNumPredecessors() != 0;
+ }) > 1 ||
(ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
}
diff --git a/llvm/test/Transforms/LoopVectorize/vect.stats.ll b/llvm/test/Transforms/LoopVectorize/vect.stats.ll
index 033907e079a7d..e3240c8181519 100644
--- a/llvm/test/Transforms/LoopVectorize/vect.stats.ll
+++ b/llvm/test/Transforms/LoopVectorize/vect.stats.ll
@@ -5,7 +5,7 @@
; vectorized) and the third one is not.
; CHECK: 4 loop-vectorize - Number of loops analyzed for vectorization
-; CHECK: 2 loop-vectorize - Number of early exit loops vectorized
+; CHECK: 1 loop-vectorize - Number of early exit loops vectorized
; CHECK: 3 loop-vectorize - Number of loops vectorized
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
More information about the llvm-commits
mailing list