Skip to content

Commit cd46829

Browse files
authored
[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.
1 parent 6d35634 commit cd46829

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,10 +1451,12 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
14511451
// Check whether the loop-related control flow in the loop nest is expected by
14521452
// vectorizer.
14531453
if (!canVectorizeLoopNestCFG(TheLoop, UseVPlanNativePath)) {
1454-
if (DoExtraAnalysis)
1454+
if (DoExtraAnalysis) {
1455+
LLVM_DEBUG(dbgs() << "LV: legality check failed: loop nest");
14551456
Result = false;
1456-
else
1457+
} else {
14571458
return false;
1459+
}
14581460
}
14591461

14601462
// We need to have a loop header.
@@ -1519,17 +1521,21 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
15191521
return false;
15201522
}
15211523

1522-
LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
1523-
<< (LAI->getRuntimePointerChecking()->Need
1524-
? " (with a runtime bound check)"
1525-
: "")
1526-
<< "!\n");
1524+
if (Result) {
1525+
LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
1526+
<< (LAI->getRuntimePointerChecking()->Need
1527+
? " (with a runtime bound check)"
1528+
: "")
1529+
<< "!\n");
1530+
}
15271531

15281532
unsigned SCEVThreshold = VectorizeSCEVCheckThreshold;
15291533
if (Hints->getForce() == LoopVectorizeHints::FK_Enabled)
15301534
SCEVThreshold = PragmaVectorizeSCEVCheckThreshold;
15311535

15321536
if (PSE.getPredicate().getComplexity() > SCEVThreshold) {
1537+
LLVM_DEBUG(dbgs() << "LV: Vectorization not profitable "
1538+
"due to SCEVThreshold");
15331539
reportVectorizationFailure("Too many SCEV checks needed",
15341540
"Too many SCEV assumptions need to be made and checked at runtime",
15351541
"TooManySCEVRunTimeChecks", ORE, TheLoop);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; This test checks that we don't emit both
2+
; successful and unsuccessful message about vectorization.
3+
4+
; REQUIRES: asserts
5+
; RUN: opt -passes=loop-vectorize -debug -disable-output < %s 2>&1 | FileCheck %s
6+
; CHECK-NOT: LV: We can vectorize this loop
7+
; CHECK: LV: Not vectorizing: Cannot prove legality
8+
; CHECK-NOT: LV: We can vectorize this loop
9+
10+
@a = global [32000 x i32] zeroinitializer, align 4
11+
12+
define void @foo(i32 %val1, i32 %val2) {
13+
entry:
14+
br label %for.body
15+
16+
for.body: ; preds = %entry, %for.body
17+
%0 = phi i32 [ %val1, %entry ], [ %add1, %for.body ]
18+
%1 = phi i32 [ %val2, %entry ], [ %2, %for.body ]
19+
%iv = phi i64 [ 1, %entry ], [ %iv.next, %for.body ]
20+
%arrayidx = getelementptr inbounds [32000 x i32], ptr @a, i64 0, i64 %iv
21+
%iv.next = add nuw nsw i64 %iv, 1
22+
%arrayidx2 = getelementptr inbounds [32000 x i32], ptr @a, i64 0, i64 %iv.next
23+
%2 = load i32, ptr %arrayidx2, align 4
24+
%add0 = add nsw i32 %2, %1
25+
%add1 = add nsw i32 %add0, %0
26+
store i32 %add1, ptr %arrayidx, align 4
27+
%exitcond = icmp eq i64 %iv.next, 31999
28+
br i1 %exitcond, label %exit, label %for.body
29+
30+
exit: ; preds = %for.body
31+
ret void
32+
}

0 commit comments

Comments
 (0)