[llvm] cd46829 - [LV] Fix emission of debug message in legality check (#101924)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 03:58:42 PDT 2024
Author: Madhur Amilkanthwar
Date: 2024-09-04T16:28:39+05:30
New Revision: cd46829e547d2d0aa3cb0ef7c9de59c507eaaecc
URL: https://github.com/llvm/llvm-project/commit/cd46829e547d2d0aa3cb0ef7c9de59c507eaaecc
DIFF: https://github.com/llvm/llvm-project/commit/cd46829e547d2d0aa3cb0ef7c9de59c507eaaecc.diff
LOG: [LV] Fix emission of debug message in legality check (#101924)
Successful vectorization message is emitted even
after "Result" is false. "Result" = false indicates failure of one of
the legality check and thus
successful message should not be printed.
Added:
llvm/test/Transforms/LoopVectorize/check-no-vectorize.ll
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 66a779da8c25bc..7042af6dd8eae5 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1451,10 +1451,12 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
// Check whether the loop-related control flow in the loop nest is expected by
// vectorizer.
if (!canVectorizeLoopNestCFG(TheLoop, UseVPlanNativePath)) {
- if (DoExtraAnalysis)
+ if (DoExtraAnalysis) {
+ LLVM_DEBUG(dbgs() << "LV: legality check failed: loop nest");
Result = false;
- else
+ } else {
return false;
+ }
}
// We need to have a loop header.
@@ -1519,17 +1521,21 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
return false;
}
- LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
- << (LAI->getRuntimePointerChecking()->Need
- ? " (with a runtime bound check)"
- : "")
- << "!\n");
+ if (Result) {
+ LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
+ << (LAI->getRuntimePointerChecking()->Need
+ ? " (with a runtime bound check)"
+ : "")
+ << "!\n");
+ }
unsigned SCEVThreshold = VectorizeSCEVCheckThreshold;
if (Hints->getForce() == LoopVectorizeHints::FK_Enabled)
SCEVThreshold = PragmaVectorizeSCEVCheckThreshold;
if (PSE.getPredicate().getComplexity() > SCEVThreshold) {
+ LLVM_DEBUG(dbgs() << "LV: Vectorization not profitable "
+ "due to SCEVThreshold");
reportVectorizationFailure("Too many SCEV checks needed",
"Too many SCEV assumptions need to be made and checked at runtime",
"TooManySCEVRunTimeChecks", ORE, TheLoop);
diff --git a/llvm/test/Transforms/LoopVectorize/check-no-vectorize.ll b/llvm/test/Transforms/LoopVectorize/check-no-vectorize.ll
new file mode 100644
index 00000000000000..e45a2049313199
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/check-no-vectorize.ll
@@ -0,0 +1,32 @@
+; This test checks that we don't emit both
+; successful and unsuccessful message about vectorization.
+
+; REQUIRES: asserts
+; RUN: opt -passes=loop-vectorize -debug -disable-output < %s 2>&1 | FileCheck %s
+; CHECK-NOT: LV: We can vectorize this loop
+; CHECK: LV: Not vectorizing: Cannot prove legality
+; CHECK-NOT: LV: We can vectorize this loop
+
+ at a = global [32000 x i32] zeroinitializer, align 4
+
+define void @foo(i32 %val1, i32 %val2) {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %0 = phi i32 [ %val1, %entry ], [ %add1, %for.body ]
+ %1 = phi i32 [ %val2, %entry ], [ %2, %for.body ]
+ %iv = phi i64 [ 1, %entry ], [ %iv.next, %for.body ]
+ %arrayidx = getelementptr inbounds [32000 x i32], ptr @a, i64 0, i64 %iv
+ %iv.next = add nuw nsw i64 %iv, 1
+ %arrayidx2 = getelementptr inbounds [32000 x i32], ptr @a, i64 0, i64 %iv.next
+ %2 = load i32, ptr %arrayidx2, align 4
+ %add0 = add nsw i32 %2, %1
+ %add1 = add nsw i32 %add0, %0
+ store i32 %add1, ptr %arrayidx, align 4
+ %exitcond = icmp eq i64 %iv.next, 31999
+ br i1 %exitcond, label %exit, label %for.body
+
+exit: ; preds = %for.body
+ ret void
+}
More information about the llvm-commits
mailing list