[llvm] [SLP] Fix : Do not skip profitable small VFs in Vectorize Stores (PR #177100)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 22:26:00 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Soumik15630m (Soumik15630)
<details>
<summary>Changes</summary>
vectorizeStores() uses RangeSizes to avoid attempting
unprofitable vectorizations. After d74e42a, the profitability
check was applied to small VFs as well, which can cause viable
sub-slices to be skipped when tree sizes differ across lanes.
Restrict the RangeSizes profitability check to VFs larger than
MaxRegVF and add a regression test.
Fix #<!-- -->177068
---
Full diff: https://github.com/llvm/llvm-project/pull/177100.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+23-7)
- (added) llvm/test/Transforms/SLPVectorizer/RISCV/stores-equal-to-maxregvf.ll (+42)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 762b394f8ea8a..0678a78f5d59e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -24024,7 +24024,9 @@ bool SLPVectorizerPass::vectorizeStores(
unsigned FirstUnvecStore =
std::distance(RangeSizes.begin(),
find_if(RangeSizes, std::bind(IsNotVectorized,
- VF >= MaxRegVF, _1)));
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
+ VF > MaxRegVF, _1)));
// Form slices of size VF starting from FirstUnvecStore and try to
// vectorize them.
@@ -24032,12 +24034,16 @@ bool SLPVectorizerPass::vectorizeStores(
unsigned FirstVecStore = std::distance(
RangeSizes.begin(),
find_if(RangeSizes.drop_front(FirstUnvecStore),
- std::bind(IsVectorized, VF >= MaxRegVF, _1)));
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
+ std::bind(IsVectorized, VF > MaxRegVF, _1)));
unsigned MaxSliceEnd = FirstVecStore >= End ? End : FirstVecStore;
for (unsigned SliceStartIdx = FirstUnvecStore;
SliceStartIdx + VF <= MaxSliceEnd;) {
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
if (!checkTreeSizes(RangeSizes.slice(SliceStartIdx, VF),
- VF >= MaxRegVF)) {
+ VF > MaxRegVF)) {
++SliceStartIdx;
continue;
}
@@ -24105,13 +24111,17 @@ bool SLPVectorizerPass::vectorizeStores(
}
if (VF > 2 && Res &&
!all_of(RangeSizes.slice(SliceStartIdx, VF),
- std::bind(VFIsProfitable, VF >= MaxRegVF, TreeSize,
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
+ std::bind(VFIsProfitable, VF > MaxRegVF, TreeSize,
_1))) {
SliceStartIdx += VF;
continue;
}
// Check for the very big VFs that we're not rebuilding same
// trees, just with larger number of elements.
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
if (VF > MaxRegVF && TreeSize > 1 &&
all_of(RangeSizes.slice(SliceStartIdx, VF),
std::bind(FirstSizeSame, TreeSize, _1))) {
@@ -24124,7 +24134,9 @@ bool SLPVectorizerPass::vectorizeStores(
if (TreeSize > 1) {
for (std::pair<unsigned, unsigned> &P :
RangeSizes.slice(SliceStartIdx, VF)) {
- if (VF >= MaxRegVF)
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
+ if (VF > MaxRegVF)
P.second = std::max(P.second, TreeSize);
else
P.first = std::max(P.first, TreeSize);
@@ -24141,9 +24153,13 @@ bool SLPVectorizerPass::vectorizeStores(
FirstUnvecStore = std::distance(
RangeSizes.begin(),
find_if(RangeSizes.drop_front(MaxSliceEnd),
- std::bind(IsNotVectorized, VF >= MaxRegVF, _1)));
+ std::bind(IsNotVectorized, VF > MaxRegVF, _1)));
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
}
- if (!AnyProfitableGraph && VF >= MaxRegVF && has_single_bit(VF))
+ if (!AnyProfitableGraph && VF > MaxRegVF && has_single_bit(VF))
+ // to go with the new definition of Large Vf definition of not counting vf which is equal to
+ // maxregvf as large - changed ">=" to ">"
break;
}
// All values vectorized - exit.
diff --git a/llvm/test/Transforms/SLPVectorizer/RISCV/stores-equal-to-maxregvf.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/stores-equal-to-maxregvf.ll
new file mode 100644
index 0000000000000..aa0f75c9c3eaf
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/stores-equal-to-maxregvf.ll
@@ -0,0 +1,42 @@
+define void @foo(ptr %pl, ptr %ps) {
+ %gep_l0 = getelementptr inbounds i32, ptr %pl, i32 92
+ %gep_l1 = getelementptr inbounds i32, ptr %pl, i32 0
+ %gep_l2 = getelementptr inbounds i32, ptr %pl, i32 2
+ %gep_l3 = getelementptr inbounds i32, ptr %pl, i32 3
+ %gep_l4 = getelementptr inbounds i32, ptr %pl, i32 4
+ %gep_l5 = getelementptr inbounds i32, ptr %pl, i32 5
+ %gep_l6 = getelementptr inbounds i32, ptr %pl, i32 7
+ %gep_l7 = getelementptr inbounds i32, ptr %pl, i32 93
+
+ %load0 = load i32, ptr %gep_l0 , align 1
+ %load1 = load i32, ptr %gep_l1 , align 1
+ %load2 = load i32, ptr %gep_l2 , align 1
+ %load3 = load i32, ptr %gep_l3 , align 1
+ %load4 = load i32, ptr %gep_l4 , align 1
+ %load5 = load i32, ptr %gep_l5 , align 1
+ %load6 = load i32, ptr %gep_l6 , align 1
+ %load7 = load i32, ptr %gep_l7 , align 1
+
+ %add6 = add i32 %load6, 2
+ %add7 = add i32 %load7, 2
+
+ %gep_s0 = getelementptr inbounds i32, ptr %ps, i32 0
+ %gep_s1 = getelementptr inbounds i32, ptr %ps, i32 1
+ %gep_s2 = getelementptr inbounds i32, ptr %ps, i32 2
+ %gep_s3 = getelementptr inbounds i32, ptr %ps, i32 3
+ %gep_s4 = getelementptr inbounds i32, ptr %ps, i32 4
+ %gep_s5 = getelementptr inbounds i32, ptr %ps, i32 5
+ %gep_s6 = getelementptr inbounds i32, ptr %ps, i32 6
+ %gep_s7 = getelementptr inbounds i32, ptr %ps, i32 7
+
+ store i32 %load0, ptr %gep_s0, align 1
+ store i32 %load1, ptr %gep_s1, align 1
+ store i32 %load2, ptr %gep_s2, align 1
+ store i32 %load3, ptr %gep_s3, align 1
+ store i32 %load4, ptr %gep_s4, align 1
+ store i32 %load5, ptr %gep_s5, align 1
+ store i32 %add6, ptr %gep_s6, align 1
+ store i32 %add7, ptr %gep_s7, align 1
+
+ ret void
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/177100
More information about the llvm-commits
mailing list