1 // WebAssemblyInstrSIMD.td - WebAssembly SIMD codegen support -*- tablegen -*-//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// WebAssembly SIMD operand code-gen constructs.
12 //===----------------------------------------------------------------------===//
14 // Instructions using the SIMD opcode prefix and requiring one of the SIMD
15 // feature predicates.
16 multiclass ABSTRACT_SIMD_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
17 list<dag> pattern_r, string asmstr_r,
18 string asmstr_s, bits<32> simdop,
19 Predicate simd_level> {
20 defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s,
21 !if(!ge(simdop, 0x100),
22 !or(0xfd0000, !and(0xffff, simdop)),
23 !or(0xfd00, !and(0xff, simdop)))>,
24 Requires<[simd_level]>;
27 multiclass SIMD_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
28 list<dag> pattern_r, string asmstr_r = "",
29 string asmstr_s = "", bits<32> simdop = -1> {
30 defm "" : ABSTRACT_SIMD_I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r,
31 asmstr_s, simdop, HasSIMD128>;
34 multiclass RELAXED_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
35 list<dag> pattern_r, string asmstr_r = "",
36 string asmstr_s = "", bits<32> simdop = -1> {
37 defm "" : ABSTRACT_SIMD_I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r,
38 asmstr_s, simdop, HasRelaxedSIMD>;
42 defm "" : ARGUMENT<V128, v16i8>;
43 defm "" : ARGUMENT<V128, v8i16>;
44 defm "" : ARGUMENT<V128, v4i32>;
45 defm "" : ARGUMENT<V128, v2i64>;
46 defm "" : ARGUMENT<V128, v4f32>;
47 defm "" : ARGUMENT<V128, v2f64>;
49 // Constrained immediate argument types
50 foreach SIZE = [8, 16] in
51 def ImmI#SIZE : ImmLeaf<i32,
52 "return -(1 << ("#SIZE#" - 1)) <= Imm && Imm < (1 << ("#SIZE#" - 1));"
54 foreach SIZE = [2, 4, 8, 16, 32] in
55 def LaneIdx#SIZE : ImmLeaf<i32, "return 0 <= Imm && Imm < "#SIZE#";">;
57 // Create vector with identical lanes: splat
58 def splat2 : PatFrag<(ops node:$x), (build_vector $x, $x)>;
59 def splat4 : PatFrag<(ops node:$x), (build_vector $x, $x, $x, $x)>;
60 def splat8 : PatFrag<(ops node:$x), (build_vector $x, $x, $x, $x,
62 def splat16 : PatFrag<(ops node:$x),
63 (build_vector $x, $x, $x, $x, $x, $x, $x, $x,
64 $x, $x, $x, $x, $x, $x, $x, $x)>;
70 WebAssemblyRegClass lane_rc;
84 let lane_idx = LaneIdx16;
95 let lane_idx = LaneIdx8;
107 let lane_idx = LaneIdx4;
109 let prefix = "i32x4";
119 let lane_idx = LaneIdx2;
121 let prefix = "i64x2";
131 let lane_idx = LaneIdx4;
133 let prefix = "f32x4";
142 let lane_idx = LaneIdx2;
144 let prefix = "f64x2";
147 defvar AllVecs = [I8x16, I16x8, I32x4, I64x2, F32x4, F64x2];
148 defvar IntVecs = [I8x16, I16x8, I32x4, I64x2];
150 //===----------------------------------------------------------------------===//
152 //===----------------------------------------------------------------------===//
155 let mayLoad = 1, UseNamedOperandTable = 1 in {
157 SIMD_I<(outs V128:$dst), (ins P2Align:$p2align, offset32_op:$off, I32:$addr),
158 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
159 "v128.load\t$dst, ${off}(${addr})$p2align",
160 "v128.load\t$off$p2align", 0>;
162 SIMD_I<(outs V128:$dst), (ins P2Align:$p2align, offset64_op:$off, I64:$addr),
163 (outs), (ins P2Align:$p2align, offset64_op:$off), [],
164 "v128.load\t$dst, ${off}(${addr})$p2align",
165 "v128.load\t$off$p2align", 0>;
168 // Def load patterns from WebAssemblyInstrMemory.td for vector types
169 foreach vec = AllVecs in {
170 defm : LoadPatNoOffset<vec.vt, load, "LOAD_V128">;
171 defm : LoadPatImmOff<vec.vt, load, regPlusImm, "LOAD_V128">;
172 defm : LoadPatImmOff<vec.vt, load, or_is_add, "LOAD_V128">;
173 defm : LoadPatOffsetOnly<vec.vt, load, "LOAD_V128">;
174 defm : LoadPatGlobalAddrOffOnly<vec.vt, load, "LOAD_V128">;
178 multiclass SIMDLoadSplat<int size, bits<32> simdop> {
179 let mayLoad = 1, UseNamedOperandTable = 1 in {
180 defm LOAD#size#_SPLAT_A32 :
181 SIMD_I<(outs V128:$dst),
182 (ins P2Align:$p2align, offset32_op:$off, I32:$addr),
184 (ins P2Align:$p2align, offset32_op:$off), [],
185 "v128.load"#size#"_splat\t$dst, ${off}(${addr})$p2align",
186 "v128.load"#size#"_splat\t$off$p2align", simdop>;
187 defm LOAD#size#_SPLAT_A64 :
188 SIMD_I<(outs V128:$dst),
189 (ins P2Align:$p2align, offset64_op:$off, I64:$addr),
191 (ins P2Align:$p2align, offset64_op:$off), [],
192 "v128.load"#size#"_splat\t$dst, ${off}(${addr})$p2align",
193 "v128.load"#size#"_splat\t$off$p2align", simdop>;
197 defm "" : SIMDLoadSplat<8, 7>;
198 defm "" : SIMDLoadSplat<16, 8>;
199 defm "" : SIMDLoadSplat<32, 9>;
200 defm "" : SIMDLoadSplat<64, 10>;
202 def wasm_load_splat_t : SDTypeProfile<1, 1, [SDTCisPtrTy<1>]>;
203 def wasm_load_splat : SDNode<"WebAssemblyISD::LOAD_SPLAT", wasm_load_splat_t,
204 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
205 def load_splat : PatFrag<(ops node:$addr), (wasm_load_splat node:$addr)>;
207 foreach vec = AllVecs in {
208 defvar inst = "LOAD"#vec.lane_bits#"_SPLAT";
209 defm : LoadPatNoOffset<vec.vt, load_splat, inst>;
210 defm : LoadPatImmOff<vec.vt, load_splat, regPlusImm, inst>;
211 defm : LoadPatImmOff<vec.vt, load_splat, or_is_add, inst>;
212 defm : LoadPatOffsetOnly<vec.vt, load_splat, inst>;
213 defm : LoadPatGlobalAddrOffOnly<vec.vt, load_splat, inst>;
217 multiclass SIMDLoadExtend<Vec vec, string loadPat, bits<32> simdop> {
218 defvar signed = vec.prefix#".load"#loadPat#"_s";
219 defvar unsigned = vec.prefix#".load"#loadPat#"_u";
220 let mayLoad = 1, UseNamedOperandTable = 1 in {
221 defm LOAD_EXTEND_S_#vec#_A32 :
222 SIMD_I<(outs V128:$dst),
223 (ins P2Align:$p2align, offset32_op:$off, I32:$addr),
224 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
225 signed#"\t$dst, ${off}(${addr})$p2align",
226 signed#"\t$off$p2align", simdop>;
227 defm LOAD_EXTEND_U_#vec#_A32 :
228 SIMD_I<(outs V128:$dst),
229 (ins P2Align:$p2align, offset32_op:$off, I32:$addr),
230 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
231 unsigned#"\t$dst, ${off}(${addr})$p2align",
232 unsigned#"\t$off$p2align", !add(simdop, 1)>;
233 defm LOAD_EXTEND_S_#vec#_A64 :
234 SIMD_I<(outs V128:$dst),
235 (ins P2Align:$p2align, offset64_op:$off, I64:$addr),
236 (outs), (ins P2Align:$p2align, offset64_op:$off), [],
237 signed#"\t$dst, ${off}(${addr})$p2align",
238 signed#"\t$off$p2align", simdop>;
239 defm LOAD_EXTEND_U_#vec#_A64 :
240 SIMD_I<(outs V128:$dst),
241 (ins P2Align:$p2align, offset64_op:$off, I64:$addr),
242 (outs), (ins P2Align:$p2align, offset64_op:$off), [],
243 unsigned#"\t$dst, ${off}(${addr})$p2align",
244 unsigned#"\t$off$p2align", !add(simdop, 1)>;
248 defm "" : SIMDLoadExtend<I16x8, "8x8", 1>;
249 defm "" : SIMDLoadExtend<I32x4, "16x4", 3>;
250 defm "" : SIMDLoadExtend<I64x2, "32x2", 5>;
252 foreach vec = [I16x8, I32x4, I64x2] in
253 foreach exts = [["sextloadvi", "_S"],
254 ["zextloadvi", "_U"],
255 ["extloadvi", "_U"]] in {
256 defvar loadpat = !cast<PatFrag>(exts[0]#vec.split.lane_bits);
257 defvar inst = "LOAD_EXTEND"#exts[1]#"_"#vec;
258 defm : LoadPatNoOffset<vec.vt, loadpat, inst>;
259 defm : LoadPatImmOff<vec.vt, loadpat, regPlusImm, inst>;
260 defm : LoadPatImmOff<vec.vt, loadpat, or_is_add, inst>;
261 defm : LoadPatOffsetOnly<vec.vt, loadpat, inst>;
262 defm : LoadPatGlobalAddrOffOnly<vec.vt, loadpat, inst>;
265 // Load lane into zero vector
266 multiclass SIMDLoadZero<Vec vec, bits<32> simdop> {
267 defvar name = "v128.load"#vec.lane_bits#"_zero";
268 let mayLoad = 1, UseNamedOperandTable = 1 in {
269 defm LOAD_ZERO_#vec#_A32 :
270 SIMD_I<(outs V128:$dst),
271 (ins P2Align:$p2align, offset32_op:$off, I32:$addr),
272 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
273 name#"\t$dst, ${off}(${addr})$p2align",
274 name#"\t$off$p2align", simdop>;
275 defm LOAD_ZERO_#vec#_A64 :
276 SIMD_I<(outs V128:$dst),
277 (ins P2Align:$p2align, offset64_op:$off, I64:$addr),
278 (outs), (ins P2Align:$p2align, offset64_op:$off), [],
279 name#"\t$dst, ${off}(${addr})$p2align",
280 name#"\t$off$p2align", simdop>;
281 } // mayLoad = 1, UseNamedOperandTable = 1
284 defm "" : SIMDLoadZero<I32x4, 0x5c>;
285 defm "" : SIMDLoadZero<I64x2, 0x5d>;
287 // Use load_zero to load scalars into vectors as well where possible.
288 // TODO: i32, i16, and i8 scalars
290 PatFrag<(ops node:$addr), (scalar_to_vector (i64 (load $addr)))>;
291 defm : LoadPatNoOffset<v2i64, load_scalar, "LOAD_ZERO_I64x2">;
292 defm : LoadPatImmOff<v2i64, load_scalar, regPlusImm, "LOAD_ZERO_I64x2">;
293 defm : LoadPatImmOff<v2i64, load_scalar, or_is_add, "LOAD_ZERO_I64x2">;
294 defm : LoadPatOffsetOnly<v2i64, load_scalar, "LOAD_ZERO_I64x2">;
295 defm : LoadPatGlobalAddrOffOnly<v2i64, load_scalar, "LOAD_ZERO_I64x2">;
297 // TODO: f32x4 and f64x2 as well
298 foreach vec = [I32x4, I64x2] in {
299 defvar inst = "LOAD_ZERO_"#vec;
300 defvar pat = PatFrag<(ops node:$ptr),
301 (vector_insert (vec.splat (vec.lane_vt 0)), (vec.lane_vt (load $ptr)), 0)>;
302 defm : LoadPatNoOffset<vec.vt, pat, inst>;
303 defm : LoadPatImmOff<vec.vt, pat, regPlusImm, inst>;
304 defm : LoadPatImmOff<vec.vt, pat, or_is_add, inst>;
305 defm : LoadPatOffsetOnly<vec.vt, pat, inst>;
306 defm : LoadPatGlobalAddrOffOnly<vec.vt, pat, inst>;
310 multiclass SIMDLoadLane<Vec vec, bits<32> simdop> {
311 defvar name = "v128.load"#vec.lane_bits#"_lane";
312 let mayLoad = 1, UseNamedOperandTable = 1 in {
313 defm LOAD_LANE_#vec#_A32 :
314 SIMD_I<(outs V128:$dst),
315 (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx,
316 I32:$addr, V128:$vec),
317 (outs), (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx),
318 [], name#"\t$dst, ${off}(${addr})$p2align, $vec, $idx",
319 name#"\t$off$p2align, $idx", simdop>;
320 defm LOAD_LANE_#vec#_A64 :
321 SIMD_I<(outs V128:$dst),
322 (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx,
323 I64:$addr, V128:$vec),
324 (outs), (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx),
325 [], name#"\t$dst, ${off}(${addr})$p2align, $vec, $idx",
326 name#"\t$off$p2align, $idx", simdop>;
327 } // mayLoad = 1, UseNamedOperandTable = 1
330 defm "" : SIMDLoadLane<I8x16, 0x54>;
331 defm "" : SIMDLoadLane<I16x8, 0x55>;
332 defm "" : SIMDLoadLane<I32x4, 0x56>;
333 defm "" : SIMDLoadLane<I64x2, 0x57>;
335 // Select loads with no constant offset.
336 multiclass LoadLanePatNoOffset<Vec vec, SDPatternOperator kind> {
337 defvar load_lane_a32 = !cast<NI>("LOAD_LANE_"#vec#"_A32");
338 defvar load_lane_a64 = !cast<NI>("LOAD_LANE_"#vec#"_A64");
339 def : Pat<(vec.vt (kind (i32 I32:$addr),
340 (vec.vt V128:$vec), (i32 vec.lane_idx:$idx))),
341 (load_lane_a32 0, 0, imm:$idx, $addr, $vec)>,
342 Requires<[HasAddr32]>;
343 def : Pat<(vec.vt (kind (i64 I64:$addr),
344 (vec.vt V128:$vec), (i32 vec.lane_idx:$idx))),
345 (load_lane_a64 0, 0, imm:$idx, $addr, $vec)>,
346 Requires<[HasAddr64]>;
350 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
351 (vector_insert $vec, (i32 (extloadi8 $ptr)), $idx)>;
353 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
354 (vector_insert $vec, (i32 (extloadi16 $ptr)), $idx)>;
356 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
357 (vector_insert $vec, (i32 (load $ptr)), $idx)>;
359 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
360 (vector_insert $vec, (i64 (load $ptr)), $idx)>;
361 // TODO: floating point lanes as well
363 defm : LoadLanePatNoOffset<I8x16, load8_lane>;
364 defm : LoadLanePatNoOffset<I16x8, load16_lane>;
365 defm : LoadLanePatNoOffset<I32x4, load32_lane>;
366 defm : LoadLanePatNoOffset<I64x2, load64_lane>;
368 // TODO: Also support the other load patterns for load_lane once the instructions
369 // are merged to the proposal.
372 let mayStore = 1, UseNamedOperandTable = 1 in {
373 defm STORE_V128_A32 :
374 SIMD_I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, V128:$vec),
375 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
376 "v128.store\t${off}(${addr})$p2align, $vec",
377 "v128.store\t$off$p2align", 11>;
378 defm STORE_V128_A64 :
379 SIMD_I<(outs), (ins P2Align:$p2align, offset64_op:$off, I64:$addr, V128:$vec),
380 (outs), (ins P2Align:$p2align, offset64_op:$off), [],
381 "v128.store\t${off}(${addr})$p2align, $vec",
382 "v128.store\t$off$p2align", 11>;
385 // Def store patterns from WebAssemblyInstrMemory.td for vector types
386 foreach vec = AllVecs in {
387 defm : StorePatNoOffset<vec.vt, store, "STORE_V128">;
388 defm : StorePatImmOff<vec.vt, store, regPlusImm, "STORE_V128">;
389 defm : StorePatImmOff<vec.vt, store, or_is_add, "STORE_V128">;
390 defm : StorePatOffsetOnly<vec.vt, store, "STORE_V128">;
391 defm : StorePatGlobalAddrOffOnly<vec.vt, store, "STORE_V128">;
395 multiclass SIMDStoreLane<Vec vec, bits<32> simdop> {
396 defvar name = "v128.store"#vec.lane_bits#"_lane";
397 let mayStore = 1, UseNamedOperandTable = 1 in {
398 defm STORE_LANE_#vec#_A32 :
400 (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx,
401 I32:$addr, V128:$vec),
402 (outs), (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx),
403 [], name#"\t${off}(${addr})$p2align, $vec, $idx",
404 name#"\t$off$p2align, $idx", simdop>;
405 defm STORE_LANE_#vec#_A64 :
406 SIMD_I<(outs V128:$dst),
407 (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx,
408 I64:$addr, V128:$vec),
409 (outs), (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx),
410 [], name#"\t${off}(${addr})$p2align, $vec, $idx",
411 name#"\t$off$p2align, $idx", simdop>;
412 } // mayStore = 1, UseNamedOperandTable = 1
415 defm "" : SIMDStoreLane<I8x16, 0x58>;
416 defm "" : SIMDStoreLane<I16x8, 0x59>;
417 defm "" : SIMDStoreLane<I32x4, 0x5a>;
418 defm "" : SIMDStoreLane<I64x2, 0x5b>;
420 // Select stores with no constant offset.
421 multiclass StoreLanePatNoOffset<Vec vec, SDPatternOperator kind> {
422 def : Pat<(kind (i32 I32:$addr), (vec.vt V128:$vec), (i32 vec.lane_idx:$idx)),
423 (!cast<NI>("STORE_LANE_"#vec#"_A32") 0, 0, imm:$idx, $addr, $vec)>,
424 Requires<[HasAddr32]>;
425 def : Pat<(kind (i64 I64:$addr), (vec.vt V128:$vec), (i32 vec.lane_idx:$idx)),
426 (!cast<NI>("STORE_LANE_"#vec#"_A64") 0, 0, imm:$idx, $addr, $vec)>,
427 Requires<[HasAddr64]>;
431 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
432 (truncstorei8 (i32 (vector_extract $vec, $idx)), $ptr)>;
434 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
435 (truncstorei16 (i32 (vector_extract $vec, $idx)), $ptr)>;
437 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
438 (store (i32 (vector_extract $vec, $idx)), $ptr)>;
440 PatFrag<(ops node:$ptr, node:$vec, node:$idx),
441 (store (i64 (vector_extract $vec, $idx)), $ptr)>;
442 // TODO: floating point lanes as well
444 let AddedComplexity = 1 in {
445 defm : StoreLanePatNoOffset<I8x16, store8_lane>;
446 defm : StoreLanePatNoOffset<I16x8, store16_lane>;
447 defm : StoreLanePatNoOffset<I32x4, store32_lane>;
448 defm : StoreLanePatNoOffset<I64x2, store64_lane>;
451 //===----------------------------------------------------------------------===//
452 // Constructing SIMD values
453 //===----------------------------------------------------------------------===//
455 // Constant: v128.const
456 multiclass ConstVec<Vec vec, dag ops, dag pat, string args> {
457 let isMoveImm = 1, isReMaterializable = 1 in
458 defm CONST_V128_#vec : SIMD_I<(outs V128:$dst), ops, (outs), ops,
459 [(set V128:$dst, (vec.vt pat))],
460 "v128.const\t$dst, "#args,
461 "v128.const\t"#args, 12>;
464 defm "" : ConstVec<I8x16,
465 (ins vec_i8imm_op:$i0, vec_i8imm_op:$i1,
466 vec_i8imm_op:$i2, vec_i8imm_op:$i3,
467 vec_i8imm_op:$i4, vec_i8imm_op:$i5,
468 vec_i8imm_op:$i6, vec_i8imm_op:$i7,
469 vec_i8imm_op:$i8, vec_i8imm_op:$i9,
470 vec_i8imm_op:$iA, vec_i8imm_op:$iB,
471 vec_i8imm_op:$iC, vec_i8imm_op:$iD,
472 vec_i8imm_op:$iE, vec_i8imm_op:$iF),
473 (build_vector ImmI8:$i0, ImmI8:$i1, ImmI8:$i2, ImmI8:$i3,
474 ImmI8:$i4, ImmI8:$i5, ImmI8:$i6, ImmI8:$i7,
475 ImmI8:$i8, ImmI8:$i9, ImmI8:$iA, ImmI8:$iB,
476 ImmI8:$iC, ImmI8:$iD, ImmI8:$iE, ImmI8:$iF),
477 !strconcat("$i0, $i1, $i2, $i3, $i4, $i5, $i6, $i7, ",
478 "$i8, $i9, $iA, $iB, $iC, $iD, $iE, $iF")>;
479 defm "" : ConstVec<I16x8,
480 (ins vec_i16imm_op:$i0, vec_i16imm_op:$i1,
481 vec_i16imm_op:$i2, vec_i16imm_op:$i3,
482 vec_i16imm_op:$i4, vec_i16imm_op:$i5,
483 vec_i16imm_op:$i6, vec_i16imm_op:$i7),
485 ImmI16:$i0, ImmI16:$i1, ImmI16:$i2, ImmI16:$i3,
486 ImmI16:$i4, ImmI16:$i5, ImmI16:$i6, ImmI16:$i7),
487 "$i0, $i1, $i2, $i3, $i4, $i5, $i6, $i7">;
488 let IsCanonical = 1 in
489 defm "" : ConstVec<I32x4,
490 (ins vec_i32imm_op:$i0, vec_i32imm_op:$i1,
491 vec_i32imm_op:$i2, vec_i32imm_op:$i3),
492 (build_vector (i32 imm:$i0), (i32 imm:$i1),
493 (i32 imm:$i2), (i32 imm:$i3)),
494 "$i0, $i1, $i2, $i3">;
495 defm "" : ConstVec<I64x2,
496 (ins vec_i64imm_op:$i0, vec_i64imm_op:$i1),
497 (build_vector (i64 imm:$i0), (i64 imm:$i1)),
499 defm "" : ConstVec<F32x4,
500 (ins f32imm_op:$i0, f32imm_op:$i1,
501 f32imm_op:$i2, f32imm_op:$i3),
502 (build_vector (f32 fpimm:$i0), (f32 fpimm:$i1),
503 (f32 fpimm:$i2), (f32 fpimm:$i3)),
504 "$i0, $i1, $i2, $i3">;
505 defm "" : ConstVec<F64x2,
506 (ins f64imm_op:$i0, f64imm_op:$i1),
507 (build_vector (f64 fpimm:$i0), (f64 fpimm:$i1)),
510 // Shuffle lanes: shuffle
512 SIMD_I<(outs V128:$dst),
513 (ins V128:$x, V128:$y,
514 vec_i8imm_op:$m0, vec_i8imm_op:$m1,
515 vec_i8imm_op:$m2, vec_i8imm_op:$m3,
516 vec_i8imm_op:$m4, vec_i8imm_op:$m5,
517 vec_i8imm_op:$m6, vec_i8imm_op:$m7,
518 vec_i8imm_op:$m8, vec_i8imm_op:$m9,
519 vec_i8imm_op:$mA, vec_i8imm_op:$mB,
520 vec_i8imm_op:$mC, vec_i8imm_op:$mD,
521 vec_i8imm_op:$mE, vec_i8imm_op:$mF),
524 vec_i8imm_op:$m0, vec_i8imm_op:$m1,
525 vec_i8imm_op:$m2, vec_i8imm_op:$m3,
526 vec_i8imm_op:$m4, vec_i8imm_op:$m5,
527 vec_i8imm_op:$m6, vec_i8imm_op:$m7,
528 vec_i8imm_op:$m8, vec_i8imm_op:$m9,
529 vec_i8imm_op:$mA, vec_i8imm_op:$mB,
530 vec_i8imm_op:$mC, vec_i8imm_op:$mD,
531 vec_i8imm_op:$mE, vec_i8imm_op:$mF),
533 "i8x16.shuffle\t$dst, $x, $y, "#
534 "$m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, "#
535 "$m8, $m9, $mA, $mB, $mC, $mD, $mE, $mF",
537 "$m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, "#
538 "$m8, $m9, $mA, $mB, $mC, $mD, $mE, $mF",
541 // Shuffles after custom lowering
542 def wasm_shuffle_t : SDTypeProfile<1, 18, []>;
543 def wasm_shuffle : SDNode<"WebAssemblyISD::SHUFFLE", wasm_shuffle_t>;
544 foreach vec = AllVecs in {
545 def : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y),
546 (i32 LaneIdx32:$m0), (i32 LaneIdx32:$m1),
547 (i32 LaneIdx32:$m2), (i32 LaneIdx32:$m3),
548 (i32 LaneIdx32:$m4), (i32 LaneIdx32:$m5),
549 (i32 LaneIdx32:$m6), (i32 LaneIdx32:$m7),
550 (i32 LaneIdx32:$m8), (i32 LaneIdx32:$m9),
551 (i32 LaneIdx32:$mA), (i32 LaneIdx32:$mB),
552 (i32 LaneIdx32:$mC), (i32 LaneIdx32:$mD),
553 (i32 LaneIdx32:$mE), (i32 LaneIdx32:$mF))),
555 imm:$m0, imm:$m1, imm:$m2, imm:$m3,
556 imm:$m4, imm:$m5, imm:$m6, imm:$m7,
557 imm:$m8, imm:$m9, imm:$mA, imm:$mB,
558 imm:$mC, imm:$mD, imm:$mE, imm:$mF)>;
561 // Swizzle lanes: i8x16.swizzle
562 def wasm_swizzle_t : SDTypeProfile<1, 2, []>;
563 def wasm_swizzle : SDNode<"WebAssemblyISD::SWIZZLE", wasm_swizzle_t>;
565 SIMD_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins),
566 [(set (v16i8 V128:$dst),
567 (wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))],
568 "i8x16.swizzle\t$dst, $src, $mask", "i8x16.swizzle", 14>;
570 def : Pat<(int_wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)),
571 (SWIZZLE $src, $mask)>;
573 multiclass Splat<Vec vec, bits<32> simdop> {
574 defm SPLAT_#vec : SIMD_I<(outs V128:$dst), (ins vec.lane_rc:$x),
576 [(set (vec.vt V128:$dst),
577 (vec.splat vec.lane_rc:$x))],
578 vec.prefix#".splat\t$dst, $x", vec.prefix#".splat",
582 defm "" : Splat<I8x16, 15>;
583 defm "" : Splat<I16x8, 16>;
584 defm "" : Splat<I32x4, 17>;
585 defm "" : Splat<I64x2, 18>;
586 defm "" : Splat<F32x4, 19>;
587 defm "" : Splat<F64x2, 20>;
589 // scalar_to_vector leaves high lanes undefined, so can be a splat
590 foreach vec = AllVecs in
591 def : Pat<(vec.vt (scalar_to_vector (vec.lane_vt vec.lane_rc:$x))),
592 (!cast<Instruction>("SPLAT_"#vec) $x)>;
594 //===----------------------------------------------------------------------===//
596 //===----------------------------------------------------------------------===//
598 // Extract lane as a scalar: extract_lane / extract_lane_s / extract_lane_u
599 multiclass ExtractLane<Vec vec, bits<32> simdop, string suffix = ""> {
600 defm EXTRACT_LANE_#vec#suffix :
601 SIMD_I<(outs vec.lane_rc:$dst), (ins V128:$vec, vec_i8imm_op:$idx),
602 (outs), (ins vec_i8imm_op:$idx), [],
603 vec.prefix#".extract_lane"#suffix#"\t$dst, $vec, $idx",
604 vec.prefix#".extract_lane"#suffix#"\t$idx", simdop>;
607 defm "" : ExtractLane<I8x16, 21, "_s">;
608 defm "" : ExtractLane<I8x16, 22, "_u">;
609 defm "" : ExtractLane<I16x8, 24, "_s">;
610 defm "" : ExtractLane<I16x8, 25, "_u">;
611 defm "" : ExtractLane<I32x4, 27>;
612 defm "" : ExtractLane<I64x2, 29>;
613 defm "" : ExtractLane<F32x4, 31>;
614 defm "" : ExtractLane<F64x2, 33>;
616 def : Pat<(vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)),
617 (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>;
618 def : Pat<(vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)),
619 (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>;
620 def : Pat<(vector_extract (v4i32 V128:$vec), (i32 LaneIdx4:$idx)),
621 (EXTRACT_LANE_I32x4 $vec, imm:$idx)>;
622 def : Pat<(vector_extract (v4f32 V128:$vec), (i32 LaneIdx4:$idx)),
623 (EXTRACT_LANE_F32x4 $vec, imm:$idx)>;
624 def : Pat<(vector_extract (v2i64 V128:$vec), (i32 LaneIdx2:$idx)),
625 (EXTRACT_LANE_I64x2 $vec, imm:$idx)>;
626 def : Pat<(vector_extract (v2f64 V128:$vec), (i32 LaneIdx2:$idx)),
627 (EXTRACT_LANE_F64x2 $vec, imm:$idx)>;
630 (sext_inreg (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), i8),
631 (EXTRACT_LANE_I8x16_s $vec, imm:$idx)>;
633 (and (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), (i32 0xff)),
634 (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>;
636 (sext_inreg (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), i16),
637 (EXTRACT_LANE_I16x8_s $vec, imm:$idx)>;
639 (and (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), (i32 0xffff)),
640 (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>;
642 // Replace lane value: replace_lane
643 multiclass ReplaceLane<Vec vec, bits<32> simdop> {
644 defm REPLACE_LANE_#vec :
645 SIMD_I<(outs V128:$dst), (ins V128:$vec, vec_i8imm_op:$idx, vec.lane_rc:$x),
646 (outs), (ins vec_i8imm_op:$idx),
647 [(set V128:$dst, (vector_insert
649 (vec.lane_vt vec.lane_rc:$x),
650 (i32 vec.lane_idx:$idx)))],
651 vec.prefix#".replace_lane\t$dst, $vec, $idx, $x",
652 vec.prefix#".replace_lane\t$idx", simdop>;
655 defm "" : ReplaceLane<I8x16, 23>;
656 defm "" : ReplaceLane<I16x8, 26>;
657 defm "" : ReplaceLane<I32x4, 28>;
658 defm "" : ReplaceLane<I64x2, 30>;
659 defm "" : ReplaceLane<F32x4, 32>;
660 defm "" : ReplaceLane<F64x2, 34>;
662 // Lower undef lane indices to zero
663 def : Pat<(vector_insert (v16i8 V128:$vec), I32:$x, undef),
664 (REPLACE_LANE_I8x16 $vec, 0, $x)>;
665 def : Pat<(vector_insert (v8i16 V128:$vec), I32:$x, undef),
666 (REPLACE_LANE_I16x8 $vec, 0, $x)>;
667 def : Pat<(vector_insert (v4i32 V128:$vec), I32:$x, undef),
668 (REPLACE_LANE_I32x4 $vec, 0, $x)>;
669 def : Pat<(vector_insert (v2i64 V128:$vec), I64:$x, undef),
670 (REPLACE_LANE_I64x2 $vec, 0, $x)>;
671 def : Pat<(vector_insert (v4f32 V128:$vec), F32:$x, undef),
672 (REPLACE_LANE_F32x4 $vec, 0, $x)>;
673 def : Pat<(vector_insert (v2f64 V128:$vec), F64:$x, undef),
674 (REPLACE_LANE_F64x2 $vec, 0, $x)>;
676 //===----------------------------------------------------------------------===//
678 //===----------------------------------------------------------------------===//
680 multiclass SIMDCondition<Vec vec, string name, CondCode cond, bits<32> simdop> {
682 SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins),
683 [(set (vec.int_vt V128:$dst),
684 (setcc (vec.vt V128:$lhs), (vec.vt V128:$rhs), cond))],
685 vec.prefix#"."#name#"\t$dst, $lhs, $rhs",
686 vec.prefix#"."#name, simdop>;
689 multiclass SIMDConditionInt<string name, CondCode cond, bits<32> baseInst> {
690 defm "" : SIMDCondition<I8x16, name, cond, baseInst>;
691 defm "" : SIMDCondition<I16x8, name, cond, !add(baseInst, 10)>;
692 defm "" : SIMDCondition<I32x4, name, cond, !add(baseInst, 20)>;
695 multiclass SIMDConditionFP<string name, CondCode cond, bits<32> baseInst> {
696 defm "" : SIMDCondition<F32x4, name, cond, baseInst>;
697 defm "" : SIMDCondition<F64x2, name, cond, !add(baseInst, 6)>;
701 let isCommutable = 1 in {
702 defm EQ : SIMDConditionInt<"eq", SETEQ, 35>;
703 defm EQ : SIMDCondition<I64x2, "eq", SETEQ, 214>;
704 defm EQ : SIMDConditionFP<"eq", SETOEQ, 65>;
705 } // isCommutable = 1
708 let isCommutable = 1 in {
709 defm NE : SIMDConditionInt<"ne", SETNE, 36>;
710 defm NE : SIMDCondition<I64x2, "ne", SETNE, 215>;
711 defm NE : SIMDConditionFP<"ne", SETUNE, 66>;
712 } // isCommutable = 1
714 // Less than: lt_s / lt_u / lt
715 defm LT_S : SIMDConditionInt<"lt_s", SETLT, 37>;
716 defm LT_S : SIMDCondition<I64x2, "lt_s", SETLT, 216>;
717 defm LT_U : SIMDConditionInt<"lt_u", SETULT, 38>;
718 defm LT : SIMDConditionFP<"lt", SETOLT, 67>;
720 // Greater than: gt_s / gt_u / gt
721 defm GT_S : SIMDConditionInt<"gt_s", SETGT, 39>;
722 defm GT_S : SIMDCondition<I64x2, "gt_s", SETGT, 217>;
723 defm GT_U : SIMDConditionInt<"gt_u", SETUGT, 40>;
724 defm GT : SIMDConditionFP<"gt", SETOGT, 68>;
726 // Less than or equal: le_s / le_u / le
727 defm LE_S : SIMDConditionInt<"le_s", SETLE, 41>;
728 defm LE_S : SIMDCondition<I64x2, "le_s", SETLE, 218>;
729 defm LE_U : SIMDConditionInt<"le_u", SETULE, 42>;
730 defm LE : SIMDConditionFP<"le", SETOLE, 69>;
732 // Greater than or equal: ge_s / ge_u / ge
733 defm GE_S : SIMDConditionInt<"ge_s", SETGE, 43>;
734 defm GE_S : SIMDCondition<I64x2, "ge_s", SETGE, 219>;
735 defm GE_U : SIMDConditionInt<"ge_u", SETUGE, 44>;
736 defm GE : SIMDConditionFP<"ge", SETOGE, 70>;
738 // Lower float comparisons that don't care about NaN to standard WebAssembly
739 // float comparisons. These instructions are generated with nnan and in the
740 // target-independent expansion of unordered comparisons and ordered ne.
741 foreach nodes = [[seteq, EQ_F32x4], [setne, NE_F32x4], [setlt, LT_F32x4],
742 [setgt, GT_F32x4], [setle, LE_F32x4], [setge, GE_F32x4]] in
743 def : Pat<(v4i32 (nodes[0] (v4f32 V128:$lhs), (v4f32 V128:$rhs))),
744 (nodes[1] $lhs, $rhs)>;
746 foreach nodes = [[seteq, EQ_F64x2], [setne, NE_F64x2], [setlt, LT_F64x2],
747 [setgt, GT_F64x2], [setle, LE_F64x2], [setge, GE_F64x2]] in
748 def : Pat<(v2i64 (nodes[0] (v2f64 V128:$lhs), (v2f64 V128:$rhs))),
749 (nodes[1] $lhs, $rhs)>;
751 //===----------------------------------------------------------------------===//
752 // Bitwise operations
753 //===----------------------------------------------------------------------===//
755 multiclass SIMDBinary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> {
756 defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
758 [(set (vec.vt V128:$dst),
759 (node (vec.vt V128:$lhs), (vec.vt V128:$rhs)))],
760 vec.prefix#"."#name#"\t$dst, $lhs, $rhs",
761 vec.prefix#"."#name, simdop>;
764 multiclass SIMDBitwise<SDPatternOperator node, string name, bits<32> simdop,
765 bit commutable = false> {
766 let isCommutable = commutable in
767 defm "" : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
769 "v128."#name#"\t$dst, $lhs, $rhs", "v128."#name, simdop>;
770 foreach vec = IntVecs in
771 def : Pat<(node (vec.vt V128:$lhs), (vec.vt V128:$rhs)),
772 (!cast<NI>(NAME) $lhs, $rhs)>;
775 multiclass SIMDUnary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> {
776 defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins),
777 [(set (vec.vt V128:$dst),
778 (vec.vt (node (vec.vt V128:$v))))],
779 vec.prefix#"."#name#"\t$dst, $v",
780 vec.prefix#"."#name, simdop>;
783 // Bitwise logic: v128.not
784 defm NOT : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins), [],
785 "v128.not\t$dst, $v", "v128.not", 77>;
786 foreach vec = IntVecs in
787 def : Pat<(vnot (vec.vt V128:$v)), (NOT $v)>;
789 // Bitwise logic: v128.and / v128.or / v128.xor
790 defm AND : SIMDBitwise<and, "and", 78, true>;
791 defm OR : SIMDBitwise<or, "or", 80, true>;
792 defm XOR : SIMDBitwise<xor, "xor", 81, true>;
794 // Bitwise logic: v128.andnot
795 def andnot : PatFrag<(ops node:$left, node:$right), (and $left, (vnot $right))>;
796 defm ANDNOT : SIMDBitwise<andnot, "andnot", 79>;
798 // Bitwise select: v128.bitselect
800 SIMD_I<(outs V128:$dst), (ins V128:$v1, V128:$v2, V128:$c), (outs), (ins), [],
801 "v128.bitselect\t$dst, $v1, $v2, $c", "v128.bitselect", 82>;
803 foreach vec = AllVecs in
804 def : Pat<(vec.vt (int_wasm_bitselect
805 (vec.vt V128:$v1), (vec.vt V128:$v2), (vec.vt V128:$c))),
806 (BITSELECT $v1, $v2, $c)>;
808 // Bitselect is equivalent to (c & v1) | (~c & v2)
809 foreach vec = IntVecs in
810 def : Pat<(vec.vt (or (and (vec.vt V128:$c), (vec.vt V128:$v1)),
811 (and (vnot V128:$c), (vec.vt V128:$v2)))),
812 (BITSELECT $v1, $v2, $c)>;
814 // Also implement vselect in terms of bitselect
815 foreach vec = AllVecs in
816 def : Pat<(vec.vt (vselect
817 (vec.int_vt V128:$c), (vec.vt V128:$v1), (vec.vt V128:$v2))),
818 (BITSELECT $v1, $v2, $c)>;
820 // MVP select on v128 values
822 I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, I32:$cond), (outs), (ins), [],
823 "v128.select\t$dst, $lhs, $rhs, $cond", "v128.select", 0x1b>;
825 foreach vec = AllVecs in {
826 def : Pat<(select I32:$cond, (vec.vt V128:$lhs), (vec.vt V128:$rhs)),
827 (SELECT_V128 $lhs, $rhs, $cond)>;
829 // ISD::SELECT requires its operand to conform to getBooleanContents, but
830 // WebAssembly's select interprets any non-zero value as true, so we can fold
831 // a setne with 0 into a select.
833 (i32 (setne I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)),
834 (SELECT_V128 $lhs, $rhs, $cond)>;
836 // And again, this time with seteq instead of setne and the arms reversed.
838 (i32 (seteq I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)),
839 (SELECT_V128 $rhs, $lhs, $cond)>;
842 //===----------------------------------------------------------------------===//
843 // Integer unary arithmetic
844 //===----------------------------------------------------------------------===//
846 multiclass SIMDUnaryInt<SDPatternOperator node, string name, bits<32> baseInst> {
847 defm "" : SIMDUnary<I8x16, node, name, baseInst>;
848 defm "" : SIMDUnary<I16x8, node, name, !add(baseInst, 32)>;
849 defm "" : SIMDUnary<I32x4, node, name, !add(baseInst, 64)>;
850 defm "" : SIMDUnary<I64x2, node, name, !add(baseInst, 96)>;
853 // Integer vector negation
854 def ivneg : PatFrag<(ops node:$in), (sub immAllZerosV, $in)>;
856 // Integer absolute value: abs
857 defm ABS : SIMDUnaryInt<abs, "abs", 96>;
859 // Integer negation: neg
860 defm NEG : SIMDUnaryInt<ivneg, "neg", 97>;
862 // Population count: popcnt
863 defm POPCNT : SIMDUnary<I8x16, ctpop, "popcnt", 0x62>;
865 // Any lane true: any_true
866 defm ANYTRUE : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), [],
867 "v128.any_true\t$dst, $vec", "v128.any_true", 0x53>;
869 foreach vec = IntVecs in
870 def : Pat<(int_wasm_anytrue (vec.vt V128:$vec)), (ANYTRUE V128:$vec)>;
872 // All lanes true: all_true
873 multiclass SIMDAllTrue<Vec vec, bits<32> simdop> {
874 defm ALLTRUE_#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins),
876 (i32 (int_wasm_alltrue (vec.vt V128:$vec))))],
877 vec.prefix#".all_true\t$dst, $vec",
878 vec.prefix#".all_true", simdop>;
881 defm "" : SIMDAllTrue<I8x16, 0x63>;
882 defm "" : SIMDAllTrue<I16x8, 0x83>;
883 defm "" : SIMDAllTrue<I32x4, 0xa3>;
884 defm "" : SIMDAllTrue<I64x2, 0xc3>;
886 // Reductions already return 0 or 1, so and 1, setne 0, and seteq 1
889 [["int_wasm_anytrue", "ANYTRUE", "I8x16"],
890 ["int_wasm_anytrue", "ANYTRUE", "I16x8"],
891 ["int_wasm_anytrue", "ANYTRUE", "I32x4"],
892 ["int_wasm_anytrue", "ANYTRUE", "I64x2"],
893 ["int_wasm_alltrue", "ALLTRUE_I8x16", "I8x16"],
894 ["int_wasm_alltrue", "ALLTRUE_I16x8", "I16x8"],
895 ["int_wasm_alltrue", "ALLTRUE_I32x4", "I32x4"],
896 ["int_wasm_alltrue", "ALLTRUE_I64x2", "I64x2"]] in {
897 defvar intrinsic = !cast<Intrinsic>(reduction[0]);
898 defvar inst = !cast<NI>(reduction[1]);
899 defvar vec = !cast<Vec>(reduction[2]);
900 def : Pat<(i32 (and (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>;
901 def : Pat<(i32 (setne (i32 (intrinsic (vec.vt V128:$x))), (i32 0))), (inst $x)>;
902 def : Pat<(i32 (seteq (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>;
905 multiclass SIMDBitmask<Vec vec, bits<32> simdop> {
906 defm _#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins),
908 (i32 (int_wasm_bitmask (vec.vt V128:$vec))))],
909 vec.prefix#".bitmask\t$dst, $vec", vec.prefix#".bitmask",
913 defm BITMASK : SIMDBitmask<I8x16, 100>;
914 defm BITMASK : SIMDBitmask<I16x8, 132>;
915 defm BITMASK : SIMDBitmask<I32x4, 164>;
916 defm BITMASK : SIMDBitmask<I64x2, 196>;
918 //===----------------------------------------------------------------------===//
920 //===----------------------------------------------------------------------===//
922 multiclass SIMDShift<Vec vec, SDNode node, string name, bits<32> simdop> {
923 defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$vec, I32:$x), (outs), (ins),
924 [(set (vec.vt V128:$dst), (node V128:$vec, I32:$x))],
925 vec.prefix#"."#name#"\t$dst, $vec, $x",
926 vec.prefix#"."#name, simdop>;
929 multiclass SIMDShiftInt<SDNode node, string name, bits<32> baseInst> {
930 defm "" : SIMDShift<I8x16, node, name, baseInst>;
931 defm "" : SIMDShift<I16x8, node, name, !add(baseInst, 32)>;
932 defm "" : SIMDShift<I32x4, node, name, !add(baseInst, 64)>;
933 defm "" : SIMDShift<I64x2, node, name, !add(baseInst, 96)>;
936 // WebAssembly SIMD shifts are nonstandard in that the shift amount is
937 // an i32 rather than a vector, so they need custom nodes.
939 SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, i32>]>;
940 def wasm_shl : SDNode<"WebAssemblyISD::VEC_SHL", wasm_shift_t>;
941 def wasm_shr_s : SDNode<"WebAssemblyISD::VEC_SHR_S", wasm_shift_t>;
942 def wasm_shr_u : SDNode<"WebAssemblyISD::VEC_SHR_U", wasm_shift_t>;
944 // Left shift by scalar: shl
945 defm SHL : SIMDShiftInt<wasm_shl, "shl", 107>;
947 // Right shift by scalar: shr_s / shr_u
948 defm SHR_S : SIMDShiftInt<wasm_shr_s, "shr_s", 108>;
949 defm SHR_U : SIMDShiftInt<wasm_shr_u, "shr_u", 109>;
951 // Optimize away an explicit mask on a shift count.
952 def : Pat<(wasm_shl (v16i8 V128:$lhs), (and I32:$rhs, 7)),
953 (SHL_I8x16 V128:$lhs, I32:$rhs)>;
954 def : Pat<(wasm_shr_s (v16i8 V128:$lhs), (and I32:$rhs, 7)),
955 (SHR_S_I8x16 V128:$lhs, I32:$rhs)>;
956 def : Pat<(wasm_shr_u (v16i8 V128:$lhs), (and I32:$rhs, 7)),
957 (SHR_U_I8x16 V128:$lhs, I32:$rhs)>;
959 def : Pat<(wasm_shl (v8i16 V128:$lhs), (and I32:$rhs, 15)),
960 (SHL_I16x8 V128:$lhs, I32:$rhs)>;
961 def : Pat<(wasm_shr_s (v8i16 V128:$lhs), (and I32:$rhs, 15)),
962 (SHR_S_I16x8 V128:$lhs, I32:$rhs)>;
963 def : Pat<(wasm_shr_u (v8i16 V128:$lhs), (and I32:$rhs, 15)),
964 (SHR_U_I16x8 V128:$lhs, I32:$rhs)>;
966 def : Pat<(wasm_shl (v4i32 V128:$lhs), (and I32:$rhs, 31)),
967 (SHL_I32x4 V128:$lhs, I32:$rhs)>;
968 def : Pat<(wasm_shr_s (v4i32 V128:$lhs), (and I32:$rhs, 31)),
969 (SHR_S_I32x4 V128:$lhs, I32:$rhs)>;
970 def : Pat<(wasm_shr_u (v4i32 V128:$lhs), (and I32:$rhs, 31)),
971 (SHR_U_I32x4 V128:$lhs, I32:$rhs)>;
973 def : Pat<(wasm_shl (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))),
974 (SHL_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>;
975 def : Pat<(wasm_shr_s (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))),
976 (SHR_S_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>;
977 def : Pat<(wasm_shr_u (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))),
978 (SHR_U_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>;
980 //===----------------------------------------------------------------------===//
981 // Integer binary arithmetic
982 //===----------------------------------------------------------------------===//
984 multiclass SIMDBinaryIntNoI8x16<SDPatternOperator node, string name, bits<32> baseInst> {
985 defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>;
986 defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>;
987 defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>;
990 multiclass SIMDBinaryIntSmall<SDPatternOperator node, string name, bits<32> baseInst> {
991 defm "" : SIMDBinary<I8x16, node, name, baseInst>;
992 defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>;
995 multiclass SIMDBinaryIntNoI64x2<SDPatternOperator node, string name, bits<32> baseInst> {
996 defm "" : SIMDBinaryIntSmall<node, name, baseInst>;
997 defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>;
1000 multiclass SIMDBinaryInt<SDPatternOperator node, string name, bits<32> baseInst> {
1001 defm "" : SIMDBinaryIntNoI64x2<node, name, baseInst>;
1002 defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>;
1005 // Integer addition: add / add_sat_s / add_sat_u
1006 let isCommutable = 1 in {
1007 defm ADD : SIMDBinaryInt<add, "add", 110>;
1008 defm ADD_SAT_S : SIMDBinaryIntSmall<saddsat, "add_sat_s", 111>;
1009 defm ADD_SAT_U : SIMDBinaryIntSmall<uaddsat, "add_sat_u", 112>;
1010 } // isCommutable = 1
1012 // Integer subtraction: sub / sub_sat_s / sub_sat_u
1013 defm SUB : SIMDBinaryInt<sub, "sub", 113>;
1015 SIMDBinaryIntSmall<int_wasm_sub_sat_signed, "sub_sat_s", 114>;
1017 SIMDBinaryIntSmall<int_wasm_sub_sat_unsigned, "sub_sat_u", 115>;
1019 // Integer multiplication: mul
1020 let isCommutable = 1 in
1021 defm MUL : SIMDBinaryIntNoI8x16<mul, "mul", 117>;
1023 // Integer min_s / min_u / max_s / max_u
1024 let isCommutable = 1 in {
1025 defm MIN_S : SIMDBinaryIntNoI64x2<smin, "min_s", 118>;
1026 defm MIN_U : SIMDBinaryIntNoI64x2<umin, "min_u", 119>;
1027 defm MAX_S : SIMDBinaryIntNoI64x2<smax, "max_s", 120>;
1028 defm MAX_U : SIMDBinaryIntNoI64x2<umax, "max_u", 121>;
1029 } // isCommutable = 1
1031 // Integer unsigned rounding average: avgr_u
1032 let isCommutable = 1 in {
1033 defm AVGR_U : SIMDBinary<I8x16, int_wasm_avgr_unsigned, "avgr_u", 123>;
1034 defm AVGR_U : SIMDBinary<I16x8, int_wasm_avgr_unsigned, "avgr_u", 155>;
1037 def add_nuw : PatFrag<(ops node:$lhs, node:$rhs), (add $lhs, $rhs),
1038 "return N->getFlags().hasNoUnsignedWrap();">;
1040 foreach vec = [I8x16, I16x8] in {
1041 defvar inst = !cast<NI>("AVGR_U_"#vec);
1042 def : Pat<(wasm_shr_u
1044 (add_nuw (vec.vt V128:$lhs), (vec.vt V128:$rhs)),
1045 (vec.splat (i32 1))),
1050 // Widening dot product: i32x4.dot_i16x8_s
1051 let isCommutable = 1 in
1052 defm DOT : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins),
1053 [(set V128:$dst, (int_wasm_dot V128:$lhs, V128:$rhs))],
1054 "i32x4.dot_i16x8_s\t$dst, $lhs, $rhs", "i32x4.dot_i16x8_s",
1057 // Extending multiplication: extmul_{low,high}_P, extmul_high
1058 def extend_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
1059 def extend_low_s : SDNode<"WebAssemblyISD::EXTEND_LOW_S", extend_t>;
1060 def extend_high_s : SDNode<"WebAssemblyISD::EXTEND_HIGH_S", extend_t>;
1061 def extend_low_u : SDNode<"WebAssemblyISD::EXTEND_LOW_U", extend_t>;
1062 def extend_high_u : SDNode<"WebAssemblyISD::EXTEND_HIGH_U", extend_t>;
1064 multiclass SIMDExtBinary<Vec vec, SDPatternOperator node, string name,
1066 defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
1068 [(set (vec.vt V128:$dst), (node
1069 (vec.split.vt V128:$lhs),(vec.split.vt V128:$rhs)))],
1070 vec.prefix#"."#name#"\t$dst, $lhs, $rhs",
1071 vec.prefix#"."#name, simdop>;
1074 class ExtMulPat<SDNode extend> :
1075 PatFrag<(ops node:$lhs, node:$rhs),
1076 (mul (extend $lhs), (extend $rhs))> {}
1078 def extmul_low_s : ExtMulPat<extend_low_s>;
1079 def extmul_high_s : ExtMulPat<extend_high_s>;
1080 def extmul_low_u : ExtMulPat<extend_low_u>;
1081 def extmul_high_u : ExtMulPat<extend_high_u>;
1084 SIMDExtBinary<I16x8, extmul_low_s, "extmul_low_i8x16_s", 0x9c>;
1085 defm EXTMUL_HIGH_S :
1086 SIMDExtBinary<I16x8, extmul_high_s, "extmul_high_i8x16_s", 0x9d>;
1088 SIMDExtBinary<I16x8, extmul_low_u, "extmul_low_i8x16_u", 0x9e>;
1089 defm EXTMUL_HIGH_U :
1090 SIMDExtBinary<I16x8, extmul_high_u, "extmul_high_i8x16_u", 0x9f>;
1093 SIMDExtBinary<I32x4, extmul_low_s, "extmul_low_i16x8_s", 0xbc>;
1094 defm EXTMUL_HIGH_S :
1095 SIMDExtBinary<I32x4, extmul_high_s, "extmul_high_i16x8_s", 0xbd>;
1097 SIMDExtBinary<I32x4, extmul_low_u, "extmul_low_i16x8_u", 0xbe>;
1098 defm EXTMUL_HIGH_U :
1099 SIMDExtBinary<I32x4, extmul_high_u, "extmul_high_i16x8_u", 0xbf>;
1102 SIMDExtBinary<I64x2, extmul_low_s, "extmul_low_i32x4_s", 0xdc>;
1103 defm EXTMUL_HIGH_S :
1104 SIMDExtBinary<I64x2, extmul_high_s, "extmul_high_i32x4_s", 0xdd>;
1106 SIMDExtBinary<I64x2, extmul_low_u, "extmul_low_i32x4_u", 0xde>;
1107 defm EXTMUL_HIGH_U :
1108 SIMDExtBinary<I64x2, extmul_high_u, "extmul_high_i32x4_u", 0xdf>;
1110 //===----------------------------------------------------------------------===//
1111 // Floating-point unary arithmetic
1112 //===----------------------------------------------------------------------===//
1114 multiclass SIMDUnaryFP<SDNode node, string name, bits<32> baseInst> {
1115 defm "" : SIMDUnary<F32x4, node, name, baseInst>;
1116 defm "" : SIMDUnary<F64x2, node, name, !add(baseInst, 12)>;
1119 // Absolute value: abs
1120 defm ABS : SIMDUnaryFP<fabs, "abs", 224>;
1123 defm NEG : SIMDUnaryFP<fneg, "neg", 225>;
1125 // Square root: sqrt
1126 defm SQRT : SIMDUnaryFP<fsqrt, "sqrt", 227>;
1128 // Rounding: ceil, floor, trunc, nearest
1129 defm CEIL : SIMDUnary<F32x4, fceil, "ceil", 0x67>;
1130 defm FLOOR : SIMDUnary<F32x4, ffloor, "floor", 0x68>;
1131 defm TRUNC: SIMDUnary<F32x4, ftrunc, "trunc", 0x69>;
1132 defm NEAREST: SIMDUnary<F32x4, fnearbyint, "nearest", 0x6a>;
1133 defm CEIL : SIMDUnary<F64x2, fceil, "ceil", 0x74>;
1134 defm FLOOR : SIMDUnary<F64x2, ffloor, "floor", 0x75>;
1135 defm TRUNC: SIMDUnary<F64x2, ftrunc, "trunc", 0x7a>;
1136 defm NEAREST: SIMDUnary<F64x2, fnearbyint, "nearest", 0x94>;
1138 //===----------------------------------------------------------------------===//
1139 // Floating-point binary arithmetic
1140 //===----------------------------------------------------------------------===//
1142 multiclass SIMDBinaryFP<SDPatternOperator node, string name, bits<32> baseInst> {
1143 defm "" : SIMDBinary<F32x4, node, name, baseInst>;
1144 defm "" : SIMDBinary<F64x2, node, name, !add(baseInst, 12)>;
1148 let isCommutable = 1 in
1149 defm ADD : SIMDBinaryFP<fadd, "add", 228>;
1152 defm SUB : SIMDBinaryFP<fsub, "sub", 229>;
1154 // Multiplication: mul
1155 let isCommutable = 1 in
1156 defm MUL : SIMDBinaryFP<fmul, "mul", 230>;
1159 defm DIV : SIMDBinaryFP<fdiv, "div", 231>;
1161 // NaN-propagating minimum: min
1162 defm MIN : SIMDBinaryFP<fminimum, "min", 232>;
1164 // NaN-propagating maximum: max
1165 defm MAX : SIMDBinaryFP<fmaximum, "max", 233>;
1167 // Pseudo-minimum: pmin
1168 def pmin : PatFrag<(ops node:$lhs, node:$rhs),
1169 (vselect (setolt $rhs, $lhs), $rhs, $lhs)>;
1170 defm PMIN : SIMDBinaryFP<pmin, "pmin", 234>;
1172 // Pseudo-maximum: pmax
1173 def pmax : PatFrag<(ops node:$lhs, node:$rhs),
1174 (vselect (setolt $lhs, $rhs), $rhs, $lhs)>;
1175 defm PMAX : SIMDBinaryFP<pmax, "pmax", 235>;
1177 // Also match the pmin/pmax cases where the operands are int vectors (but the
1178 // comparison is still a floating point comparison). This can happen when using
1179 // the wasm_simd128.h intrinsics because v128_t is an integer vector.
1180 foreach vec = [F32x4, F64x2] in {
1181 defvar pmin = !cast<NI>("PMIN_"#vec);
1182 defvar pmax = !cast<NI>("PMAX_"#vec);
1183 def : Pat<(vec.int_vt (vselect
1184 (setolt (vec.vt (bitconvert V128:$rhs)),
1185 (vec.vt (bitconvert V128:$lhs))),
1186 V128:$rhs, V128:$lhs)),
1188 def : Pat<(vec.int_vt (vselect
1189 (setolt (vec.vt (bitconvert V128:$lhs)),
1190 (vec.vt (bitconvert V128:$rhs))),
1191 V128:$rhs, V128:$lhs)),
1195 // And match the pmin/pmax LLVM intrinsics as well
1196 def : Pat<(v4f32 (int_wasm_pmin (v4f32 V128:$lhs), (v4f32 V128:$rhs))),
1197 (PMIN_F32x4 V128:$lhs, V128:$rhs)>;
1198 def : Pat<(v4f32 (int_wasm_pmax (v4f32 V128:$lhs), (v4f32 V128:$rhs))),
1199 (PMAX_F32x4 V128:$lhs, V128:$rhs)>;
1200 def : Pat<(v2f64 (int_wasm_pmin (v2f64 V128:$lhs), (v2f64 V128:$rhs))),
1201 (PMIN_F64x2 V128:$lhs, V128:$rhs)>;
1202 def : Pat<(v2f64 (int_wasm_pmax (v2f64 V128:$lhs), (v2f64 V128:$rhs))),
1203 (PMAX_F64x2 V128:$lhs, V128:$rhs)>;
1205 //===----------------------------------------------------------------------===//
1207 //===----------------------------------------------------------------------===//
1209 multiclass SIMDConvert<Vec vec, Vec arg, SDPatternOperator op, string name,
1212 SIMD_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins),
1213 [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))],
1214 vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>;
1217 // Floating point to integer with saturation: trunc_sat
1218 defm "" : SIMDConvert<I32x4, F32x4, fp_to_sint, "trunc_sat_f32x4_s", 248>;
1219 defm "" : SIMDConvert<I32x4, F32x4, fp_to_uint, "trunc_sat_f32x4_u", 249>;
1221 // Support the saturating variety as well.
1222 def trunc_s_sat32 : PatFrag<(ops node:$x), (fp_to_sint_sat $x, i32)>;
1223 def trunc_u_sat32 : PatFrag<(ops node:$x), (fp_to_uint_sat $x, i32)>;
1224 def : Pat<(v4i32 (trunc_s_sat32 (v4f32 V128:$src))), (fp_to_sint_I32x4 $src)>;
1225 def : Pat<(v4i32 (trunc_u_sat32 (v4f32 V128:$src))), (fp_to_uint_I32x4 $src)>;
1227 def trunc_sat_zero_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
1228 def trunc_sat_zero_s :
1229 SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_S", trunc_sat_zero_t>;
1230 def trunc_sat_zero_u :
1231 SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_U", trunc_sat_zero_t>;
1232 defm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_s, "trunc_sat_zero_f64x2_s",
1234 defm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_u, "trunc_sat_zero_f64x2_u",
1237 // Integer to floating point: convert
1238 def convert_low_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
1239 def convert_low_s : SDNode<"WebAssemblyISD::CONVERT_LOW_S", convert_low_t>;
1240 def convert_low_u : SDNode<"WebAssemblyISD::CONVERT_LOW_U", convert_low_t>;
1241 defm "" : SIMDConvert<F32x4, I32x4, sint_to_fp, "convert_i32x4_s", 250>;
1242 defm "" : SIMDConvert<F32x4, I32x4, uint_to_fp, "convert_i32x4_u", 251>;
1243 defm "" : SIMDConvert<F64x2, I32x4, convert_low_s, "convert_low_i32x4_s", 0xfe>;
1244 defm "" : SIMDConvert<F64x2, I32x4, convert_low_u, "convert_low_i32x4_u", 0xff>;
1246 // Extending operations
1247 // TODO: refactor this to be uniform for i64x2 if the numbering is not changed.
1248 multiclass SIMDExtend<Vec vec, bits<32> baseInst> {
1249 defm "" : SIMDConvert<vec, vec.split, extend_low_s,
1250 "extend_low_"#vec.split.prefix#"_s", baseInst>;
1251 defm "" : SIMDConvert<vec, vec.split, extend_high_s,
1252 "extend_high_"#vec.split.prefix#"_s", !add(baseInst, 1)>;
1253 defm "" : SIMDConvert<vec, vec.split, extend_low_u,
1254 "extend_low_"#vec.split.prefix#"_u", !add(baseInst, 2)>;
1255 defm "" : SIMDConvert<vec, vec.split, extend_high_u,
1256 "extend_high_"#vec.split.prefix#"_u", !add(baseInst, 3)>;
1259 defm "" : SIMDExtend<I16x8, 0x87>;
1260 defm "" : SIMDExtend<I32x4, 0xa7>;
1261 defm "" : SIMDExtend<I64x2, 0xc7>;
1263 // Narrowing operations
1264 multiclass SIMDNarrow<Vec vec, bits<32> baseInst> {
1265 defvar name = vec.split.prefix#".narrow_"#vec.prefix;
1266 defm NARROW_S_#vec.split :
1267 SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins),
1268 [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_signed
1269 (vec.vt V128:$low), (vec.vt V128:$high))))],
1270 name#"_s\t$dst, $low, $high", name#"_s", baseInst>;
1271 defm NARROW_U_#vec.split :
1272 SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins),
1273 [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_unsigned
1274 (vec.vt V128:$low), (vec.vt V128:$high))))],
1275 name#"_u\t$dst, $low, $high", name#"_u", !add(baseInst, 1)>;
1278 defm "" : SIMDNarrow<I16x8, 101>;
1279 defm "" : SIMDNarrow<I32x4, 133>;
1281 // WebAssemblyISD::NARROW_U
1282 def wasm_narrow_t : SDTypeProfile<1, 2, []>;
1283 def wasm_narrow_u : SDNode<"WebAssemblyISD::NARROW_U", wasm_narrow_t>;
1284 def : Pat<(v16i8 (wasm_narrow_u (v8i16 V128:$left), (v8i16 V128:$right))),
1285 (NARROW_U_I8x16 $left, $right)>;
1286 def : Pat<(v8i16 (wasm_narrow_u (v4i32 V128:$left), (v4i32 V128:$right))),
1287 (NARROW_U_I16x8 $left, $right)>;
1289 // Bitcasts are nops
1290 // Matching bitcast t1 to t1 causes strange errors, so avoid repeating types
1291 foreach t1 = AllVecs in
1292 foreach t2 = AllVecs in
1294 def : Pat<(t1.vt (bitconvert (t2.vt V128:$v))), (t1.vt V128:$v)>;
1296 // Extended pairwise addition
1297 defm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_signed,
1298 "extadd_pairwise_i8x16_s", 0x7c>;
1299 defm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_unsigned,
1300 "extadd_pairwise_i8x16_u", 0x7d>;
1301 defm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_signed,
1302 "extadd_pairwise_i16x8_s", 0x7e>;
1303 defm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_unsigned,
1304 "extadd_pairwise_i16x8_u", 0x7f>;
1306 // f64x2 <-> f32x4 conversions
1307 def demote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
1308 def demote_zero : SDNode<"WebAssemblyISD::DEMOTE_ZERO", demote_t>;
1309 defm "" : SIMDConvert<F32x4, F64x2, demote_zero,
1310 "demote_zero_f64x2", 0x5e>;
1312 def promote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
1313 def promote_low : SDNode<"WebAssemblyISD::PROMOTE_LOW", promote_t>;
1314 defm "" : SIMDConvert<F64x2, F32x4, promote_low, "promote_low_f32x4", 0x5f>;
1316 // Lower extending loads to load64_zero + promote_low
1317 def extloadv2f32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1318 let MemoryVT = v2f32;
1320 // Adapted from the body of LoadPatNoOffset
1321 // TODO: other addressing patterns
1322 def : Pat<(v2f64 (extloadv2f32 (i32 I32:$addr))),
1323 (promote_low_F64x2 (LOAD_ZERO_I64x2_A32 0, 0, I32:$addr))>,
1324 Requires<[HasAddr32]>;
1325 def : Pat<(v2f64 (extloadv2f32 (i64 I64:$addr))),
1326 (promote_low_F64x2 (LOAD_ZERO_I64x2_A64 0, 0, I64:$addr))>,
1327 Requires<[HasAddr64]>;
1329 //===----------------------------------------------------------------------===//
1330 // Saturating Rounding Q-Format Multiplication
1331 //===----------------------------------------------------------------------===//
1333 defm Q15MULR_SAT_S :
1334 SIMDBinary<I16x8, int_wasm_q15mulr_sat_signed, "q15mulr_sat_s", 0x82>;
1336 //===----------------------------------------------------------------------===//
1337 // Fused Multiply- Add and Subtract (FMA/FMS)
1338 //===----------------------------------------------------------------------===//
1340 multiclass SIMDFM<Vec vec, bits<32> simdopA, bits<32> simdopS> {
1342 RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins),
1343 [(set (vec.vt V128:$dst), (int_wasm_fma
1344 (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))],
1345 vec.prefix#".fma\t$dst, $a, $b, $c", vec.prefix#".fma", simdopA>;
1347 RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins),
1348 [(set (vec.vt V128:$dst), (int_wasm_fms
1349 (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))],
1350 vec.prefix#".fms\t$dst, $a, $b, $c", vec.prefix#".fms", simdopS>;
1353 defm "" : SIMDFM<F32x4, 0xaf, 0xb0>;
1354 defm "" : SIMDFM<F64x2, 0xcf, 0xd0>;
1356 //===----------------------------------------------------------------------===//
1358 //===----------------------------------------------------------------------===//
1360 multiclass SIMDLANESELECT<Vec vec, bits<32> op> {
1361 defm LANESELECT_#vec :
1362 RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins),
1363 [(set (vec.vt V128:$dst), (int_wasm_laneselect
1364 (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))],
1365 vec.prefix#".laneselect\t$dst, $a, $b, $c", vec.prefix#".laneselect", op>;
1368 defm "" : SIMDLANESELECT<I8x16, 0xb2>;
1369 defm "" : SIMDLANESELECT<I16x8, 0xb3>;
1370 defm "" : SIMDLANESELECT<I32x4, 0xd2>;
1371 defm "" : SIMDLANESELECT<I64x2, 0xd3>;
1374 //===----------------------------------------------------------------------===//
1376 //===----------------------------------------------------------------------===//
1378 defm RELAXED_SWIZZLE :
1379 RELAXED_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins),
1380 [(set (v16i8 V128:$dst),
1381 (int_wasm_relaxed_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))],
1382 "i8x16.relaxed_swizzle\t$dst, $src, $mask", "i8x16.relaxed_swizzle", 162>;
1384 //===----------------------------------------------------------------------===//
1385 // Relaxed floating-point min and max.
1386 //===----------------------------------------------------------------------===//
1388 multiclass SIMD_RELAXED_FMINMAX<Vec vec, bits<32> simdopMin, bits<32> simdopMax> {
1389 defm RELAXED_FMIN_#vec :
1390 RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b), (outs), (ins),
1391 [(set (vec.vt V128:$dst), (int_wasm_relaxed_min
1392 (vec.vt V128:$a), (vec.vt V128:$b)))],
1393 vec.prefix#".relaxed_min\t$dst, $a, $b", vec.prefix#".relaxed_min", simdopMin>;
1394 defm RELAXED_FMAX_#vec :
1395 RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b), (outs), (ins),
1396 [(set (vec.vt V128:$dst), (int_wasm_relaxed_max
1397 (vec.vt V128:$a), (vec.vt V128:$b)))],
1398 vec.prefix#".relaxed_max\t$dst, $a, $b", vec.prefix#".relaxed_max", simdopMax>;
1401 defm "" : SIMD_RELAXED_FMINMAX<F32x4, 0xb4, 0xe2>;
1402 defm "" : SIMD_RELAXED_FMINMAX<F64x2, 0xd4, 0xee>;
1404 //===----------------------------------------------------------------------===//
1405 // Relaxed floating-point to int conversions
1406 //===----------------------------------------------------------------------===//
1408 multiclass SIMD_RELAXED_CONVERT<Vec vec, Vec arg, SDPatternOperator op, string name, bits<32> simdop> {
1410 RELAXED_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins),
1411 [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))],
1412 vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>;
1415 defm "" : SIMD_RELAXED_CONVERT<I32x4, F32x4, int_wasm_relaxed_trunc_signed, "relaxed_trunc_f32x4_s", 0xa5>;
1416 defm "" : SIMD_RELAXED_CONVERT<I32x4, F32x4, int_wasm_relaxed_trunc_unsigned, "relaxed_trunc_f32x4_u", 0xa6>;
1418 defm "" : SIMD_RELAXED_CONVERT<I32x4, F64x2, int_wasm_relaxed_trunc_zero_signed, "relaxed_trunc_f64x2_s_zero", 0xc5>;
1419 defm "" : SIMD_RELAXED_CONVERT<I32x4, F64x2, int_wasm_relaxed_trunc_zero_unsigned, "relaxed_trunc_f64x2_u_zero", 0xc6>;