Skip to content

Commit b8dccb7

Browse files
committed
[VPlan] Emit note when UserVF > MaxUserVF (NFCI).
As suggested in #103033, add a remark when the UserVF is ignored due to it being larger than MaxUserVF. Only changes behavior of diagnostic/debug output.
1 parent 00def06 commit b8dccb7

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -7014,27 +7014,32 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
70147014

70157015
ElementCount MaxUserVF =
70167016
UserVF.isScalable() ? MaxFactors.ScalableVF : MaxFactors.FixedVF;
7017-
bool UserVFIsLegal = ElementCount::isKnownLE(UserVF, MaxUserVF);
7018-
if (!UserVF.isZero() && UserVFIsLegal) {
7019-
assert(isPowerOf2_32(UserVF.getKnownMinValue()) &&
7020-
"VF needs to be a power of two");
7021-
// Collect the instructions (and their associated costs) that will be more
7022-
// profitable to scalarize.
7023-
CM.collectInLoopReductions();
7024-
if (CM.selectUserVectorizationFactor(UserVF)) {
7025-
LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n");
7026-
buildVPlansWithVPRecipes(UserVF, UserVF);
7027-
if (!hasPlanWithVF(UserVF)) {
7028-
LLVM_DEBUG(dbgs() << "LV: No VPlan could be built for " << UserVF
7029-
<< ".\n");
7030-
return std::nullopt;
7031-
}
7017+
if (!UserVF.isZero()) {
7018+
if (!ElementCount::isKnownLE(UserVF, MaxUserVF)) {
7019+
reportVectorizationInfo(
7020+
"UserVF ignored because it may be larger than the maximal safe VF",
7021+
"InvalidUserVF", ORE, OrigLoop);
7022+
} else {
7023+
assert(isPowerOf2_32(UserVF.getKnownMinValue()) &&
7024+
"VF needs to be a power of two");
7025+
// Collect the instructions (and their associated costs) that will be more
7026+
// profitable to scalarize.
7027+
CM.collectInLoopReductions();
7028+
if (CM.selectUserVectorizationFactor(UserVF)) {
7029+
LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n");
7030+
buildVPlansWithVPRecipes(UserVF, UserVF);
7031+
if (!hasPlanWithVF(UserVF)) {
7032+
LLVM_DEBUG(dbgs()
7033+
<< "LV: No VPlan could be built for " << UserVF << ".\n");
7034+
return std::nullopt;
7035+
}
70327036

7033-
LLVM_DEBUG(printPlans(dbgs()));
7034-
return {{UserVF, 0, 0}};
7035-
} else
7036-
reportVectorizationInfo("UserVF ignored because of invalid costs.",
7037-
"InvalidCost", ORE, OrigLoop);
7037+
LLVM_DEBUG(printPlans(dbgs()));
7038+
return {{UserVF, 0, 0}};
7039+
} else
7040+
reportVectorizationInfo("UserVF ignored because of invalid costs.",
7041+
"InvalidCost", ORE, OrigLoop);
7042+
}
70387043
}
70397044

70407045
// Collect the Vectorization Factor Candidates.

llvm/test/Transforms/LoopVectorize/unsafe-vf-hint-remark.ll

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
1414

1515
; CHECK: LV: User VF=4 is unsafe, clamping to max safe VF=2.
1616
; CHECK: remark: <unknown>:0:0: User-specified vectorization factor 4 is unsafe, clamping to maximum safe vectorization factor 2
17+
; CHECK: remark: <unknown>:0:0: UserVF ignored because it may be larger than the maximal safe VF
1718
; CHECK-LABEL: @foo
1819
; CHECK: <2 x i32>
1920
define void @foo(ptr %a, ptr %b) {

0 commit comments

Comments
 (0)