diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 05a6c5f36d26eb..0bae9ad1844ec4 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7014,27 +7014,32 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) { ElementCount MaxUserVF = UserVF.isScalable() ? MaxFactors.ScalableVF : MaxFactors.FixedVF; - bool UserVFIsLegal = ElementCount::isKnownLE(UserVF, MaxUserVF); - if (!UserVF.isZero() && UserVFIsLegal) { - assert(isPowerOf2_32(UserVF.getKnownMinValue()) && - "VF needs to be a power of two"); - // Collect the instructions (and their associated costs) that will be more - // profitable to scalarize. - CM.collectInLoopReductions(); - if (CM.selectUserVectorizationFactor(UserVF)) { - LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n"); - buildVPlansWithVPRecipes(UserVF, UserVF); - if (!hasPlanWithVF(UserVF)) { - LLVM_DEBUG(dbgs() << "LV: No VPlan could be built for " << UserVF - << ".\n"); - return std::nullopt; - } + if (!UserVF.isZero()) { + if (!ElementCount::isKnownLE(UserVF, MaxUserVF)) { + reportVectorizationInfo( + "UserVF ignored because it may be larger than the maximal safe VF", + "InvalidUserVF", ORE, OrigLoop); + } else { + assert(isPowerOf2_32(UserVF.getKnownMinValue()) && + "VF needs to be a power of two"); + // Collect the instructions (and their associated costs) that will be more + // profitable to scalarize. + CM.collectInLoopReductions(); + if (CM.selectUserVectorizationFactor(UserVF)) { + LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n"); + buildVPlansWithVPRecipes(UserVF, UserVF); + if (!hasPlanWithVF(UserVF)) { + LLVM_DEBUG(dbgs() + << "LV: No VPlan could be built for " << UserVF << ".\n"); + return std::nullopt; + } - LLVM_DEBUG(printPlans(dbgs())); - return {{UserVF, 0, 0}}; - } else - reportVectorizationInfo("UserVF ignored because of invalid costs.", - "InvalidCost", ORE, OrigLoop); + LLVM_DEBUG(printPlans(dbgs())); + return {{UserVF, 0, 0}}; + } else + reportVectorizationInfo("UserVF ignored because of invalid costs.", + "InvalidCost", ORE, OrigLoop); + } } // Collect the Vectorization Factor Candidates. diff --git a/llvm/test/Transforms/LoopVectorize/unsafe-vf-hint-remark.ll b/llvm/test/Transforms/LoopVectorize/unsafe-vf-hint-remark.ll index 0c9fa742765d31..8104441ad19934 100644 --- a/llvm/test/Transforms/LoopVectorize/unsafe-vf-hint-remark.ll +++ b/llvm/test/Transforms/LoopVectorize/unsafe-vf-hint-remark.ll @@ -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 ; CHECK: LV: User VF=4 is unsafe, clamping to max safe VF=2. ; CHECK: remark: :0:0: User-specified vectorization factor 4 is unsafe, clamping to maximum safe vectorization factor 2 +; CHECK: remark: :0:0: UserVF ignored because it may be larger than the maximal safe VF ; CHECK-LABEL: @foo ; CHECK: <2 x i32> define void @foo(ptr %a, ptr %b) {