Skip to content

Commit d4773c6

Browse files
committed
[RISCV] Fix a crash in RISCVGatherScatterLowering
We were assuming that the constant must always be fixed length when this is not required. Such code is unlikely after optimization, which is why we didn't see this previously.
1 parent 8308e81 commit d4773c6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ bool RISCVGatherScatterLowering::isLegalTypeAndAlignment(Type *DataType,
107107

108108
// TODO: Should we consider the mask when looking for a stride?
109109
static std::pair<Value *, Value *> matchStridedConstant(Constant *StartC) {
110+
if (!isa<FixedVectorType>(StartC->getType()))
111+
return std::make_pair(nullptr, nullptr);
112+
110113
unsigned NumElts = cast<FixedVectorType>(StartC->getType())->getNumElements();
111114

112115
// Check that the start value is a strided constant.

llvm/test/CodeGen/RISCV/rvv/strided-load-store.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ define void @scatter_loopless(<vscale x 1 x i64> %x, ptr %p, i64 %stride) {
135135
ret void
136136
}
137137

138+
; We previously crashed expecting a constant to be fixed length.
139+
define void @constant_stride(<vscale x 1 x i64> %x, ptr %p, i64 %stride) {
140+
; CHECK-LABEL: @constant_stride(
141+
; CHECK-NEXT: [[PTRS:%.*]] = getelementptr i32, ptr [[P:%.*]], <vscale x 1 x i64> zeroinitializer
142+
; CHECK-NEXT: call void @llvm.masked.scatter.nxv1i64.nxv1p0(<vscale x 1 x i64> [[X:%.*]], <vscale x 1 x ptr> [[PTRS]], i32 8, <vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i1 true, i64 0), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer))
143+
; CHECK-NEXT: ret void
144+
;
145+
%ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> zeroinitializer
146+
call void @llvm.masked.scatter.nxv1i64.nxv1p0(
147+
<vscale x 1 x i64> %x,
148+
<vscale x 1 x ptr> %ptrs,
149+
i32 8,
150+
<vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i1 1, i64 0), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer)
151+
)
152+
ret void
153+
}
154+
138155
declare i64 @llvm.vscale.i64()
139156
declare void @llvm.masked.scatter.nxv1i64.nxv1p0(<vscale x 1 x i64>, <vscale x 1 x ptr>, i32, <vscale x 1 x i1>)
140157
declare <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<vscale x 1 x ptr>, i32, <vscale x 1 x i1>, <vscale x 1 x i64>)

0 commit comments

Comments
 (0)