You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[RISCVGatherScatterLowering] Support shl in non-recursive matching
We can apply the same logic as for multiply since a left shift is just a multiply by a power of two. Note that since shl is not commutative, we do need to be careful to match sure that the splat is the RHS of the instruction.
Differential Revision: https://reviews.llvm.org/D150471
; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP2]], 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))
120
+
; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
121
+
;
122
+
%step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
123
+
%splat.insert = insertelement <vscale x 1 x i64> poison, i64%offset, i640
124
+
%splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
125
+
%offsetv = add <vscale x 1 x i64> %step, %splat
126
+
%ptrs = getelementptri32, ptr%p, <vscale x 1 x i64> %offsetv
127
+
%x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
128
+
<vscale x 1 x ptr> %ptrs,
129
+
i328,
130
+
<vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i11, i640), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer),
131
+
<vscale x 1 x i64> poison
132
+
)
133
+
ret <vscale x 1 x i64> %x
134
+
}
135
+
136
+
define <vscale x 1 x i64> @straightline_offset_shl(ptr%p) {
; 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 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))
140
+
; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
141
+
;
142
+
%step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
143
+
%splat.insert = insertelement <vscale x 1 x i64> poison, i643, i640
144
+
%splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
145
+
%offset = shl <vscale x 1 x i64> %step, %splat
146
+
%ptrs = getelementptri32, ptr%p, <vscale x 1 x i64> %offset
147
+
%x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
148
+
<vscale x 1 x ptr> %ptrs,
149
+
i328,
150
+
<vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i11, i640), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer),
151
+
<vscale x 1 x i64> poison
152
+
)
153
+
ret <vscale x 1 x i64> %x
154
+
}
155
+
156
+
define <vscale x 1 x i64> @neg_shl_is_not_commutative(ptr%p) {
157
+
; CHECK-LABEL: @neg_shl_is_not_commutative(
158
+
; CHECK-NEXT: [[STEP:%.*]] = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
159
+
; CHECK-NEXT: [[SPLAT_INSERT:%.*]] = insertelement <vscale x 1 x i64> poison, i64 3, i64 0
160
+
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 1 x i64> [[SPLAT_INSERT]], <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
161
+
; CHECK-NEXT: [[OFFSET:%.*]] = shl <vscale x 1 x i64> [[SPLAT]], [[STEP]]
162
+
; CHECK-NEXT: [[PTRS:%.*]] = getelementptr i32, ptr [[P:%.*]], <vscale x 1 x i64> [[OFFSET]]
163
+
; 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)
164
+
; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
165
+
;
166
+
%step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
167
+
%splat.insert = insertelement <vscale x 1 x i64> poison, i643, i640
168
+
%splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
169
+
%offset = shl <vscale x 1 x i64> %splat, %step
170
+
%ptrs = getelementptri32, ptr%p, <vscale x 1 x i64> %offset
171
+
%x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
172
+
<vscale x 1 x ptr> %ptrs,
173
+
i328,
174
+
<vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i11, i640), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer),
175
+
<vscale x 1 x i64> poison
176
+
)
177
+
ret <vscale x 1 x i64> %x
178
+
}
179
+
180
+
define <vscale x 1 x i64> @straightline_offset_shl_nonc(ptr%p, i64%shift) {
; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP3]], i64 [[TMP4]], <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))
187
+
; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
188
+
;
189
+
%step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
190
+
%splat.insert = insertelement <vscale x 1 x i64> poison, i64%shift, i640
191
+
%splat = shufflevector <vscale x 1 x i64> %splat.insert, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
192
+
%offset = shl <vscale x 1 x i64> %step, %splat
193
+
%ptrs = getelementptri32, ptr%p, <vscale x 1 x i64> %offset
194
+
%x = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(
195
+
<vscale x 1 x ptr> %ptrs,
196
+
i328,
197
+
<vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i11, i640), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer),
198
+
<vscale x 1 x i64> poison
199
+
)
200
+
ret <vscale x 1 x i64> %x
201
+
}
202
+
115
203
definevoid@scatter_loopless(<vscale x 1 x i64> %x, ptr%p, i64%stride) {
116
204
; CHECK-LABEL: @scatter_loopless(
117
205
; CHECK-NEXT: [[TMP1:%.*]] = mul i64 0, [[STRIDE:%.*]]
0 commit comments