1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -S -riscv-gather-scatter-lowering -mtriple=riscv64 -mattr=+m,+v | FileCheck %s --check-prefixes=CHECK
4 %struct.foo = type { i32, i32, i32, i32 }
6 declare <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
8 define <vscale x 1 x i64> @gather(ptr %a, i32 %len) {
9 ; CHECK-LABEL: @gather(
10 ; CHECK-NEXT: vector.ph:
11 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[LEN:%.*]] to i64
12 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.vscale.i64()
13 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
15 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
16 ; CHECK-NEXT: [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
17 ; CHECK-NEXT: [[ACCUM:%.*]] = phi <vscale x 1 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[ACCUM_NEXT:%.*]], [[VECTOR_BODY]] ]
18 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [[STRUCT_FOO:%.*]], ptr [[A:%.*]], i64 [[VEC_IND_SCALAR]], i32 3
19 ; CHECK-NEXT: [[GATHER:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> undef, ptr [[TMP1]], i64 16, <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))
20 ; CHECK-NEXT: [[ACCUM_NEXT]] = add <vscale x 1 x i64> [[ACCUM]], [[GATHER]]
21 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP0]]
22 ; CHECK-NEXT: [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], [[TMP0]]
23 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i64 [[INDEX_NEXT]], [[WIDE_TRIP_COUNT]]
24 ; CHECK-NEXT: br i1 [[TMP2]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
25 ; CHECK: for.cond.cleanup:
26 ; CHECK-NEXT: ret <vscale x 1 x i64> [[ACCUM_NEXT]]
29 %wide.trip.count = zext i32 %len to i64
30 %0 = tail call i64 @llvm.vscale.i64()
31 %1 = tail call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
32 %.splatinsert = insertelement <vscale x 1 x i64> poison, i64 %0, i64 0
33 %.splat = shufflevector <vscale x 1 x i64> %.splatinsert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
36 vector.body: ; preds = %vector.body, %vector.ph
37 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
38 %vec.ind = phi <vscale x 1 x i64> [ %1, %vector.ph ], [ %vec.ind.next, %vector.body ]
39 %accum = phi <vscale x 1 x i64> [ zeroinitializer, %vector.ph ], [ %accum.next, %vector.body ]
40 %2 = getelementptr inbounds %struct.foo, ptr %a, <vscale x 1 x i64> %vec.ind, i32 3
41 %gather = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<vscale x 1 x ptr> %2, i32 8, <vscale x 1 x i1> splat (i1 true), <vscale x 1 x i64> undef)
42 %accum.next = add <vscale x 1 x i64> %accum, %gather
43 %index.next = add nuw i64 %index, %0
44 %vec.ind.next = add <vscale x 1 x i64> %vec.ind, %.splat
45 %3 = icmp ne i64 %index.next, %wide.trip.count
46 br i1 %3, label %for.cond.cleanup, label %vector.body
48 for.cond.cleanup: ; preds = %vector.body
49 ret <vscale x 1 x i64> %accum.next
52 define <vscale x 1 x i64> @gather_disjoint_or(ptr %a, i64 %len) {
53 ; CHECK-LABEL: @gather_disjoint_or(
54 ; CHECK-NEXT: vector.ph:
55 ; CHECK-NEXT: [[VSCALE:%.*]] = call i64 @llvm.vscale.i64()
56 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
58 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
59 ; CHECK-NEXT: [[VEC_IND_SCALAR:%.*]] = phi i64 [ 1, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
60 ; CHECK-NEXT: [[ACCUM:%.*]] = phi <vscale x 1 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[ACCUM_NEXT:%.*]], [[VECTOR_BODY]] ]
61 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[VEC_IND_SCALAR]]
62 ; CHECK-NEXT: [[GATHER:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP0]], i64 16, <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))
63 ; CHECK-NEXT: [[ACCUM_NEXT]] = add <vscale x 1 x i64> [[ACCUM]], [[GATHER]]
64 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[VSCALE]]
65 ; CHECK-NEXT: [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 2
66 ; CHECK-NEXT: [[EXIT:%.*]] = icmp ne i64 [[INDEX_NEXT]], [[LEN:%.*]]
67 ; CHECK-NEXT: br i1 [[EXIT]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
68 ; CHECK: for.cond.cleanup:
69 ; CHECK-NEXT: ret <vscale x 1 x i64> [[ACCUM_NEXT]]
72 %vscale = call i64 @llvm.vscale.i64()
73 %step = tail call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
74 %step.mul2 = shl <vscale x 1 x i64> %step, splat (i64 1)
77 vector.body: ; preds = %vector.body, %vector.ph
78 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
79 %vec.ind = phi <vscale x 1 x i64> [ %step.mul2, %vector.ph ], [ %vec.ind.next, %vector.body ]
81 %accum = phi <vscale x 1 x i64> [ zeroinitializer, %vector.ph ], [ %accum.next, %vector.body ]
83 %vec.ind.or = or disjoint <vscale x 1 x i64> %vec.ind, splat (i64 1)
85 %gep = getelementptr i64, ptr %a, <vscale x 1 x i64> %vec.ind.or
86 %gather = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
87 <vscale x 1 x ptr> %gep,
89 <vscale x 1 x i1> splat (i1 true),
90 <vscale x 1 x i64> poison
93 %accum.next = add <vscale x 1 x i64> %accum, %gather
94 %index.next = add nuw i64 %index, %vscale
95 %vec.ind.next = add <vscale x 1 x i64> %vec.ind, splat (i64 2)
97 %exit = icmp ne i64 %index.next, %len
98 br i1 %exit, label %for.cond.cleanup, label %vector.body
100 for.cond.cleanup: ; preds = %vector.body
101 ret <vscale x 1 x i64> %accum.next
104 define void @scatter(ptr %a, i32 %len) {
105 ; CHECK-LABEL: @scatter(
106 ; CHECK-NEXT: vector.ph:
107 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[LEN:%.*]] to i64
108 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.vscale.i64()
109 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
110 ; CHECK: vector.body:
111 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
112 ; CHECK-NEXT: [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
113 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [[STRUCT_FOO:%.*]], ptr [[A:%.*]], i64 [[VEC_IND_SCALAR]], i32 3
114 ; CHECK-NEXT: call void @llvm.riscv.masked.strided.store.nxv1i64.p0.i64(<vscale x 1 x i64> zeroinitializer, ptr [[TMP1]], i64 16, <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))
115 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP0]]
116 ; CHECK-NEXT: [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], [[TMP0]]
117 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i64 [[INDEX_NEXT]], [[WIDE_TRIP_COUNT]]
118 ; CHECK-NEXT: br i1 [[TMP2]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
119 ; CHECK: for.cond.cleanup:
120 ; CHECK-NEXT: ret void
123 %wide.trip.count = zext i32 %len to i64
124 %0 = tail call i64 @llvm.vscale.i64()
125 %1 = tail call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
126 %.splatinsert = insertelement <vscale x 1 x i64> poison, i64 %0, i64 0
127 %.splat = shufflevector <vscale x 1 x i64> %.splatinsert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
128 br label %vector.body
130 vector.body: ; preds = %vector.body, %vector.ph
131 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
132 %vec.ind = phi <vscale x 1 x i64> [ %1, %vector.ph ], [ %vec.ind.next, %vector.body ]
133 %2 = getelementptr inbounds %struct.foo, ptr %a, <vscale x 1 x i64> %vec.ind, i32 3
134 tail call void @llvm.masked.scatter.nxv1i64.nxv1p0(<vscale x 1 x i64> zeroinitializer, <vscale x 1 x ptr> %2, i32 8, <vscale x 1 x i1> splat (i1 true))
135 %index.next = add nuw i64 %index, %0
136 %vec.ind.next = add <vscale x 1 x i64> %vec.ind, %.splat
137 %3 = icmp ne i64 %index.next, %wide.trip.count
138 br i1 %3, label %for.cond.cleanup, label %vector.body
140 for.cond.cleanup: ; preds = %vector.body
144 define <vscale x 1 x i64> @gather_loopless(ptr %p, i64 %stride) {
145 ; CHECK-LABEL: @gather_loopless(
146 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[STRIDE:%.*]], 4
147 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[P:%.*]], i64 [[TMP1]], <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))
148 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
150 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
151 %splat.insert = insertelement <vscale x 1 x i64> poison, i64 %stride, i64 0
152 %splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
153 %offsets = mul <vscale x 1 x i64> %step, %splat
154 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offsets
155 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
156 <vscale x 1 x ptr> %ptrs,
158 <vscale x 1 x i1> splat (i1 1),
159 <vscale x 1 x i64> poison
161 ret <vscale x 1 x i64> %x
164 define <vscale x 1 x i64> @straightline_offset_add(ptr %p, i64 %offset) {
165 ; CHECK-LABEL: @straightline_offset_add(
166 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 [[OFFSET:%.*]]
167 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP1]], i64 4, <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))
168 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
170 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
171 %splat.insert = insertelement <vscale x 1 x i64> poison, i64 %offset, i64 0
172 %splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
173 %offsetv = add <vscale x 1 x i64> %step, %splat
174 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offsetv
175 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
176 <vscale x 1 x ptr> %ptrs,
178 <vscale x 1 x i1> splat (i1 1),
179 <vscale x 1 x i64> poison
181 ret <vscale x 1 x i64> %x
184 define <vscale x 1 x i64> @straightline_offset_disjoint_or(ptr %p, i64 %offset) {
185 ; CHECK-LABEL: @straightline_offset_disjoint_or(
186 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 1
187 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP1]], i64 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))
188 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
190 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
191 %step.shl = shl <vscale x 1 x i64> %step, splat (i64 1)
192 %offsetv = or disjoint <vscale x 1 x i64> %step.shl, splat (i64 1)
193 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offsetv
194 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
195 <vscale x 1 x ptr> %ptrs,
197 <vscale x 1 x i1> splat (i1 true),
198 <vscale x 1 x i64> poison
200 ret <vscale x 1 x i64> %x
203 define <vscale x 1 x i64> @straightline_offset_shl(ptr %p) {
204 ; CHECK-LABEL: @straightline_offset_shl(
205 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[P:%.*]], i64 32, <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))
206 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
208 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
209 %offset = shl <vscale x 1 x i64> %step, splat (i64 3)
210 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offset
211 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
212 <vscale x 1 x ptr> %ptrs,
214 <vscale x 1 x i1> splat (i1 1),
215 <vscale x 1 x i64> poison
217 ret <vscale x 1 x i64> %x
220 define <vscale x 1 x i64> @neg_shl_is_not_commutative(ptr %p) {
221 ; CHECK-LABEL: @neg_shl_is_not_commutative(
222 ; CHECK-NEXT: [[STEP:%.*]] = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
223 ; CHECK-NEXT: [[SPLAT_INSERT:%.*]] = insertelement <vscale x 1 x i64> poison, i64 3, i64 0
224 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 1 x i64> [[SPLAT_INSERT]], <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
225 ; CHECK-NEXT: [[OFFSET:%.*]] = shl <vscale x 1 x i64> [[SPLAT]], [[STEP]]
226 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr i32, ptr [[P:%.*]], <vscale x 1 x i64> [[OFFSET]]
227 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<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), <vscale x 1 x i64> poison)
228 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
230 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
231 %splat.insert = insertelement <vscale x 1 x i64> poison, i64 3, i64 0
232 %splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
233 %offset = shl <vscale x 1 x i64> %splat, %step
234 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offset
235 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
236 <vscale x 1 x ptr> %ptrs,
238 <vscale x 1 x i1> splat (i1 1),
239 <vscale x 1 x i64> poison
241 ret <vscale x 1 x i64> %x
244 define <vscale x 1 x i64> @straightline_offset_shl_nonc(ptr %p, i64 %shift) {
245 ; CHECK-LABEL: @straightline_offset_shl_nonc(
246 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 1, [[SHIFT:%.*]]
247 ; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 4
248 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[P:%.*]], i64 [[TMP2]], <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))
249 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
251 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
252 %splat.insert = insertelement <vscale x 1 x i64> poison, i64 %shift, i64 0
253 %splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
254 %offset = shl <vscale x 1 x i64> %step, %splat
255 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offset
256 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
257 <vscale x 1 x ptr> %ptrs,
259 <vscale x 1 x i1> splat (i1 1),
260 <vscale x 1 x i64> poison
262 ret <vscale x 1 x i64> %x
265 define void @scatter_loopless(<vscale x 1 x i64> %x, ptr %p, i64 %stride) {
266 ; CHECK-LABEL: @scatter_loopless(
267 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[STRIDE:%.*]], 4
268 ; CHECK-NEXT: call void @llvm.riscv.masked.strided.store.nxv1i64.p0.i64(<vscale x 1 x i64> [[X:%.*]], ptr [[P:%.*]], i64 [[TMP1]], <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))
269 ; CHECK-NEXT: ret void
271 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
272 %splat.insert = insertelement <vscale x 1 x i64> poison, i64 %stride, i64 0
273 %splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
274 %offsets = mul <vscale x 1 x i64> %step, %splat
275 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> %offsets
276 call void @llvm.masked.scatter.nxv1i64.nxv1p0(
277 <vscale x 1 x i64> %x,
278 <vscale x 1 x ptr> %ptrs,
280 <vscale x 1 x i1> splat (i1 1)
285 ; We previously crashed expecting a constant to be fixed length.
286 define void @constant_stride(<vscale x 1 x i64> %x, ptr %p, i64 %stride) {
287 ; CHECK-LABEL: @constant_stride(
288 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr i32, ptr [[P:%.*]], <vscale x 1 x i64> zeroinitializer
289 ; 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))
290 ; CHECK-NEXT: ret void
292 %ptrs = getelementptr i32, ptr %p, <vscale x 1 x i64> zeroinitializer
293 call void @llvm.masked.scatter.nxv1i64.nxv1p0(
294 <vscale x 1 x i64> %x,
295 <vscale x 1 x ptr> %ptrs,
297 <vscale x 1 x i1> splat (i1 1)
302 define <vscale x 1 x i64> @vector_base_scalar_offset(ptr %p, i64 %offset) {
303 ; CHECK-LABEL: @vector_base_scalar_offset(
304 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i64, ptr [[P:%.*]], i64 [[OFFSET:%.*]]
305 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP1]], i64 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))
306 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
308 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
309 %ptrs1 = getelementptr i64, ptr %p, <vscale x 1 x i64> %step
310 %ptrs2 = getelementptr i64, <vscale x 1 x ptr> %ptrs1, i64 %offset
311 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
312 <vscale x 1 x ptr> %ptrs2,
314 <vscale x 1 x i1> splat (i1 1),
315 <vscale x 1 x i64> poison
317 ret <vscale x 1 x i64> %x
320 define <vscale x 1 x i64> @splat_base_scalar_offset(ptr %p, i64 %offset) {
321 ; CHECK-LABEL: @splat_base_scalar_offset(
322 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i64, ptr [[P:%.*]], i64 [[OFFSET:%.*]]
323 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP1]], i64 0, <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))
324 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
326 %head = insertelement <vscale x 1 x ptr> poison, ptr %p, i32 0
327 %splat = shufflevector <vscale x 1 x ptr> %head, <vscale x 1 x ptr> poison, <vscale x 1 x i32> zeroinitializer
328 %ptrs = getelementptr i64, <vscale x 1 x ptr> %splat, i64 %offset
329 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
330 <vscale x 1 x ptr> %ptrs,
332 <vscale x 1 x i1> splat (i1 1),
333 <vscale x 1 x i64> poison
335 ret <vscale x 1 x i64> %x
338 ; We shouldn't be able to determine a stride here.
339 define <vscale x 1 x i64> @nonstrided_base_scalar_offset(ptr %p, <vscale x 1 x i64> %v, i64 %offset) {
340 ; CHECK-LABEL: @nonstrided_base_scalar_offset(
341 ; CHECK-NEXT: [[PTRS1:%.*]] = getelementptr i64, ptr [[P:%.*]], <vscale x 1 x i64> [[V:%.*]]
342 ; CHECK-NEXT: [[PTRS2:%.*]] = getelementptr i64, <vscale x 1 x ptr> [[PTRS1]], i64 [[OFFSET:%.*]]
343 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<vscale x 1 x ptr> [[PTRS2]], 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), <vscale x 1 x i64> poison)
344 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
346 %ptrs1 = getelementptr i64, ptr %p, <vscale x 1 x i64> %v
347 %ptrs2 = getelementptr i64, <vscale x 1 x ptr> %ptrs1, i64 %offset
348 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
349 <vscale x 1 x ptr> %ptrs2,
351 <vscale x 1 x i1> splat (i1 1),
352 <vscale x 1 x i64> poison
354 ret <vscale x 1 x i64> %x
357 ; We shouldn't be able to determine a scalar base here.
358 define <vscale x 1 x i64> @vector_base_vector_offset(ptr %p, <vscale x 1 x i64> %offset) {
359 ; CHECK-LABEL: @vector_base_vector_offset(
360 ; CHECK-NEXT: [[STEP:%.*]] = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
361 ; CHECK-NEXT: [[PTRS1:%.*]] = getelementptr i64, ptr [[P:%.*]], <vscale x 1 x i64> [[STEP]]
362 ; CHECK-NEXT: [[PTRS2:%.*]] = getelementptr i64, <vscale x 1 x ptr> [[PTRS1]], <vscale x 1 x i64> [[OFFSET:%.*]]
363 ; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<vscale x 1 x ptr> [[PTRS2]], 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), <vscale x 1 x i64> poison)
364 ; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
366 %step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
367 %ptrs1 = getelementptr i64, ptr %p, <vscale x 1 x i64> %step
368 %ptrs2 = getelementptr i64, <vscale x 1 x ptr> %ptrs1, <vscale x 1 x i64> %offset
369 %x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
370 <vscale x 1 x ptr> %ptrs2,
372 <vscale x 1 x i1> splat (i1 1),
373 <vscale x 1 x i64> poison
375 ret <vscale x 1 x i64> %x
378 declare i64 @llvm.vscale.i64()
379 declare void @llvm.masked.scatter.nxv1i64.nxv1p0(<vscale x 1 x i64>, <vscale x 1 x ptr>, i32, <vscale x 1 x i1>)
380 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>)