[llvm] [SLP][Revec] Address issue #203195 (PR #203477)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 01:12:02 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
Author: Sushant Gokhale (sushgokh)
<details>
<summary>Changes</summary>
Cost modelling change introduced by commit SHA f15666d is enabling revec of test shown in the above issue. This is introducing a crash as the reduced value(a scalar) is being added to a vector tail value.
Patch tries to address this.
---
Full diff: https://github.com/llvm/llvm-project/pull/203477.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+17-2)
- (added) llvm/test/Transforms/SLPVectorizer/X86/revec-ordered-reductions.ll (+29)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 46a4385002c21..ede8b5478d58c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -30275,11 +30275,26 @@ class HorizontalReduction {
// Emit ordered reduction for the vectorized window.
Builder.SetCurrentDebugLocation(
cast<Instruction>(ReductionRoot)->getDebugLoc());
- if (VectorizedTree)
+ if (auto *VecTy = dyn_cast<FixedVectorType>(DestTy);
+ SLPReVec && VecTy && SuccessRoot) {
+ unsigned DestTyNumElements = getNumElements(VecTy);
+ unsigned VF = getNumElements(SuccessRoot->getType()) / DestTyNumElements;
+ for (auto I : seq<unsigned>(VF)) {
+ auto Position = I * DestTyNumElements;
+ Value *SubVec = createExtractVector(Builder, SuccessRoot,
+ DestTyNumElements, Position);
+ if (!VectorizedTree)
+ VectorizedTree = SubVec;
+ else
+ VectorizedTree = createOp(Builder, RdxKind, VectorizedTree, SubVec,
+ "op.rdx", ReductionOps);
+ }
+ } else if (VectorizedTree) {
VectorizedTree =
emitReduction(SuccessRoot, Builder, TTI, DestTy, VectorizedTree);
- else
+ } else {
VectorizedTree = emitReduction(SuccessRoot, Builder, TTI, DestTy);
+ }
// Fold trailing scalars [SuccessStart+SuccessWidth, N).
for (Value *RdxVal :
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-ordered-reductions.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-ordered-reductions.ll
new file mode 100644
index 0000000000000..5beb6275e7ec6
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-ordered-reductions.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -mtriple=x86_64-unknown-linux-gnu -p slp-vectorizer -slp-revec -S < %s | FileCheck %s
+
+define <16 x float> @ordered_fadd_chain(ptr %p0, ptr %p1) {
+; CHECK-LABEL: define <16 x float> @ordered_fadd_chain(
+; CHECK-SAME: ptr [[P0:%.*]], ptr [[P1:%.*]]) {
+; CHECK-NEXT: [[V0:%.*]] = load <16 x float>, ptr [[P0]], align 64
+; CHECK-NEXT: [[V1:%.*]] = load <16 x float>, ptr [[P1]], align 64
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x float> [[V0]], <16 x float> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <64 x float> <float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float undef, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <64 x float> [[TMP1]], <64 x i32> <i32 64, i32 65, i32 66, i32 67, i32 68, i32 69, i32 70, i32 71, i32 72, i32 73, i32 74, i32 75, i32 76, i32 77, i32 78, i32 79, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>
+; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <16 x float> [[V1]], <16 x float> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <64 x float> [[TMP2]], <64 x float> [[TMP3]], <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 64, i32 65, i32 66, i32 67, i32 68, i32 69, i32 70, i32 71, i32 72, i32 73, i32 74, i32 75, i32 76, i32 77, i32 78, i32 79, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>
+; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <64 x float> [[TMP4]], <64 x float> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>
+; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <64 x float> [[TMP5]], <64 x float> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
+; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <64 x float> [[TMP5]], <64 x float> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; CHECK-NEXT: [[OP_RDX:%.*]] = fadd <16 x float> [[TMP6]], [[TMP7]]
+; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <64 x float> [[TMP5]], <64 x float> poison, <16 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47>
+; CHECK-NEXT: [[OP_RDX1:%.*]] = fadd <16 x float> [[OP_RDX]], [[TMP8]]
+; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <64 x float> [[TMP5]], <64 x float> poison, <16 x i32> <i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>
+; CHECK-NEXT: [[OP_RDX2:%.*]] = fadd <16 x float> [[OP_RDX1]], [[TMP9]]
+; CHECK-NEXT: ret <16 x float> [[OP_RDX2]]
+;
+ %v0 = load <16 x float>, ptr %p0
+ %v1 = load <16 x float>, ptr %p1
+ %add0 = fadd <16 x float> %v0, %v0
+ %add1 = fadd <16 x float> %add0, %v1
+ %add2 = fadd <16 x float> %add1, splat (float 1.000000e+00)
+ ret <16 x float> %add2
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/203477
More information about the llvm-commits
mailing list