-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV] Prevent query the computeCost() when VF=1 in emitInvalidCostRemarks(). #117288
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] Prevent query the computeCost() when VF=1 in emitInvalidCostRemarks(). #117288
Conversation
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-llvm-transforms Author: Elvis Wang (ElvisWang123) ChangesWe should only query the computeCost() when the VF is vector. Full diff: https://github.com/llvm/llvm-project/pull/117288.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d13770a35c108f..5a61a6f83e3764 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4373,6 +4373,9 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
SmallVector<RecipeVFPair> InvalidCosts;
for (const auto &Plan : VPlans) {
for (ElementCount VF : Plan->vectorFactors()) {
+ if (VF.isScalar())
+ continue;
+
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
CM);
precomputeCosts(*Plan, VF, CostCtx);
|
@llvm/pr-subscribers-vectorizers Author: Elvis Wang (ElvisWang123) ChangesWe should only query the computeCost() when the VF is vector. Full diff: https://github.com/llvm/llvm-project/pull/117288.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d13770a35c108f..5a61a6f83e3764 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4373,6 +4373,9 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
SmallVector<RecipeVFPair> InvalidCosts;
for (const auto &Plan : VPlans) {
for (ElementCount VF : Plan->vectorFactors()) {
+ if (VF.isScalar())
+ continue;
+
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
CM);
precomputeCosts(*Plan, VF, CostCtx);
|
7619544
to
6f1c1c7
Compare
6f1c1c7
to
2e9579d
Compare
Soft ping! |
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! Seems sensible.
@@ -4372,6 +4372,9 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks( | |||
SmallVector<RecipeVFPair> InvalidCosts; | |||
for (const auto &Plan : VPlans) { | |||
for (ElementCount VF : Plan->vectorFactors()) { | |||
if (VF.isScalar()) |
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.
Could you add a comment here why we skip scalar VFs? Presumably because we don’t expect them to have invalid costs?
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.
Updated comments.
Currently, we cannot query the vplan-based cost model with scalar VF because we use lots of cast<VectorType>(toVectorTy(SrcTy, VF))
in computeCost()
.
f30cdb0
to
9c8caeb
Compare
Found a test case extracted from TSVC s311. |
@@ -0,0 +1,65 @@ | |||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | |||
; RUN: opt < %s -mtriple=riscv64 -mattr=+v -p loop-vectorize -pass-remarks-analysis=loop-vectorize -S | 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.
This doesn't feel quite right, since you're passing -pass-remarks-analysis=loop-vectorize
but not testing the output. Given this test is about remarks, I think we should check the output and also ensure we don't see the VF=1 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.
Passing -pass-remarks-analysis=loop-vectorize
just for triggering emitInvalidCostRemarks()
and make sure the compiler don't crash. I don't have any ideas about testing the remark output.
Something I can imagine is that using --debug-only=loop-vecotorize
to print the cost. But it always using the legacy cost model to calculate/print the scalar cost.
Do you have better suggestion to test this 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.
You could also check the remark output, assuming there is any? Or of not, check that there is no remark output
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.
Update test, thanks!
6385ea0
to
bb4f8f5
Compare
@@ -0,0 +1,65 @@ | |||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | |||
; RUN: opt < %s -mtriple=riscv64 -mattr=+v -p loop-vectorize -pass-remarks-analysis=loop-vectorize -S | 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.
You could also check the remark output, assuming there is any? Or of not, check that there is no remark output
loop: | ||
%iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ] | ||
%red = phi float [ 0.000000e+00, %entry ], [ %red.next, %loop ] | ||
%red.next = fadd float 0.000000e+00, %red |
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.
this is a no-op reduction, can this also reproduce with a 'real' reductions?
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, update test case to real reduction.
https://godbolt.org/z/dj3hrK8fT
Becaue the original test case will not vectorized anymore. Update the test case the will hit the bug.
bb4f8f5
to
5ad2ad5
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
…rks(). (llvm#117288) We should only query the computeCost() when the VF is vector.
We should only query the computeCost() when the VF is vector.