diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5591,13 +5591,8 @@ ElementCount LoopVectorizationCostModel::getMaxLegalScalableVF(unsigned MaxSafeElements) { - if (!TTI.supportsScalableVectors() && !ForceTargetSupportsScalableVectors) { - reportVectorizationInfo( - "Disabling scalable vectorization, because target does not " - "support scalable vectors.", - "ScalableVectorsUnsupported", ORE, TheLoop); + if (!TTI.supportsScalableVectors() && !ForceTargetSupportsScalableVectors) return ElementCount::getScalable(0); - } if (Hints->isScalableVectorizationDisabled()) { reportVectorizationInfo("Scalable vectorization is explicitly disabled", @@ -5605,6 +5600,8 @@ return ElementCount::getScalable(0); } + LLVM_DEBUG(dbgs() << "LV: Scalable vectorization is available\n"); + auto MaxScalableVF = ElementCount::getScalable( std::numeric_limits::max()); @@ -5707,17 +5704,32 @@ return MaxSafeFixedVF; } - LLVM_DEBUG(dbgs() << "LV: User VF=" << UserVF - << " is unsafe. Ignoring scalable UserVF.\n"); - ORE->emit([&]() { - return OptimizationRemarkAnalysis(DEBUG_TYPE, "VectorizationFactor", - TheLoop->getStartLoc(), - TheLoop->getHeader()) - << "User-specified vectorization factor " - << ore::NV("UserVectorizationFactor", UserVF) - << " is unsafe. Ignoring the hint to let the compiler pick a " - "suitable VF."; - }); + if (!TTI.supportsScalableVectors() && !ForceTargetSupportsScalableVectors) { + LLVM_DEBUG(dbgs() << "LV: User VF=" << UserVF + << " is ignored because scalable vectors are not " + "available.\n"); + ORE->emit([&]() { + return OptimizationRemarkAnalysis(DEBUG_TYPE, "VectorizationFactor", + TheLoop->getStartLoc(), + TheLoop->getHeader()) + << "User-specified vectorization factor " + << ore::NV("UserVectorizationFactor", UserVF) + << " is ignored because the target does not support scalable " + "vectors. The compiler will pick a more suitable value."; + }); + } else { + LLVM_DEBUG(dbgs() << "LV: User VF=" << UserVF + << " is unsafe. Ignoring scalable UserVF.\n"); + ORE->emit([&]() { + return OptimizationRemarkAnalysis(DEBUG_TYPE, "VectorizationFactor", + TheLoop->getStartLoc(), + TheLoop->getHeader()) + << "User-specified vectorization factor " + << ore::NV("UserVectorizationFactor", UserVF) + << " is unsafe. Ignoring the hint to let the compiler pick a " + "more suitable value."; + }); + } } LLVM_DEBUG(dbgs() << "LV: The Smallest and Widest types: " << SmallestType diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll --- a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll @@ -38,6 +38,7 @@ ; fixed-width vectorization is used instead. ; CHECK-DBG: LV: Checking a loop in "test1" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: Max legal vector width too small, scalable vectorization unfeasible. ; CHECK-DBG: remark: :0:0: Max legal vector width too small, scalable vectorization unfeasible. ; CHECK-DBG: LV: The max safe fixed VF is: 8. @@ -82,6 +83,7 @@ ; } ; CHECK-DBG: LV: Checking a loop in "test2" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: Max legal vector width too small, scalable vectorization unfeasible. ; CHECK-DBG: LV: The max safe fixed VF is: 4. ; CHECK-DBG: LV: User VF=vscale x 8 is unsafe. Ignoring scalable UserVF. @@ -131,6 +133,7 @@ ; Max fixed VF=32, Max scalable VF=2, safe to vectorize. ; CHECK-DBG-LABEL: LV: Checking a loop in "test3" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: The max safe scalable VF is: vscale x 2. ; CHECK-DBG: LV: Using user VF vscale x 2. ; CHECK-LABEL: @test3 @@ -179,9 +182,10 @@ ; Max fixed VF=32, Max scalable VF=2, unsafe to vectorize. ; CHECK-DBG-LABEL: LV: Checking a loop in "test4" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: The max safe scalable VF is: vscale x 2. ; CHECK-DBG: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. -; CHECK-DBG: remark: :0:0: User-specified vectorization factor vscale x 4 is unsafe. Ignoring the hint to let the compiler pick a suitable VF. +; CHECK-DBG: remark: :0:0: User-specified vectorization factor vscale x 4 is unsafe. Ignoring the hint to let the compiler pick a more suitable value. ; CHECK-DBG: Found feasible scalable VF = vscale x 2 ; CHECK-DBG: LV: Selecting VF: 4. ; CHECK-LABEL: @test4 @@ -229,6 +233,7 @@ ; Max fixed VF=128, Max scalable VF=8, safe to vectorize. ; CHECK-DBG-LABEL: LV: Checking a loop in "test5" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: The max safe scalable VF is: vscale x 8. ; CHECK-DBG: LV: Using user VF vscale x 4 ; CHECK-LABEL: @test5 @@ -276,13 +281,14 @@ ; Max fixed VF=128, Max scalable VF=8, unsafe to vectorize. ; CHECK-DBG-LABEL: LV: Checking a loop in "test6" +; CHECK-DBG: LV: Scalable vectorization is available ; CHECK-DBG: LV: The max safe scalable VF is: vscale x 8. ; CHECK-DBG: LV: User VF=vscale x 16 is unsafe. Ignoring scalable UserVF. -; CHECK-DBG: remark: :0:0: User-specified vectorization factor vscale x 16 is unsafe. Ignoring the hint to let the compiler pick a suitable VF. +; CHECK-DBG: remark: :0:0: User-specified vectorization factor vscale x 16 is unsafe. Ignoring the hint to let the compiler pick a more suitable value. ; CHECK-DBG: LV: Found feasible scalable VF = vscale x 4 -; CHECK-DBG: Selecting VF: 4. +; CHECK-DBG: Selecting VF: vscale x 4. ; CHECK-LABEL: @test6 -; CHECK: <4 x i32> +; CHECK: define void @test6(i32* %a, i32* %b) { entry: br label %loop @@ -310,9 +316,8 @@ !17 = !{!"llvm.loop.vectorize.scalable.enable", i1 true} ; CHECK-NO-SVE-REMARKS-LABEL: LV: Checking a loop in "test_no_sve" -; CHECK-NO-SVE-REMARKS: LV: Disabling scalable vectorization, because target does not support scalable vectors. -; CHECK-NO-SVE-REMARKS: remark: :0:0: Disabling scalable vectorization, because target does not support scalable vectors. -; CHECK-NO-SVE-REMARKS: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. +; CHECK-NO-SVE-REMARKS: LV: User VF=vscale x 4 is ignored because scalable vectors are not available. +; CHECK-NO-SVE-REMARKS: remark: :0:0: User-specified vectorization factor vscale x 4 is ignored because the target does not support scalable vectors. The compiler will pick a more suitable value. ; CHECK-NO-SVE-REMARKS: LV: Selecting VF: 4. ; CHECK-NO-SVE-LABEL: @test_no_sve ; CHECK-NO-SVE: <4 x i32> @@ -344,12 +349,13 @@ ; Test the LV falls back to fixed-width vectorization if scalable vectors are ; supported but max vscale is undefined. ; -; CHECK-NO-SVE-REMARKS-LABEL: LV: Checking a loop in "test_no_max_vscale" -; CHECK-NO-SVE-REMARKS: The max safe fixed VF is: 4. -; CHECK-NO-SVE-REMARKS: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. -; CHECK-NO-SVE-REMARKS: LV: Selecting VF: 4. -; CHECK-NO-SVE-LABEL: @test_no_max_vscale -; CHECK-NO-SVE: <4 x i32> +; CHECK-DBG-LABEL: LV: Checking a loop in "test_no_max_vscale" +; CHECK-DBG: LV: Scalable vectorization is available +; CHECK-DBG: The max safe fixed VF is: 4. +; CHECK-DBG: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. +; CHECK-DBG: LV: Selecting VF: 4. +; CHECK-LABEL: @test_no_max_vscale +; CHECK: <4 x i32> define void @test_no_max_vscale(i32* %a, i32* %b) { entry: br label %loop diff --git a/llvm/test/Transforms/LoopVectorize/scalable-vf-hint.ll b/llvm/test/Transforms/LoopVectorize/scalable-vf-hint.ll --- a/llvm/test/Transforms/LoopVectorize/scalable-vf-hint.ll +++ b/llvm/test/Transforms/LoopVectorize/scalable-vf-hint.ll @@ -3,8 +3,8 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" -; CHECK: LV: Disabling scalable vectorization, because target does not support scalable vectors. -; CHECK: remark: :0:0: Disabling scalable vectorization, because target does not support scalable vectors. +; CHECK: LV: User VF=vscale x 4 is ignored because scalable vectors are not available. +; CHECK: remark: :0:0: User-specified vectorization factor vscale x 4 is ignored because the target does not support scalable vectors. The compiler will pick a more suitable value. ; CHECK: LV: The Widest register safe to use is: 32 bits. define void @test1(i32* %a, i32* %b) { entry: