-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LV] Fix emission of debug message in legality check #101924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LV] Fix emission of debug message in legality check #101924
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Madhur Amilkanthwar (madhur13490) ChangesSuccessful vectorization message is emitted even Full diff: https://github.com/llvm/llvm-project/pull/101924.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 465d0df30e3f7..35c841f470261 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1441,10 +1441,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.
@@ -1509,11 +1511,6 @@ 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");
unsigned SCEVThreshold = VectorizeSCEVCheckThreshold;
if (Hints->getForce() == LoopVectorizeHints::FK_Enabled)
@@ -1528,6 +1525,13 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
else
return false;
}
+ if (Result) {
+ LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
+ << (LAI->getRuntimePointerChecking()->Need
+ ? " (with a runtime bound check)"
+ : "")
+ << "!\n");
+ }
// Okay! We've done all the tests. If any have failed, return false. Otherwise
// we can vectorize, and at this point we don't have any other mem analysis
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
6782629
to
444a13a
Compare
Kindly add a test? |
444a13a
to
d5faf52
Compare
Done. The test makes sure that we don't emit both successful and unsuccessful message about vectorization. |
Gentle ping to the reviewers! |
@@ -1528,6 +1525,13 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) { | |||
else | |||
return false; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd add an empty line between these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refreshed code.
; successful and unsuccessful message about vectorization. | ||
|
||
; RUN: opt -passes=loop-vectorize -debug -disable-output -pass-remarks-missed=loop-vectorize %s 2>&1 | FileCheck %s | ||
; CHECK-NOT: LV: We can vectorize this loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also add this CHECK-NOT after the CHECK as well, to make sure it doesn't happen in either order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
; CHECK: LV: Not vectorizing: Cannot prove legality | ||
|
||
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" | ||
target triple = "aarch64-unknown-linux-gnu" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test depend on the target triple? If so, it must go in the AArch64 directory. Though ideally it would be triple-independent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this does not depend on TT. I have done the change.
@a = dso_local global [32000 x i32] zeroinitializer, align 4 | ||
@b = dso_local global [32000 x i32] zeroinitializer, align 4 | ||
|
||
define dso_local void @foo() local_unnamed_addr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary dso_local / local_unnamed_addr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done!
@@ -1528,6 +1525,13 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) { | |||
else | |||
return false; | |||
} | |||
if (Result) { | |||
LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be kept at the original place? the check above is a profitability check, we can still vectorize the loop
Might be good to have a test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. But I think the meaning attached to "false" returned from this function is slightly misleading. If "false" is returned through the last instance then the loop is vectorizable but not profitable. For other instances, it is not vectorizable at all. I think the name of the function should be canVectorizeAndProfitable
.
6777222
to
8bb9dc7
Compare
ret void | ||
|
||
for.body: ; preds = %entry, %for.body | ||
%0 = phi i32 [ %.pre17, %entry ], [ %add6, %for.body ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to give the variables better names: %0
, %1
, %.pre
, %.pre17
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
; CHECK: LV: Not vectorizing: Cannot prove legality | ||
; CHECK-NOT: LV: We can vectorize this loop | ||
|
||
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, removed.
; This test asserts that we don't emit both | ||
; successful and unsuccessful message about vectorization. | ||
|
||
; RUN: opt -passes=loop-vectorize -debug -disable-output -pass-remarks-missed=loop-vectorize %s 2>&1 | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-debug-only=loop-vectorize? Are we checking pass remarks as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks for catching!
@@ -0,0 +1,36 @@ | |||
; This test asserts that we don't emit both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd probably name this test dbg-print-no-vectorize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflow comment
; This test asserts that we don't emit both | |
; This test checks that we don't emit both successful and unsuccessful |
@@ -1441,10 +1441,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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps possible to check this message as well? Shouldn't the debug message start with an "LV: " prefix for uniformity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
; This test asserts that we don't emit both | ||
; successful and unsuccessful message about vectorization. | ||
|
||
; RUN: opt -passes=loop-vectorize -debug -disable-output -pass-remarks-missed=loop-vectorize %s 2>&1 | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs REQUIRES: asserts, since we're checking debug printing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
8bb9dc7
to
01a81a0
Compare
for.body: ; preds = %entry, %for.body | ||
%0 = phi i32 [ %val_a, %entry ], [ %add6, %for.body ] | ||
%1 = phi i32 [ %load_a_gep, %entry ], [ %2, %for.body ] | ||
%indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ] | |
%iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
%1 = phi i32 [ %load_a_gep, %entry ], [ %2, %for.body ] | ||
%indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ] | ||
%arrayidx = getelementptr inbounds [32000 x i32], ptr @a, i64 0, i64 %indvars.iv | ||
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 | |
%iv.next = add nuw nsw i64 %indvars.iv, 1 |
|
||
define void @foo() { | ||
entry: | ||
%load_a_gep = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass as arg to simplify test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
define void @foo() { | ||
entry: | ||
%load_a_gep = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4 | ||
%val_a = load i32, ptr @a, align 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass as arg to simplify test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sure. Done
; CHECK-NOT: LV: We can vectorize this loop | ||
|
||
@a = global [32000 x i32] zeroinitializer, align 4 | ||
@b = global [32000 x i32] zeroinitializer, align 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! yes, removed.
%val_a = load i32, ptr @a, align 4 | ||
br label %for.body | ||
|
||
for.cond.cleanup: ; preds = %for.body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be good to move this to the end of the function and shorten name to something like exit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,36 @@ | |||
; This test asserts that we don't emit both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflow comment
; This test asserts that we don't emit both | |
; This test checks that we don't emit both successful and unsuccessful |
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to the original change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but doing it as good to have a debug message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, generally it's preferable to keep things separate if possible. Fine to keep it here in the PR for now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks!
01a81a0
to
b99b73e
Compare
@fhahn Does the new revision look ok now? |
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, generally it's preferable to keep things separate if possible. Fine to keep it here in the PR for now though
unsigned SCEVThreshold = VectorizeSCEVCheckThreshold; | ||
if (Hints->getForce() == LoopVectorizeHints::FK_Enabled) | ||
SCEVThreshold = PragmaVectorizeSCEVCheckThreshold; | ||
|
||
if (Result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also keep where the message is emitted at the original place, so SCEVThreshold
's definition is closer to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, there is no reason to change. Thanks! Hopefully, looks good now :)
b99b73e
to
800f54b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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.
800f54b
to
2881500
Compare
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.