[llvm] [LV] Only check isVectorizableEarlyExitLoop with multiple exits. (PR #121994)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 12:59:39 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
Author: Florian Hahn (fhahn)
<details>
<summary>Changes</summary>
Currently we emit early-exit related debug messages/remarks even when there is a single exit. Update to only check isVectorizableEarlyExitLoop if there isn't a single exit block.
---
Full diff: https://github.com/llvm/llvm-project/pull/121994.diff
4 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (+13-4)
- (modified) llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll (+5-5)
- (modified) llvm/test/Transforms/LoopVectorize/early_exit_legality.ll (+1-1)
- (modified) llvm/test/Transforms/LoopVectorize/uncountable-single-exit-loops.ll (+3-3)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index cb0b4641b6492b..b11406bb0f390b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1784,14 +1784,23 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
HasUncountableEarlyExit = false;
if (isa<SCEVCouldNotCompute>(PSE.getBackedgeTakenCount())) {
- HasUncountableEarlyExit = true;
- if (!isVectorizableEarlyExitLoop()) {
- UncountableExitingBlocks.clear();
- HasUncountableEarlyExit = false;
+ if (TheLoop->getExitingBlock()) {
+ reportVectorizationFailure("Cannot vectorize uncountable loop",
+ "UnsupportedUncountableLoop", ORE, TheLoop);
if (DoExtraAnalysis)
Result = false;
else
return false;
+ } else {
+ HasUncountableEarlyExit = true;
+ if (!isVectorizableEarlyExitLoop()) {
+ UncountableExitingBlocks.clear();
+ HasUncountableEarlyExit = false;
+ if (DoExtraAnalysis)
+ Result = false;
+ else
+ return false;
+ }
}
}
diff --git a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
index 4c0317e300f190..70134fa6bc78d6 100644
--- a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
+++ b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
@@ -12,7 +12,7 @@
; }
; }
; File, line, and column should match those specified in the metadata
-; CHECK: remark: source.cpp:5:9: loop not vectorized: Cannot vectorize early exit loop
+; CHECK: remark: source.cpp:5:9: loop not vectorized: Cannot vectorize uncountable loop
; CHECK: remark: source.cpp:5:9: loop not vectorized
; void test_disabled(int *A, int Length) {
@@ -46,12 +46,12 @@
; YAML: --- !Analysis
; YAML-NEXT: Pass: loop-vectorize
-; YAML-NEXT: Name: EarlyExitNotLatchPredecessor
+; YAML-NEXT: Name: UnsupportedUncountableLoop
; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }
; YAML-NEXT: Function: _Z4testPii
; YAML-NEXT: Args:
; YAML-NEXT: - String: 'loop not vectorized: '
-; YAML-NEXT: - String: Cannot vectorize early exit loop
+; YAML-NEXT: - String: Cannot vectorize uncountable loop
; YAML-NEXT: ...
; YAML-NEXT: --- !Missed
; YAML-NEXT: Pass: loop-vectorize
@@ -117,12 +117,12 @@
; YAML-NEXT: ...
; YAML-NEXT: --- !Analysis
; YAML-NEXT: Pass: loop-vectorize
-; YAML-NEXT: Name: EarlyExitNotLatchPredecessor
+; YAML-NEXT: Name: UnsupportedUncountableLoop
; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
; YAML-NEXT: Function: test_multiple_failures
; YAML-NEXT: Args:
; YAML-NEXT: - String: 'loop not vectorized: '
-; YAML-NEXT: - String: Cannot vectorize early exit loop
+; YAML-NEXT: - String: Cannot vectorize uncountable loop
; YAML-NEXT: ...
; YAML: --- !Missed
; YAML-NEXT: Pass: loop-vectorize
diff --git a/llvm/test/Transforms/LoopVectorize/early_exit_legality.ll b/llvm/test/Transforms/LoopVectorize/early_exit_legality.ll
index 8df0eaec6a8c9d..6d365b9d77e80b 100644
--- a/llvm/test/Transforms/LoopVectorize/early_exit_legality.ll
+++ b/llvm/test/Transforms/LoopVectorize/early_exit_legality.ll
@@ -357,7 +357,7 @@ loop.end:
define i64 @uncountable_exit_infinite_loop() {
; CHECK-LABEL: LV: Checking a loop in 'uncountable_exit_infinite_loop'
-; CHECK: LV: Not vectorizing: Cannot determine exact exit count for latch block.
+; CHECK: LV: Not vectorizing: Cannot vectorize uncountable loop.
entry:
%p1 = alloca [1024 x i8]
%p2 = alloca [1024 x i8]
diff --git a/llvm/test/Transforms/LoopVectorize/uncountable-single-exit-loops.ll b/llvm/test/Transforms/LoopVectorize/uncountable-single-exit-loops.ll
index 252061335e7365..c3958262f0af89 100644
--- a/llvm/test/Transforms/LoopVectorize/uncountable-single-exit-loops.ll
+++ b/llvm/test/Transforms/LoopVectorize/uncountable-single-exit-loops.ll
@@ -1,17 +1,17 @@
; REQUIRES: asserts
-; RUN: opt -p loop-vectorize -debug %s 2>&1 | FileCheck %s
+; RUN: opt -p loop-vectorize -debug-only=loop-vectorize -S %s 2>&1 | FileCheck %s
; CHECK-LABEL: LV: Checking a loop in 'latch_exit_cannot_compute_btc_due_to_step'
; CHECK: LV: Did not find one integer induction var.
-; CHECK-NEXT: LV: Not vectorizing: Early exit is not the latch predecessor.
+; CHECK-NEXT: LV: Not vectorizing: Cannot vectorize uncountable loop.
; CHECK-NEXT: LV: Interleaving disabled by the pass manager
; CHECK-NEXT: LV: Not vectorizing: Cannot prove legality.
; CHECK-LABEL: LV: Checking a loop in 'header_exit_cannot_compute_btc_due_to_step'
; CHECK: LV: Found an induction variable.
; CHECK-NEXT: LV: Did not find one integer induction var.
-; CHECK-NEXT: LV: Not vectorizing: Cannot determine exact exit count for latch block.
+; CHECK-NEXT: LV: Not vectorizing: Cannot vectorize uncountable loop.
; CHECK-NEXT: LV: Interleaving disabled by the pass manager
; CHECK-NEXT: LV: Not vectorizing: Cannot prove legality.
``````````
</details>
https://github.com/llvm/llvm-project/pull/121994
More information about the llvm-commits
mailing list