[llvm] [SLP] Use ConstantInt::getSigned for stride argument to strided load/store intrinsics (PR #175007)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 8 07:51:21 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alex Bradbury (asb)
<details>
<summary>Changes</summary>
strided-stores-vectorized.ll crashes for RV32 without fixing the relevant logic in vectorizeTree, because the argument can't be represented as a 32-bit unsigned value:
```
llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed.
```
It is intended to be signed, so we simply use ConstantInt::getSigned instead. This fixes other stride-related instances in the file as well. I believe I could track down reproducers for the otrer ConstantInt::getSigned changes but as the change is "obvious" I haven't done so far (just let me know if you believe I should in order to land this). For further context, this change is part of unblocking rv32gcv llvm-test-suite in CI, so extenstive ongoing testing will come from that.
---
Full diff: https://github.com/llvm/llvm-project/pull/175007.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+3-3)
- (modified) llvm/test/Transforms/SLPVectorizer/RISCV/strided-stores-vectorized.ll (+26-11)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index cc78d01890662..270635186edfb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7168,7 +7168,7 @@ bool BoUpSLP::analyzeConstantStrideCandidate(
}
Type *StrideTy = DL->getIndexType(Ptr0->getType());
- SPtrInfo.StrideVal = ConstantInt::get(StrideTy, StrideIntVal);
+ SPtrInfo.StrideVal = ConstantInt::getSigned(StrideTy, StrideIntVal);
SPtrInfo.Ty = getWidenedType(NewScalarTy, VecSz);
return true;
}
@@ -20474,7 +20474,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
Value *NewStride =
Builder.CreateIntCast(Stride, StrideTy, /*isSigned=*/true);
StrideVal = Builder.CreateMul(
- NewStride, ConstantInt::get(
+ NewStride, ConstantInt::getSigned(
StrideTy, (IsReverseOrder ? -1 : 1) *
static_cast<int>(
DL->getTypeAllocSize(ScalarTy))));
@@ -20556,7 +20556,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
Intrinsic::experimental_vp_strided_store,
{VecTy, Ptr->getType(), StrideTy},
{VecValue, Ptr,
- ConstantInt::get(
+ ConstantInt::getSigned(
StrideTy, -static_cast<int>(DL->getTypeAllocSize(ScalarTy))),
Builder.getAllOnesMask(VecTy->getElementCount()),
Builder.getInt32(E->Scalars.size())});
diff --git a/llvm/test/Transforms/SLPVectorizer/RISCV/strided-stores-vectorized.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/strided-stores-vectorized.ll
index 7a0ab8002b8c0..ad8eaaabb62ec 100644
--- a/llvm/test/Transforms/SLPVectorizer/RISCV/strided-stores-vectorized.ll
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/strided-stores-vectorized.ll
@@ -1,16 +1,31 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=riscv64-unknown-linux -mattr=+v | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=riscv64-unknown-linux -mattr=+v \
+; RUN: | FileCheck -check-prefix=RV64 %s
+; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=riscv32-unknown-linux -mattr=+v \
+; RUN: | FileCheck -check-prefix=RV32 %s
define void @store_reverse(ptr %p3) {
-; CHECK-LABEL: @store_reverse(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i64, ptr [[P3:%.*]], i64 8
-; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[P3]], i64 7
-; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i64>, ptr [[P3]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i64>, ptr [[ARRAYIDX1]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = shl <4 x i64> [[TMP0]], [[TMP1]]
-; CHECK-NEXT: call void @llvm.experimental.vp.strided.store.v4i64.p0.i64(<4 x i64> [[TMP2]], ptr align 8 [[ARRAYIDX2]], i64 -8, <4 x i1> splat (i1 true), i32 4)
-; CHECK-NEXT: ret void
+; RV64-LABEL: define void @store_reverse(
+; RV64-SAME: ptr [[P3:%.*]]) #[[ATTR0:[0-9]+]] {
+; RV64-NEXT: [[ENTRY:.*:]]
+; RV64-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i64, ptr [[P3]], i64 8
+; RV64-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[P3]], i64 7
+; RV64-NEXT: [[TMP0:%.*]] = load <4 x i64>, ptr [[P3]], align 8
+; RV64-NEXT: [[TMP1:%.*]] = load <4 x i64>, ptr [[ARRAYIDX1]], align 8
+; RV64-NEXT: [[TMP2:%.*]] = shl <4 x i64> [[TMP0]], [[TMP1]]
+; RV64-NEXT: call void @llvm.experimental.vp.strided.store.v4i64.p0.i64(<4 x i64> [[TMP2]], ptr align 8 [[ARRAYIDX2]], i64 -8, <4 x i1> splat (i1 true), i32 4)
+; RV64-NEXT: ret void
+;
+; RV32-LABEL: define void @store_reverse(
+; RV32-SAME: ptr [[P3:%.*]]) #[[ATTR0:[0-9]+]] {
+; RV32-NEXT: [[ENTRY:.*:]]
+; RV32-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i64, ptr [[P3]], i64 8
+; RV32-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[P3]], i64 7
+; RV32-NEXT: [[TMP0:%.*]] = load <4 x i64>, ptr [[P3]], align 8
+; RV32-NEXT: [[TMP1:%.*]] = load <4 x i64>, ptr [[ARRAYIDX1]], align 8
+; RV32-NEXT: [[TMP2:%.*]] = shl <4 x i64> [[TMP0]], [[TMP1]]
+; RV32-NEXT: call void @llvm.experimental.vp.strided.store.v4i64.p0.i32(<4 x i64> [[TMP2]], ptr align 8 [[ARRAYIDX2]], i32 -8, <4 x i1> splat (i1 true), i32 4)
+; RV32-NEXT: ret void
;
entry:
%0 = load i64, ptr %p3, align 8
``````````
</details>
https://github.com/llvm/llvm-project/pull/175007
More information about the llvm-commits
mailing list