10b57cec5SDimitry Andric// WebAssemblyInstrSIMD.td - WebAssembly SIMD codegen support -*- tablegen -*-// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric/// 90b57cec5SDimitry Andric/// \file 100b57cec5SDimitry Andric/// WebAssembly SIMD operand code-gen constructs. 110b57cec5SDimitry Andric/// 120b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 14349cc55cSDimitry Andric// Instructions using the SIMD opcode prefix and requiring one of the SIMD 15349cc55cSDimitry Andric// feature predicates. 16349cc55cSDimitry Andricmulticlass ABSTRACT_SIMD_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, 17349cc55cSDimitry Andric list<dag> pattern_r, string asmstr_r, 18349cc55cSDimitry Andric string asmstr_s, bits<32> simdop, 19349cc55cSDimitry Andric Predicate simd_level> { 200b57cec5SDimitry Andric defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s, 21e8d8bef9SDimitry Andric !if(!ge(simdop, 0x100), 22e8d8bef9SDimitry Andric !or(0xfd0000, !and(0xffff, simdop)), 23e8d8bef9SDimitry Andric !or(0xfd00, !and(0xff, simdop)))>, 24349cc55cSDimitry Andric Requires<[simd_level]>; 250b57cec5SDimitry Andric} 260b57cec5SDimitry Andric 27349cc55cSDimitry Andricmulticlass SIMD_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, 28349cc55cSDimitry Andric list<dag> pattern_r, string asmstr_r = "", 29349cc55cSDimitry Andric string asmstr_s = "", bits<32> simdop = -1> { 30349cc55cSDimitry Andric defm "" : ABSTRACT_SIMD_I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, 31349cc55cSDimitry Andric asmstr_s, simdop, HasSIMD128>; 32349cc55cSDimitry Andric} 33349cc55cSDimitry Andric 34349cc55cSDimitry Andricmulticlass RELAXED_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, 35349cc55cSDimitry Andric list<dag> pattern_r, string asmstr_r = "", 36349cc55cSDimitry Andric string asmstr_s = "", bits<32> simdop = -1> { 37349cc55cSDimitry Andric defm "" : ABSTRACT_SIMD_I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, 38349cc55cSDimitry Andric asmstr_s, simdop, HasRelaxedSIMD>; 39349cc55cSDimitry Andric} 40349cc55cSDimitry Andric 41349cc55cSDimitry Andric 420b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v16i8>; 430b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v8i16>; 440b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v4i32>; 450b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v2i64>; 460b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v4f32>; 470b57cec5SDimitry Andricdefm "" : ARGUMENT<V128, v2f64>; 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric// Constrained immediate argument types 500b57cec5SDimitry Andricforeach SIZE = [8, 16] in 510b57cec5SDimitry Andricdef ImmI#SIZE : ImmLeaf<i32, 520b57cec5SDimitry Andric "return -(1 << ("#SIZE#" - 1)) <= Imm && Imm < (1 << ("#SIZE#" - 1));" 530b57cec5SDimitry Andric>; 540b57cec5SDimitry Andricforeach SIZE = [2, 4, 8, 16, 32] in 550b57cec5SDimitry Andricdef LaneIdx#SIZE : ImmLeaf<i32, "return 0 <= Imm && Imm < "#SIZE#";">; 560b57cec5SDimitry Andric 57e8d8bef9SDimitry Andricclass Vec { 58e8d8bef9SDimitry Andric ValueType vt; 59e8d8bef9SDimitry Andric ValueType int_vt; 60e8d8bef9SDimitry Andric ValueType lane_vt; 61e8d8bef9SDimitry Andric WebAssemblyRegClass lane_rc; 62e8d8bef9SDimitry Andric int lane_bits; 63e8d8bef9SDimitry Andric ImmLeaf lane_idx; 64*bdd1243dSDimitry Andric SDPatternOperator lane_load; 65e8d8bef9SDimitry Andric PatFrag splat; 66e8d8bef9SDimitry Andric string prefix; 67e8d8bef9SDimitry Andric Vec split; 68e8d8bef9SDimitry Andric} 69e8d8bef9SDimitry Andric 70e8d8bef9SDimitry Andricdef I8x16 : Vec { 71e8d8bef9SDimitry Andric let vt = v16i8; 72e8d8bef9SDimitry Andric let int_vt = vt; 73e8d8bef9SDimitry Andric let lane_vt = i32; 74e8d8bef9SDimitry Andric let lane_rc = I32; 75e8d8bef9SDimitry Andric let lane_bits = 8; 76e8d8bef9SDimitry Andric let lane_idx = LaneIdx16; 77*bdd1243dSDimitry Andric let lane_load = extloadi8; 78*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v16i8 (splat_vector (i8 $x)))>; 79e8d8bef9SDimitry Andric let prefix = "i8x16"; 80e8d8bef9SDimitry Andric} 81e8d8bef9SDimitry Andric 82e8d8bef9SDimitry Andricdef I16x8 : Vec { 83e8d8bef9SDimitry Andric let vt = v8i16; 84e8d8bef9SDimitry Andric let int_vt = vt; 85e8d8bef9SDimitry Andric let lane_vt = i32; 86e8d8bef9SDimitry Andric let lane_rc = I32; 87e8d8bef9SDimitry Andric let lane_bits = 16; 88e8d8bef9SDimitry Andric let lane_idx = LaneIdx8; 89*bdd1243dSDimitry Andric let lane_load = extloadi16; 90*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v8i16 (splat_vector (i16 $x)))>; 91e8d8bef9SDimitry Andric let prefix = "i16x8"; 92e8d8bef9SDimitry Andric let split = I8x16; 93e8d8bef9SDimitry Andric} 94e8d8bef9SDimitry Andric 95e8d8bef9SDimitry Andricdef I32x4 : Vec { 96e8d8bef9SDimitry Andric let vt = v4i32; 97e8d8bef9SDimitry Andric let int_vt = vt; 98e8d8bef9SDimitry Andric let lane_vt = i32; 99e8d8bef9SDimitry Andric let lane_rc = I32; 100e8d8bef9SDimitry Andric let lane_bits = 32; 101e8d8bef9SDimitry Andric let lane_idx = LaneIdx4; 102*bdd1243dSDimitry Andric let lane_load = load; 103*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v4i32 (splat_vector (i32 $x)))>; 104e8d8bef9SDimitry Andric let prefix = "i32x4"; 105e8d8bef9SDimitry Andric let split = I16x8; 106e8d8bef9SDimitry Andric} 107e8d8bef9SDimitry Andric 108e8d8bef9SDimitry Andricdef I64x2 : Vec { 109e8d8bef9SDimitry Andric let vt = v2i64; 110e8d8bef9SDimitry Andric let int_vt = vt; 111e8d8bef9SDimitry Andric let lane_vt = i64; 112e8d8bef9SDimitry Andric let lane_rc = I64; 113e8d8bef9SDimitry Andric let lane_bits = 64; 114e8d8bef9SDimitry Andric let lane_idx = LaneIdx2; 115*bdd1243dSDimitry Andric let lane_load = load; 116*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v2i64 (splat_vector (i64 $x)))>; 117e8d8bef9SDimitry Andric let prefix = "i64x2"; 118e8d8bef9SDimitry Andric let split = I32x4; 119e8d8bef9SDimitry Andric} 120e8d8bef9SDimitry Andric 121e8d8bef9SDimitry Andricdef F32x4 : Vec { 122e8d8bef9SDimitry Andric let vt = v4f32; 123e8d8bef9SDimitry Andric let int_vt = v4i32; 124e8d8bef9SDimitry Andric let lane_vt = f32; 125e8d8bef9SDimitry Andric let lane_rc = F32; 126e8d8bef9SDimitry Andric let lane_bits = 32; 127e8d8bef9SDimitry Andric let lane_idx = LaneIdx4; 128*bdd1243dSDimitry Andric let lane_load = load; 129*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v4f32 (splat_vector (f32 $x)))>; 130e8d8bef9SDimitry Andric let prefix = "f32x4"; 131e8d8bef9SDimitry Andric} 132e8d8bef9SDimitry Andric 133e8d8bef9SDimitry Andricdef F64x2 : Vec { 134e8d8bef9SDimitry Andric let vt = v2f64; 135e8d8bef9SDimitry Andric let int_vt = v2i64; 136e8d8bef9SDimitry Andric let lane_vt = f64; 137e8d8bef9SDimitry Andric let lane_rc = F64; 138e8d8bef9SDimitry Andric let lane_bits = 64; 139e8d8bef9SDimitry Andric let lane_idx = LaneIdx2; 140*bdd1243dSDimitry Andric let lane_load = load; 141*bdd1243dSDimitry Andric let splat = PatFrag<(ops node:$x), (v2f64 (splat_vector (f64 $x)))>; 142e8d8bef9SDimitry Andric let prefix = "f64x2"; 143e8d8bef9SDimitry Andric} 144e8d8bef9SDimitry Andric 145e8d8bef9SDimitry Andricdefvar AllVecs = [I8x16, I16x8, I32x4, I64x2, F32x4, F64x2]; 146e8d8bef9SDimitry Andricdefvar IntVecs = [I8x16, I16x8, I32x4, I64x2]; 147e8d8bef9SDimitry Andric 1480b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1490b57cec5SDimitry Andric// Load and store 1500b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric// Load: v128.load 1535ffd83dbSDimitry Andriclet mayLoad = 1, UseNamedOperandTable = 1 in { 1545ffd83dbSDimitry Andricdefm LOAD_V128_A32 : 1550b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), (ins P2Align:$p2align, offset32_op:$off, I32:$addr), 1560b57cec5SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off), [], 1570b57cec5SDimitry Andric "v128.load\t$dst, ${off}(${addr})$p2align", 1580b57cec5SDimitry Andric "v128.load\t$off$p2align", 0>; 1595ffd83dbSDimitry Andricdefm LOAD_V128_A64 : 1605ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), (ins P2Align:$p2align, offset64_op:$off, I64:$addr), 1615ffd83dbSDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off), [], 1625ffd83dbSDimitry Andric "v128.load\t$dst, ${off}(${addr})$p2align", 1635ffd83dbSDimitry Andric "v128.load\t$off$p2align", 0>; 1645ffd83dbSDimitry Andric} 1650b57cec5SDimitry Andric 166e8d8bef9SDimitry Andric// Def load patterns from WebAssemblyInstrMemory.td for vector types 167e8d8bef9SDimitry Andricforeach vec = AllVecs in { 168*bdd1243dSDimitry Andricdefm : LoadPat<vec.vt, load, "LOAD_V128">; 1690b57cec5SDimitry Andric} 1700b57cec5SDimitry Andric 171e8d8bef9SDimitry Andric// v128.loadX_splat 172e8d8bef9SDimitry Andricmulticlass SIMDLoadSplat<int size, bits<32> simdop> { 1735ffd83dbSDimitry Andric let mayLoad = 1, UseNamedOperandTable = 1 in { 174e8d8bef9SDimitry Andric defm LOAD#size#_SPLAT_A32 : 1755ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 1765ffd83dbSDimitry Andric (ins P2Align:$p2align, offset32_op:$off, I32:$addr), 1775ffd83dbSDimitry Andric (outs), 1785ffd83dbSDimitry Andric (ins P2Align:$p2align, offset32_op:$off), [], 179e8d8bef9SDimitry Andric "v128.load"#size#"_splat\t$dst, ${off}(${addr})$p2align", 180e8d8bef9SDimitry Andric "v128.load"#size#"_splat\t$off$p2align", simdop>; 181e8d8bef9SDimitry Andric defm LOAD#size#_SPLAT_A64 : 1825ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 1835ffd83dbSDimitry Andric (ins P2Align:$p2align, offset64_op:$off, I64:$addr), 1845ffd83dbSDimitry Andric (outs), 1855ffd83dbSDimitry Andric (ins P2Align:$p2align, offset64_op:$off), [], 186e8d8bef9SDimitry Andric "v128.load"#size#"_splat\t$dst, ${off}(${addr})$p2align", 187e8d8bef9SDimitry Andric "v128.load"#size#"_splat\t$off$p2align", simdop>; 1888bcb0991SDimitry Andric } 1895ffd83dbSDimitry Andric} 1908bcb0991SDimitry Andric 191e8d8bef9SDimitry Andricdefm "" : SIMDLoadSplat<8, 7>; 192e8d8bef9SDimitry Andricdefm "" : SIMDLoadSplat<16, 8>; 193e8d8bef9SDimitry Andricdefm "" : SIMDLoadSplat<32, 9>; 194e8d8bef9SDimitry Andricdefm "" : SIMDLoadSplat<64, 10>; 1958bcb0991SDimitry Andric 196e8d8bef9SDimitry Andricforeach vec = AllVecs in { 197e8d8bef9SDimitry Andric defvar inst = "LOAD"#vec.lane_bits#"_SPLAT"; 198*bdd1243dSDimitry Andric defm : LoadPat<vec.vt, 199*bdd1243dSDimitry Andric PatFrag<(ops node:$addr), (splat_vector (vec.lane_vt (vec.lane_load node:$addr)))>, 200*bdd1243dSDimitry Andric inst>; 2018bcb0991SDimitry Andric} 2028bcb0991SDimitry Andric 2038bcb0991SDimitry Andric// Load and extend 204e8d8bef9SDimitry Andricmulticlass SIMDLoadExtend<Vec vec, string loadPat, bits<32> simdop> { 205e8d8bef9SDimitry Andric defvar signed = vec.prefix#".load"#loadPat#"_s"; 206e8d8bef9SDimitry Andric defvar unsigned = vec.prefix#".load"#loadPat#"_u"; 2075ffd83dbSDimitry Andric let mayLoad = 1, UseNamedOperandTable = 1 in { 208e8d8bef9SDimitry Andric defm LOAD_EXTEND_S_#vec#_A32 : 2095ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 2105ffd83dbSDimitry Andric (ins P2Align:$p2align, offset32_op:$off, I32:$addr), 2118bcb0991SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off), [], 212e8d8bef9SDimitry Andric signed#"\t$dst, ${off}(${addr})$p2align", 213e8d8bef9SDimitry Andric signed#"\t$off$p2align", simdop>; 214e8d8bef9SDimitry Andric defm LOAD_EXTEND_U_#vec#_A32 : 2155ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 2165ffd83dbSDimitry Andric (ins P2Align:$p2align, offset32_op:$off, I32:$addr), 2178bcb0991SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off), [], 218e8d8bef9SDimitry Andric unsigned#"\t$dst, ${off}(${addr})$p2align", 219e8d8bef9SDimitry Andric unsigned#"\t$off$p2align", !add(simdop, 1)>; 220e8d8bef9SDimitry Andric defm LOAD_EXTEND_S_#vec#_A64 : 2215ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 2225ffd83dbSDimitry Andric (ins P2Align:$p2align, offset64_op:$off, I64:$addr), 2235ffd83dbSDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off), [], 224e8d8bef9SDimitry Andric signed#"\t$dst, ${off}(${addr})$p2align", 225e8d8bef9SDimitry Andric signed#"\t$off$p2align", simdop>; 226e8d8bef9SDimitry Andric defm LOAD_EXTEND_U_#vec#_A64 : 2275ffd83dbSDimitry Andric SIMD_I<(outs V128:$dst), 2285ffd83dbSDimitry Andric (ins P2Align:$p2align, offset64_op:$off, I64:$addr), 2295ffd83dbSDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off), [], 230e8d8bef9SDimitry Andric unsigned#"\t$dst, ${off}(${addr})$p2align", 231e8d8bef9SDimitry Andric unsigned#"\t$off$p2align", !add(simdop, 1)>; 2328bcb0991SDimitry Andric } 2338bcb0991SDimitry Andric} 2348bcb0991SDimitry Andric 235e8d8bef9SDimitry Andricdefm "" : SIMDLoadExtend<I16x8, "8x8", 1>; 236e8d8bef9SDimitry Andricdefm "" : SIMDLoadExtend<I32x4, "16x4", 3>; 237e8d8bef9SDimitry Andricdefm "" : SIMDLoadExtend<I64x2, "32x2", 5>; 2388bcb0991SDimitry Andric 239e8d8bef9SDimitry Andricforeach vec = [I16x8, I32x4, I64x2] in 240e8d8bef9SDimitry Andricforeach exts = [["sextloadvi", "_S"], 241e8d8bef9SDimitry Andric ["zextloadvi", "_U"], 242e8d8bef9SDimitry Andric ["extloadvi", "_U"]] in { 243e8d8bef9SDimitry Andricdefvar loadpat = !cast<PatFrag>(exts[0]#vec.split.lane_bits); 244e8d8bef9SDimitry Andricdefvar inst = "LOAD_EXTEND"#exts[1]#"_"#vec; 245*bdd1243dSDimitry Andricdefm : LoadPat<vec.vt, loadpat, inst>; 2468bcb0991SDimitry Andric} 2478bcb0991SDimitry Andric 248e8d8bef9SDimitry Andric// Load lane into zero vector 249e8d8bef9SDimitry Andricmulticlass SIMDLoadZero<Vec vec, bits<32> simdop> { 250e8d8bef9SDimitry Andric defvar name = "v128.load"#vec.lane_bits#"_zero"; 251e8d8bef9SDimitry Andric let mayLoad = 1, UseNamedOperandTable = 1 in { 252e8d8bef9SDimitry Andric defm LOAD_ZERO_#vec#_A32 : 253e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), 254e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset32_op:$off, I32:$addr), 255e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off), [], 256e8d8bef9SDimitry Andric name#"\t$dst, ${off}(${addr})$p2align", 257e8d8bef9SDimitry Andric name#"\t$off$p2align", simdop>; 258e8d8bef9SDimitry Andric defm LOAD_ZERO_#vec#_A64 : 259e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), 260e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset64_op:$off, I64:$addr), 261e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off), [], 262e8d8bef9SDimitry Andric name#"\t$dst, ${off}(${addr})$p2align", 263e8d8bef9SDimitry Andric name#"\t$off$p2align", simdop>; 264e8d8bef9SDimitry Andric } // mayLoad = 1, UseNamedOperandTable = 1 265e8d8bef9SDimitry Andric} 266e8d8bef9SDimitry Andric 267fe6060f1SDimitry Andricdefm "" : SIMDLoadZero<I32x4, 0x5c>; 268fe6060f1SDimitry Andricdefm "" : SIMDLoadZero<I64x2, 0x5d>; 269e8d8bef9SDimitry Andric 270349cc55cSDimitry Andric// Use load_zero to load scalars into vectors as well where possible. 271*bdd1243dSDimitry Andric// TODO: i16, and i8 scalars 272*bdd1243dSDimitry Andricforeach vec = [I32x4, I64x2] in { 273*bdd1243dSDimitry Andric defvar inst = "LOAD_ZERO_"#vec; 274*bdd1243dSDimitry Andric defvar pat = PatFrag<(ops node:$addr), (scalar_to_vector (vec.lane_vt (load $addr)))>; 275*bdd1243dSDimitry Andric defm : LoadPat<vec.vt, pat, inst>; 276*bdd1243dSDimitry Andric} 277349cc55cSDimitry Andric 278fe6060f1SDimitry Andric// TODO: f32x4 and f64x2 as well 279e8d8bef9SDimitry Andricforeach vec = [I32x4, I64x2] in { 280e8d8bef9SDimitry Andric defvar inst = "LOAD_ZERO_"#vec; 281fe6060f1SDimitry Andric defvar pat = PatFrag<(ops node:$ptr), 282fe6060f1SDimitry Andric (vector_insert (vec.splat (vec.lane_vt 0)), (vec.lane_vt (load $ptr)), 0)>; 283*bdd1243dSDimitry Andric defm : LoadPat<vec.vt, pat, inst>; 284e8d8bef9SDimitry Andric} 285e8d8bef9SDimitry Andric 286e8d8bef9SDimitry Andric// Load lane 287e8d8bef9SDimitry Andricmulticlass SIMDLoadLane<Vec vec, bits<32> simdop> { 288e8d8bef9SDimitry Andric defvar name = "v128.load"#vec.lane_bits#"_lane"; 289e8d8bef9SDimitry Andric let mayLoad = 1, UseNamedOperandTable = 1 in { 290e8d8bef9SDimitry Andric defm LOAD_LANE_#vec#_A32 : 291e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), 292e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx, 293e8d8bef9SDimitry Andric I32:$addr, V128:$vec), 294e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx), 295e8d8bef9SDimitry Andric [], name#"\t$dst, ${off}(${addr})$p2align, $vec, $idx", 296e8d8bef9SDimitry Andric name#"\t$off$p2align, $idx", simdop>; 297e8d8bef9SDimitry Andric defm LOAD_LANE_#vec#_A64 : 298e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), 299e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx, 300e8d8bef9SDimitry Andric I64:$addr, V128:$vec), 301e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx), 302e8d8bef9SDimitry Andric [], name#"\t$dst, ${off}(${addr})$p2align, $vec, $idx", 303e8d8bef9SDimitry Andric name#"\t$off$p2align, $idx", simdop>; 304e8d8bef9SDimitry Andric } // mayLoad = 1, UseNamedOperandTable = 1 305e8d8bef9SDimitry Andric} 306e8d8bef9SDimitry Andric 307fe6060f1SDimitry Andricdefm "" : SIMDLoadLane<I8x16, 0x54>; 308fe6060f1SDimitry Andricdefm "" : SIMDLoadLane<I16x8, 0x55>; 309fe6060f1SDimitry Andricdefm "" : SIMDLoadLane<I32x4, 0x56>; 310fe6060f1SDimitry Andricdefm "" : SIMDLoadLane<I64x2, 0x57>; 311e8d8bef9SDimitry Andric 312e8d8bef9SDimitry Andric// Select loads with no constant offset. 313fe6060f1SDimitry Andricmulticlass LoadLanePatNoOffset<Vec vec, SDPatternOperator kind> { 314e8d8bef9SDimitry Andric defvar load_lane_a32 = !cast<NI>("LOAD_LANE_"#vec#"_A32"); 315e8d8bef9SDimitry Andric defvar load_lane_a64 = !cast<NI>("LOAD_LANE_"#vec#"_A64"); 316e8d8bef9SDimitry Andric def : Pat<(vec.vt (kind (i32 I32:$addr), 317e8d8bef9SDimitry Andric (vec.vt V128:$vec), (i32 vec.lane_idx:$idx))), 318e8d8bef9SDimitry Andric (load_lane_a32 0, 0, imm:$idx, $addr, $vec)>, 319e8d8bef9SDimitry Andric Requires<[HasAddr32]>; 320e8d8bef9SDimitry Andric def : Pat<(vec.vt (kind (i64 I64:$addr), 321e8d8bef9SDimitry Andric (vec.vt V128:$vec), (i32 vec.lane_idx:$idx))), 322e8d8bef9SDimitry Andric (load_lane_a64 0, 0, imm:$idx, $addr, $vec)>, 323e8d8bef9SDimitry Andric Requires<[HasAddr64]>; 324e8d8bef9SDimitry Andric} 325e8d8bef9SDimitry Andric 326fe6060f1SDimitry Andricdef load8_lane : 327fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 328fe6060f1SDimitry Andric (vector_insert $vec, (i32 (extloadi8 $ptr)), $idx)>; 329fe6060f1SDimitry Andricdef load16_lane : 330fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 331fe6060f1SDimitry Andric (vector_insert $vec, (i32 (extloadi16 $ptr)), $idx)>; 332fe6060f1SDimitry Andricdef load32_lane : 333fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 334fe6060f1SDimitry Andric (vector_insert $vec, (i32 (load $ptr)), $idx)>; 335fe6060f1SDimitry Andricdef load64_lane : 336fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 337fe6060f1SDimitry Andric (vector_insert $vec, (i64 (load $ptr)), $idx)>; 338fe6060f1SDimitry Andric// TODO: floating point lanes as well 339fe6060f1SDimitry Andric 340fe6060f1SDimitry Andricdefm : LoadLanePatNoOffset<I8x16, load8_lane>; 341fe6060f1SDimitry Andricdefm : LoadLanePatNoOffset<I16x8, load16_lane>; 342fe6060f1SDimitry Andricdefm : LoadLanePatNoOffset<I32x4, load32_lane>; 343fe6060f1SDimitry Andricdefm : LoadLanePatNoOffset<I64x2, load64_lane>; 344e8d8bef9SDimitry Andric 345e8d8bef9SDimitry Andric// TODO: Also support the other load patterns for load_lane once the instructions 346e8d8bef9SDimitry Andric// are merged to the proposal. 3478bcb0991SDimitry Andric 3480b57cec5SDimitry Andric// Store: v128.store 3495ffd83dbSDimitry Andriclet mayStore = 1, UseNamedOperandTable = 1 in { 3505ffd83dbSDimitry Andricdefm STORE_V128_A32 : 3510b57cec5SDimitry Andric SIMD_I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, V128:$vec), 3520b57cec5SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off), [], 3530b57cec5SDimitry Andric "v128.store\t${off}(${addr})$p2align, $vec", 3545ffd83dbSDimitry Andric "v128.store\t$off$p2align", 11>; 3555ffd83dbSDimitry Andricdefm STORE_V128_A64 : 3565ffd83dbSDimitry Andric SIMD_I<(outs), (ins P2Align:$p2align, offset64_op:$off, I64:$addr, V128:$vec), 3575ffd83dbSDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off), [], 3585ffd83dbSDimitry Andric "v128.store\t${off}(${addr})$p2align, $vec", 3595ffd83dbSDimitry Andric "v128.store\t$off$p2align", 11>; 3605ffd83dbSDimitry Andric} 361e8d8bef9SDimitry Andric 362e8d8bef9SDimitry Andric// Def store patterns from WebAssemblyInstrMemory.td for vector types 363e8d8bef9SDimitry Andricforeach vec = AllVecs in { 364*bdd1243dSDimitry Andricdefm : StorePat<vec.vt, store, "STORE_V128">; 3650b57cec5SDimitry Andric} 3660b57cec5SDimitry Andric 367e8d8bef9SDimitry Andric// Store lane 368e8d8bef9SDimitry Andricmulticlass SIMDStoreLane<Vec vec, bits<32> simdop> { 369e8d8bef9SDimitry Andric defvar name = "v128.store"#vec.lane_bits#"_lane"; 370e8d8bef9SDimitry Andric let mayStore = 1, UseNamedOperandTable = 1 in { 371e8d8bef9SDimitry Andric defm STORE_LANE_#vec#_A32 : 372e8d8bef9SDimitry Andric SIMD_I<(outs), 373e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx, 374e8d8bef9SDimitry Andric I32:$addr, V128:$vec), 375e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset32_op:$off, vec_i8imm_op:$idx), 376e8d8bef9SDimitry Andric [], name#"\t${off}(${addr})$p2align, $vec, $idx", 377e8d8bef9SDimitry Andric name#"\t$off$p2align, $idx", simdop>; 378e8d8bef9SDimitry Andric defm STORE_LANE_#vec#_A64 : 379e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), 380e8d8bef9SDimitry Andric (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx, 381e8d8bef9SDimitry Andric I64:$addr, V128:$vec), 382e8d8bef9SDimitry Andric (outs), (ins P2Align:$p2align, offset64_op:$off, vec_i8imm_op:$idx), 383e8d8bef9SDimitry Andric [], name#"\t${off}(${addr})$p2align, $vec, $idx", 384e8d8bef9SDimitry Andric name#"\t$off$p2align, $idx", simdop>; 385e8d8bef9SDimitry Andric } // mayStore = 1, UseNamedOperandTable = 1 386e8d8bef9SDimitry Andric} 387e8d8bef9SDimitry Andric 388fe6060f1SDimitry Andricdefm "" : SIMDStoreLane<I8x16, 0x58>; 389fe6060f1SDimitry Andricdefm "" : SIMDStoreLane<I16x8, 0x59>; 390fe6060f1SDimitry Andricdefm "" : SIMDStoreLane<I32x4, 0x5a>; 391fe6060f1SDimitry Andricdefm "" : SIMDStoreLane<I64x2, 0x5b>; 392e8d8bef9SDimitry Andric 393*bdd1243dSDimitry Andricmulticlass StoreLanePat<Vec vec, SDPatternOperator kind> { 394*bdd1243dSDimitry Andric def : Pat<(kind (AddrOps32 offset32_op:$offset, I32:$addr), 395*bdd1243dSDimitry Andric (vec.vt V128:$vec), 396*bdd1243dSDimitry Andric (i32 vec.lane_idx:$idx)), 397*bdd1243dSDimitry Andric (!cast<NI>("STORE_LANE_"#vec#"_A32") 0, $offset, imm:$idx, $addr, $vec)>, 398e8d8bef9SDimitry Andric Requires<[HasAddr32]>; 399*bdd1243dSDimitry Andric def : Pat<(kind (AddrOps64 offset64_op:$offset, I64:$addr), 400*bdd1243dSDimitry Andric (vec.vt V128:$vec), 401*bdd1243dSDimitry Andric (i32 vec.lane_idx:$idx)), 402*bdd1243dSDimitry Andric (!cast<NI>("STORE_LANE_"#vec#"_A64") 0, $offset, imm:$idx, $addr, $vec)>, 403e8d8bef9SDimitry Andric Requires<[HasAddr64]>; 404e8d8bef9SDimitry Andric} 405e8d8bef9SDimitry Andric 406fe6060f1SDimitry Andricdef store8_lane : 407fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 408fe6060f1SDimitry Andric (truncstorei8 (i32 (vector_extract $vec, $idx)), $ptr)>; 409fe6060f1SDimitry Andricdef store16_lane : 410fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 411fe6060f1SDimitry Andric (truncstorei16 (i32 (vector_extract $vec, $idx)), $ptr)>; 412fe6060f1SDimitry Andricdef store32_lane : 413fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 414fe6060f1SDimitry Andric (store (i32 (vector_extract $vec, $idx)), $ptr)>; 415fe6060f1SDimitry Andricdef store64_lane : 416fe6060f1SDimitry Andric PatFrag<(ops node:$ptr, node:$vec, node:$idx), 417fe6060f1SDimitry Andric (store (i64 (vector_extract $vec, $idx)), $ptr)>; 418fe6060f1SDimitry Andric// TODO: floating point lanes as well 419e8d8bef9SDimitry Andric 420fe6060f1SDimitry Andriclet AddedComplexity = 1 in { 421*bdd1243dSDimitry Andricdefm : StoreLanePat<I8x16, store8_lane>; 422*bdd1243dSDimitry Andricdefm : StoreLanePat<I16x8, store16_lane>; 423*bdd1243dSDimitry Andricdefm : StoreLanePat<I32x4, store32_lane>; 424*bdd1243dSDimitry Andricdefm : StoreLanePat<I64x2, store64_lane>; 425fe6060f1SDimitry Andric} 426e8d8bef9SDimitry Andric 4270b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4280b57cec5SDimitry Andric// Constructing SIMD values 4290b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4300b57cec5SDimitry Andric 4310b57cec5SDimitry Andric// Constant: v128.const 432e8d8bef9SDimitry Andricmulticlass ConstVec<Vec vec, dag ops, dag pat, string args> { 433fe6060f1SDimitry Andric let isMoveImm = 1, isReMaterializable = 1 in 434e8d8bef9SDimitry Andric defm CONST_V128_#vec : SIMD_I<(outs V128:$dst), ops, (outs), ops, 435e8d8bef9SDimitry Andric [(set V128:$dst, (vec.vt pat))], 4360b57cec5SDimitry Andric "v128.const\t$dst, "#args, 4375ffd83dbSDimitry Andric "v128.const\t"#args, 12>; 4380b57cec5SDimitry Andric} 4390b57cec5SDimitry Andric 440e8d8bef9SDimitry Andricdefm "" : ConstVec<I8x16, 4410b57cec5SDimitry Andric (ins vec_i8imm_op:$i0, vec_i8imm_op:$i1, 4420b57cec5SDimitry Andric vec_i8imm_op:$i2, vec_i8imm_op:$i3, 4430b57cec5SDimitry Andric vec_i8imm_op:$i4, vec_i8imm_op:$i5, 4440b57cec5SDimitry Andric vec_i8imm_op:$i6, vec_i8imm_op:$i7, 4450b57cec5SDimitry Andric vec_i8imm_op:$i8, vec_i8imm_op:$i9, 4460b57cec5SDimitry Andric vec_i8imm_op:$iA, vec_i8imm_op:$iB, 4470b57cec5SDimitry Andric vec_i8imm_op:$iC, vec_i8imm_op:$iD, 4480b57cec5SDimitry Andric vec_i8imm_op:$iE, vec_i8imm_op:$iF), 4490b57cec5SDimitry Andric (build_vector ImmI8:$i0, ImmI8:$i1, ImmI8:$i2, ImmI8:$i3, 4500b57cec5SDimitry Andric ImmI8:$i4, ImmI8:$i5, ImmI8:$i6, ImmI8:$i7, 4510b57cec5SDimitry Andric ImmI8:$i8, ImmI8:$i9, ImmI8:$iA, ImmI8:$iB, 4520b57cec5SDimitry Andric ImmI8:$iC, ImmI8:$iD, ImmI8:$iE, ImmI8:$iF), 4530b57cec5SDimitry Andric !strconcat("$i0, $i1, $i2, $i3, $i4, $i5, $i6, $i7, ", 4540b57cec5SDimitry Andric "$i8, $i9, $iA, $iB, $iC, $iD, $iE, $iF")>; 455e8d8bef9SDimitry Andricdefm "" : ConstVec<I16x8, 4560b57cec5SDimitry Andric (ins vec_i16imm_op:$i0, vec_i16imm_op:$i1, 4570b57cec5SDimitry Andric vec_i16imm_op:$i2, vec_i16imm_op:$i3, 4580b57cec5SDimitry Andric vec_i16imm_op:$i4, vec_i16imm_op:$i5, 4590b57cec5SDimitry Andric vec_i16imm_op:$i6, vec_i16imm_op:$i7), 4600b57cec5SDimitry Andric (build_vector 4610b57cec5SDimitry Andric ImmI16:$i0, ImmI16:$i1, ImmI16:$i2, ImmI16:$i3, 4620b57cec5SDimitry Andric ImmI16:$i4, ImmI16:$i5, ImmI16:$i6, ImmI16:$i7), 4630b57cec5SDimitry Andric "$i0, $i1, $i2, $i3, $i4, $i5, $i6, $i7">; 4640b57cec5SDimitry Andriclet IsCanonical = 1 in 465e8d8bef9SDimitry Andricdefm "" : ConstVec<I32x4, 4660b57cec5SDimitry Andric (ins vec_i32imm_op:$i0, vec_i32imm_op:$i1, 4670b57cec5SDimitry Andric vec_i32imm_op:$i2, vec_i32imm_op:$i3), 4680b57cec5SDimitry Andric (build_vector (i32 imm:$i0), (i32 imm:$i1), 4690b57cec5SDimitry Andric (i32 imm:$i2), (i32 imm:$i3)), 4700b57cec5SDimitry Andric "$i0, $i1, $i2, $i3">; 471e8d8bef9SDimitry Andricdefm "" : ConstVec<I64x2, 4720b57cec5SDimitry Andric (ins vec_i64imm_op:$i0, vec_i64imm_op:$i1), 4730b57cec5SDimitry Andric (build_vector (i64 imm:$i0), (i64 imm:$i1)), 4740b57cec5SDimitry Andric "$i0, $i1">; 475e8d8bef9SDimitry Andricdefm "" : ConstVec<F32x4, 4760b57cec5SDimitry Andric (ins f32imm_op:$i0, f32imm_op:$i1, 4770b57cec5SDimitry Andric f32imm_op:$i2, f32imm_op:$i3), 4780b57cec5SDimitry Andric (build_vector (f32 fpimm:$i0), (f32 fpimm:$i1), 4790b57cec5SDimitry Andric (f32 fpimm:$i2), (f32 fpimm:$i3)), 4800b57cec5SDimitry Andric "$i0, $i1, $i2, $i3">; 481e8d8bef9SDimitry Andricdefm "" : ConstVec<F64x2, 4820b57cec5SDimitry Andric (ins f64imm_op:$i0, f64imm_op:$i1), 4830b57cec5SDimitry Andric (build_vector (f64 fpimm:$i0), (f64 fpimm:$i1)), 4840b57cec5SDimitry Andric "$i0, $i1">; 4850b57cec5SDimitry Andric 486*bdd1243dSDimitry Andric// Match splat(x) -> const.v128(x, ..., x) 487*bdd1243dSDimitry Andricforeach vec = AllVecs in { 488*bdd1243dSDimitry Andric defvar numEls = !div(vec.vt.Size, vec.lane_bits); 489*bdd1243dSDimitry Andric defvar isFloat = !or(!eq(vec.lane_vt, f32), !eq(vec.lane_vt, f64)); 490*bdd1243dSDimitry Andric defvar immKind = !if(isFloat, fpimm, imm); 491*bdd1243dSDimitry Andric def : Pat<(vec.splat (vec.lane_vt immKind:$x)), 492*bdd1243dSDimitry Andric !dag(!cast<NI>("CONST_V128_"#vec), 493*bdd1243dSDimitry Andric !listsplat((vec.lane_vt immKind:$x), numEls), 494*bdd1243dSDimitry Andric ?)>; 495*bdd1243dSDimitry Andric} 496*bdd1243dSDimitry Andric 4970b57cec5SDimitry Andric// Shuffle lanes: shuffle 4980b57cec5SDimitry Andricdefm SHUFFLE : 4990b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), 5000b57cec5SDimitry Andric (ins V128:$x, V128:$y, 5010b57cec5SDimitry Andric vec_i8imm_op:$m0, vec_i8imm_op:$m1, 5020b57cec5SDimitry Andric vec_i8imm_op:$m2, vec_i8imm_op:$m3, 5030b57cec5SDimitry Andric vec_i8imm_op:$m4, vec_i8imm_op:$m5, 5040b57cec5SDimitry Andric vec_i8imm_op:$m6, vec_i8imm_op:$m7, 5050b57cec5SDimitry Andric vec_i8imm_op:$m8, vec_i8imm_op:$m9, 5060b57cec5SDimitry Andric vec_i8imm_op:$mA, vec_i8imm_op:$mB, 5070b57cec5SDimitry Andric vec_i8imm_op:$mC, vec_i8imm_op:$mD, 5080b57cec5SDimitry Andric vec_i8imm_op:$mE, vec_i8imm_op:$mF), 5090b57cec5SDimitry Andric (outs), 5100b57cec5SDimitry Andric (ins 5110b57cec5SDimitry Andric vec_i8imm_op:$m0, vec_i8imm_op:$m1, 5120b57cec5SDimitry Andric vec_i8imm_op:$m2, vec_i8imm_op:$m3, 5130b57cec5SDimitry Andric vec_i8imm_op:$m4, vec_i8imm_op:$m5, 5140b57cec5SDimitry Andric vec_i8imm_op:$m6, vec_i8imm_op:$m7, 5150b57cec5SDimitry Andric vec_i8imm_op:$m8, vec_i8imm_op:$m9, 5160b57cec5SDimitry Andric vec_i8imm_op:$mA, vec_i8imm_op:$mB, 5170b57cec5SDimitry Andric vec_i8imm_op:$mC, vec_i8imm_op:$mD, 5180b57cec5SDimitry Andric vec_i8imm_op:$mE, vec_i8imm_op:$mF), 5190b57cec5SDimitry Andric [], 520e8d8bef9SDimitry Andric "i8x16.shuffle\t$dst, $x, $y, "# 5210b57cec5SDimitry Andric "$m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, "# 5220b57cec5SDimitry Andric "$m8, $m9, $mA, $mB, $mC, $mD, $mE, $mF", 523e8d8bef9SDimitry Andric "i8x16.shuffle\t"# 5240b57cec5SDimitry Andric "$m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, "# 5250b57cec5SDimitry Andric "$m8, $m9, $mA, $mB, $mC, $mD, $mE, $mF", 5265ffd83dbSDimitry Andric 13>; 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andric// Shuffles after custom lowering 5290b57cec5SDimitry Andricdef wasm_shuffle_t : SDTypeProfile<1, 18, []>; 5300b57cec5SDimitry Andricdef wasm_shuffle : SDNode<"WebAssemblyISD::SHUFFLE", wasm_shuffle_t>; 531e8d8bef9SDimitry Andricforeach vec = AllVecs in { 532e8d8bef9SDimitry Andricdef : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y), 5330b57cec5SDimitry Andric (i32 LaneIdx32:$m0), (i32 LaneIdx32:$m1), 5340b57cec5SDimitry Andric (i32 LaneIdx32:$m2), (i32 LaneIdx32:$m3), 5350b57cec5SDimitry Andric (i32 LaneIdx32:$m4), (i32 LaneIdx32:$m5), 5360b57cec5SDimitry Andric (i32 LaneIdx32:$m6), (i32 LaneIdx32:$m7), 5370b57cec5SDimitry Andric (i32 LaneIdx32:$m8), (i32 LaneIdx32:$m9), 5380b57cec5SDimitry Andric (i32 LaneIdx32:$mA), (i32 LaneIdx32:$mB), 5390b57cec5SDimitry Andric (i32 LaneIdx32:$mC), (i32 LaneIdx32:$mD), 5400b57cec5SDimitry Andric (i32 LaneIdx32:$mE), (i32 LaneIdx32:$mF))), 541e8d8bef9SDimitry Andric (SHUFFLE $x, $y, 542e8d8bef9SDimitry Andric imm:$m0, imm:$m1, imm:$m2, imm:$m3, 543e8d8bef9SDimitry Andric imm:$m4, imm:$m5, imm:$m6, imm:$m7, 544e8d8bef9SDimitry Andric imm:$m8, imm:$m9, imm:$mA, imm:$mB, 545e8d8bef9SDimitry Andric imm:$mC, imm:$mD, imm:$mE, imm:$mF)>; 5460b57cec5SDimitry Andric} 5470b57cec5SDimitry Andric 548e8d8bef9SDimitry Andric// Swizzle lanes: i8x16.swizzle 5498bcb0991SDimitry Andricdef wasm_swizzle_t : SDTypeProfile<1, 2, []>; 5508bcb0991SDimitry Andricdef wasm_swizzle : SDNode<"WebAssemblyISD::SWIZZLE", wasm_swizzle_t>; 5518bcb0991SDimitry Andricdefm SWIZZLE : 5528bcb0991SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins), 5538bcb0991SDimitry Andric [(set (v16i8 V128:$dst), 5548bcb0991SDimitry Andric (wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))], 555e8d8bef9SDimitry Andric "i8x16.swizzle\t$dst, $src, $mask", "i8x16.swizzle", 14>; 5568bcb0991SDimitry Andric 5578bcb0991SDimitry Andricdef : Pat<(int_wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)), 558e8d8bef9SDimitry Andric (SWIZZLE $src, $mask)>; 5598bcb0991SDimitry Andric 560e8d8bef9SDimitry Andricmulticlass Splat<Vec vec, bits<32> simdop> { 561e8d8bef9SDimitry Andric defm SPLAT_#vec : SIMD_I<(outs V128:$dst), (ins vec.lane_rc:$x), 562e8d8bef9SDimitry Andric (outs), (ins), 563e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 564e8d8bef9SDimitry Andric (vec.splat vec.lane_rc:$x))], 565e8d8bef9SDimitry Andric vec.prefix#".splat\t$dst, $x", vec.prefix#".splat", 566e8d8bef9SDimitry Andric simdop>; 5670b57cec5SDimitry Andric} 5680b57cec5SDimitry Andric 569e8d8bef9SDimitry Andricdefm "" : Splat<I8x16, 15>; 570e8d8bef9SDimitry Andricdefm "" : Splat<I16x8, 16>; 571e8d8bef9SDimitry Andricdefm "" : Splat<I32x4, 17>; 572e8d8bef9SDimitry Andricdefm "" : Splat<I64x2, 18>; 573e8d8bef9SDimitry Andricdefm "" : Splat<F32x4, 19>; 574e8d8bef9SDimitry Andricdefm "" : Splat<F64x2, 20>; 5750b57cec5SDimitry Andric 5760b57cec5SDimitry Andric// scalar_to_vector leaves high lanes undefined, so can be a splat 577e8d8bef9SDimitry Andricforeach vec = AllVecs in 578e8d8bef9SDimitry Andricdef : Pat<(vec.vt (scalar_to_vector (vec.lane_vt vec.lane_rc:$x))), 579e8d8bef9SDimitry Andric (!cast<Instruction>("SPLAT_"#vec) $x)>; 5800b57cec5SDimitry Andric 5810b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 5820b57cec5SDimitry Andric// Accessing lanes 5830b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 5840b57cec5SDimitry Andric 5850b57cec5SDimitry Andric// Extract lane as a scalar: extract_lane / extract_lane_s / extract_lane_u 586e8d8bef9SDimitry Andricmulticlass ExtractLane<Vec vec, bits<32> simdop, string suffix = ""> { 587e8d8bef9SDimitry Andric defm EXTRACT_LANE_#vec#suffix : 588e8d8bef9SDimitry Andric SIMD_I<(outs vec.lane_rc:$dst), (ins V128:$vec, vec_i8imm_op:$idx), 5895ffd83dbSDimitry Andric (outs), (ins vec_i8imm_op:$idx), [], 590e8d8bef9SDimitry Andric vec.prefix#".extract_lane"#suffix#"\t$dst, $vec, $idx", 591e8d8bef9SDimitry Andric vec.prefix#".extract_lane"#suffix#"\t$idx", simdop>; 5920b57cec5SDimitry Andric} 5930b57cec5SDimitry Andric 594e8d8bef9SDimitry Andricdefm "" : ExtractLane<I8x16, 21, "_s">; 595e8d8bef9SDimitry Andricdefm "" : ExtractLane<I8x16, 22, "_u">; 596e8d8bef9SDimitry Andricdefm "" : ExtractLane<I16x8, 24, "_s">; 597e8d8bef9SDimitry Andricdefm "" : ExtractLane<I16x8, 25, "_u">; 598e8d8bef9SDimitry Andricdefm "" : ExtractLane<I32x4, 27>; 599e8d8bef9SDimitry Andricdefm "" : ExtractLane<I64x2, 29>; 600e8d8bef9SDimitry Andricdefm "" : ExtractLane<F32x4, 31>; 601e8d8bef9SDimitry Andricdefm "" : ExtractLane<F64x2, 33>; 6020b57cec5SDimitry Andric 6035ffd83dbSDimitry Andricdef : Pat<(vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), 604e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>; 6055ffd83dbSDimitry Andricdef : Pat<(vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), 606e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>; 6075ffd83dbSDimitry Andricdef : Pat<(vector_extract (v4i32 V128:$vec), (i32 LaneIdx4:$idx)), 608e8d8bef9SDimitry Andric (EXTRACT_LANE_I32x4 $vec, imm:$idx)>; 6095ffd83dbSDimitry Andricdef : Pat<(vector_extract (v4f32 V128:$vec), (i32 LaneIdx4:$idx)), 610e8d8bef9SDimitry Andric (EXTRACT_LANE_F32x4 $vec, imm:$idx)>; 6115ffd83dbSDimitry Andricdef : Pat<(vector_extract (v2i64 V128:$vec), (i32 LaneIdx2:$idx)), 612e8d8bef9SDimitry Andric (EXTRACT_LANE_I64x2 $vec, imm:$idx)>; 6135ffd83dbSDimitry Andricdef : Pat<(vector_extract (v2f64 V128:$vec), (i32 LaneIdx2:$idx)), 614e8d8bef9SDimitry Andric (EXTRACT_LANE_F64x2 $vec, imm:$idx)>; 6150b57cec5SDimitry Andric 6165ffd83dbSDimitry Andricdef : Pat< 6175ffd83dbSDimitry Andric (sext_inreg (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), i8), 618e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_s $vec, imm:$idx)>; 6195ffd83dbSDimitry Andricdef : Pat< 6205ffd83dbSDimitry Andric (and (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), (i32 0xff)), 621e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>; 6225ffd83dbSDimitry Andricdef : Pat< 6235ffd83dbSDimitry Andric (sext_inreg (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), i16), 624e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_s $vec, imm:$idx)>; 6255ffd83dbSDimitry Andricdef : Pat< 6265ffd83dbSDimitry Andric (and (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), (i32 0xffff)), 627e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>; 6280b57cec5SDimitry Andric 6290b57cec5SDimitry Andric// Replace lane value: replace_lane 630e8d8bef9SDimitry Andricmulticlass ReplaceLane<Vec vec, bits<32> simdop> { 631e8d8bef9SDimitry Andric defm REPLACE_LANE_#vec : 632e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$vec, vec_i8imm_op:$idx, vec.lane_rc:$x), 6330b57cec5SDimitry Andric (outs), (ins vec_i8imm_op:$idx), 6340b57cec5SDimitry Andric [(set V128:$dst, (vector_insert 635e8d8bef9SDimitry Andric (vec.vt V128:$vec), 636e8d8bef9SDimitry Andric (vec.lane_vt vec.lane_rc:$x), 637e8d8bef9SDimitry Andric (i32 vec.lane_idx:$idx)))], 638e8d8bef9SDimitry Andric vec.prefix#".replace_lane\t$dst, $vec, $idx, $x", 639e8d8bef9SDimitry Andric vec.prefix#".replace_lane\t$idx", simdop>; 6400b57cec5SDimitry Andric} 6410b57cec5SDimitry Andric 642e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I8x16, 23>; 643e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I16x8, 26>; 644e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I32x4, 28>; 645e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I64x2, 30>; 646e8d8bef9SDimitry Andricdefm "" : ReplaceLane<F32x4, 32>; 647e8d8bef9SDimitry Andricdefm "" : ReplaceLane<F64x2, 34>; 6480b57cec5SDimitry Andric 6490b57cec5SDimitry Andric// Lower undef lane indices to zero 6500b57cec5SDimitry Andricdef : Pat<(vector_insert (v16i8 V128:$vec), I32:$x, undef), 651e8d8bef9SDimitry Andric (REPLACE_LANE_I8x16 $vec, 0, $x)>; 6520b57cec5SDimitry Andricdef : Pat<(vector_insert (v8i16 V128:$vec), I32:$x, undef), 653e8d8bef9SDimitry Andric (REPLACE_LANE_I16x8 $vec, 0, $x)>; 6540b57cec5SDimitry Andricdef : Pat<(vector_insert (v4i32 V128:$vec), I32:$x, undef), 655e8d8bef9SDimitry Andric (REPLACE_LANE_I32x4 $vec, 0, $x)>; 6560b57cec5SDimitry Andricdef : Pat<(vector_insert (v2i64 V128:$vec), I64:$x, undef), 657e8d8bef9SDimitry Andric (REPLACE_LANE_I64x2 $vec, 0, $x)>; 6580b57cec5SDimitry Andricdef : Pat<(vector_insert (v4f32 V128:$vec), F32:$x, undef), 659e8d8bef9SDimitry Andric (REPLACE_LANE_F32x4 $vec, 0, $x)>; 6600b57cec5SDimitry Andricdef : Pat<(vector_insert (v2f64 V128:$vec), F64:$x, undef), 661e8d8bef9SDimitry Andric (REPLACE_LANE_F64x2 $vec, 0, $x)>; 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6640b57cec5SDimitry Andric// Comparisons 6650b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6660b57cec5SDimitry Andric 667e8d8bef9SDimitry Andricmulticlass SIMDCondition<Vec vec, string name, CondCode cond, bits<32> simdop> { 668e8d8bef9SDimitry Andric defm _#vec : 6690b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 670e8d8bef9SDimitry Andric [(set (vec.int_vt V128:$dst), 671e8d8bef9SDimitry Andric (setcc (vec.vt V128:$lhs), (vec.vt V128:$rhs), cond))], 672e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 673e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 6740b57cec5SDimitry Andric} 6750b57cec5SDimitry Andric 6760b57cec5SDimitry Andricmulticlass SIMDConditionInt<string name, CondCode cond, bits<32> baseInst> { 677e8d8bef9SDimitry Andric defm "" : SIMDCondition<I8x16, name, cond, baseInst>; 678e8d8bef9SDimitry Andric defm "" : SIMDCondition<I16x8, name, cond, !add(baseInst, 10)>; 679e8d8bef9SDimitry Andric defm "" : SIMDCondition<I32x4, name, cond, !add(baseInst, 20)>; 6800b57cec5SDimitry Andric} 6810b57cec5SDimitry Andric 6820b57cec5SDimitry Andricmulticlass SIMDConditionFP<string name, CondCode cond, bits<32> baseInst> { 683e8d8bef9SDimitry Andric defm "" : SIMDCondition<F32x4, name, cond, baseInst>; 684e8d8bef9SDimitry Andric defm "" : SIMDCondition<F64x2, name, cond, !add(baseInst, 6)>; 6850b57cec5SDimitry Andric} 6860b57cec5SDimitry Andric 6870b57cec5SDimitry Andric// Equality: eq 6880b57cec5SDimitry Andriclet isCommutable = 1 in { 6895ffd83dbSDimitry Andricdefm EQ : SIMDConditionInt<"eq", SETEQ, 35>; 690fe6060f1SDimitry Andricdefm EQ : SIMDCondition<I64x2, "eq", SETEQ, 214>; 6915ffd83dbSDimitry Andricdefm EQ : SIMDConditionFP<"eq", SETOEQ, 65>; 6920b57cec5SDimitry Andric} // isCommutable = 1 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andric// Non-equality: ne 6950b57cec5SDimitry Andriclet isCommutable = 1 in { 6965ffd83dbSDimitry Andricdefm NE : SIMDConditionInt<"ne", SETNE, 36>; 697fe6060f1SDimitry Andricdefm NE : SIMDCondition<I64x2, "ne", SETNE, 215>; 6985ffd83dbSDimitry Andricdefm NE : SIMDConditionFP<"ne", SETUNE, 66>; 6990b57cec5SDimitry Andric} // isCommutable = 1 7000b57cec5SDimitry Andric 7010b57cec5SDimitry Andric// Less than: lt_s / lt_u / lt 7025ffd83dbSDimitry Andricdefm LT_S : SIMDConditionInt<"lt_s", SETLT, 37>; 703fe6060f1SDimitry Andricdefm LT_S : SIMDCondition<I64x2, "lt_s", SETLT, 216>; 7045ffd83dbSDimitry Andricdefm LT_U : SIMDConditionInt<"lt_u", SETULT, 38>; 7055ffd83dbSDimitry Andricdefm LT : SIMDConditionFP<"lt", SETOLT, 67>; 7060b57cec5SDimitry Andric 7070b57cec5SDimitry Andric// Greater than: gt_s / gt_u / gt 7085ffd83dbSDimitry Andricdefm GT_S : SIMDConditionInt<"gt_s", SETGT, 39>; 709fe6060f1SDimitry Andricdefm GT_S : SIMDCondition<I64x2, "gt_s", SETGT, 217>; 7105ffd83dbSDimitry Andricdefm GT_U : SIMDConditionInt<"gt_u", SETUGT, 40>; 7115ffd83dbSDimitry Andricdefm GT : SIMDConditionFP<"gt", SETOGT, 68>; 7120b57cec5SDimitry Andric 7130b57cec5SDimitry Andric// Less than or equal: le_s / le_u / le 7145ffd83dbSDimitry Andricdefm LE_S : SIMDConditionInt<"le_s", SETLE, 41>; 715fe6060f1SDimitry Andricdefm LE_S : SIMDCondition<I64x2, "le_s", SETLE, 218>; 7165ffd83dbSDimitry Andricdefm LE_U : SIMDConditionInt<"le_u", SETULE, 42>; 7175ffd83dbSDimitry Andricdefm LE : SIMDConditionFP<"le", SETOLE, 69>; 7180b57cec5SDimitry Andric 7190b57cec5SDimitry Andric// Greater than or equal: ge_s / ge_u / ge 7205ffd83dbSDimitry Andricdefm GE_S : SIMDConditionInt<"ge_s", SETGE, 43>; 721fe6060f1SDimitry Andricdefm GE_S : SIMDCondition<I64x2, "ge_s", SETGE, 219>; 7225ffd83dbSDimitry Andricdefm GE_U : SIMDConditionInt<"ge_u", SETUGE, 44>; 7235ffd83dbSDimitry Andricdefm GE : SIMDConditionFP<"ge", SETOGE, 70>; 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andric// Lower float comparisons that don't care about NaN to standard WebAssembly 7260b57cec5SDimitry Andric// float comparisons. These instructions are generated with nnan and in the 7270b57cec5SDimitry Andric// target-independent expansion of unordered comparisons and ordered ne. 728e8d8bef9SDimitry Andricforeach nodes = [[seteq, EQ_F32x4], [setne, NE_F32x4], [setlt, LT_F32x4], 729e8d8bef9SDimitry Andric [setgt, GT_F32x4], [setle, LE_F32x4], [setge, GE_F32x4]] in 7300b57cec5SDimitry Andricdef : Pat<(v4i32 (nodes[0] (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 731e8d8bef9SDimitry Andric (nodes[1] $lhs, $rhs)>; 7320b57cec5SDimitry Andric 733e8d8bef9SDimitry Andricforeach nodes = [[seteq, EQ_F64x2], [setne, NE_F64x2], [setlt, LT_F64x2], 734e8d8bef9SDimitry Andric [setgt, GT_F64x2], [setle, LE_F64x2], [setge, GE_F64x2]] in 7350b57cec5SDimitry Andricdef : Pat<(v2i64 (nodes[0] (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 736e8d8bef9SDimitry Andric (nodes[1] $lhs, $rhs)>; 737e8d8bef9SDimitry Andric 7380b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7390b57cec5SDimitry Andric// Bitwise operations 7400b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7410b57cec5SDimitry Andric 742fe6060f1SDimitry Andricmulticlass SIMDBinary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> { 743e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 7440b57cec5SDimitry Andric (outs), (ins), 745e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 746e8d8bef9SDimitry Andric (node (vec.vt V128:$lhs), (vec.vt V128:$rhs)))], 747e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 748e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 7490b57cec5SDimitry Andric} 7500b57cec5SDimitry Andric 751fe6060f1SDimitry Andricmulticlass SIMDBitwise<SDPatternOperator node, string name, bits<32> simdop, 752fe6060f1SDimitry Andric bit commutable = false> { 753e8d8bef9SDimitry Andric let isCommutable = commutable in 754e8d8bef9SDimitry Andric defm "" : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 755e8d8bef9SDimitry Andric (outs), (ins), [], 756e8d8bef9SDimitry Andric "v128."#name#"\t$dst, $lhs, $rhs", "v128."#name, simdop>; 757e8d8bef9SDimitry Andric foreach vec = IntVecs in 758e8d8bef9SDimitry Andric def : Pat<(node (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 759e8d8bef9SDimitry Andric (!cast<NI>(NAME) $lhs, $rhs)>; 7600b57cec5SDimitry Andric} 7610b57cec5SDimitry Andric 762fe6060f1SDimitry Andricmulticlass SIMDUnary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> { 763e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins), 764e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 765e8d8bef9SDimitry Andric (vec.vt (node (vec.vt V128:$v))))], 766e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $v", 767e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 7680b57cec5SDimitry Andric} 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andric// Bitwise logic: v128.not 771e8d8bef9SDimitry Andricdefm NOT : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins), [], 772e8d8bef9SDimitry Andric "v128.not\t$dst, $v", "v128.not", 77>; 773e8d8bef9SDimitry Andricforeach vec = IntVecs in 774e8d8bef9SDimitry Andricdef : Pat<(vnot (vec.vt V128:$v)), (NOT $v)>; 7750b57cec5SDimitry Andric 7760b57cec5SDimitry Andric// Bitwise logic: v128.and / v128.or / v128.xor 777e8d8bef9SDimitry Andricdefm AND : SIMDBitwise<and, "and", 78, true>; 778e8d8bef9SDimitry Andricdefm OR : SIMDBitwise<or, "or", 80, true>; 779e8d8bef9SDimitry Andricdefm XOR : SIMDBitwise<xor, "xor", 81, true>; 7800b57cec5SDimitry Andric 7818bcb0991SDimitry Andric// Bitwise logic: v128.andnot 7828bcb0991SDimitry Andricdef andnot : PatFrag<(ops node:$left, node:$right), (and $left, (vnot $right))>; 7835ffd83dbSDimitry Andricdefm ANDNOT : SIMDBitwise<andnot, "andnot", 79>; 7848bcb0991SDimitry Andric 7850b57cec5SDimitry Andric// Bitwise select: v128.bitselect 786e8d8bef9SDimitry Andricdefm BITSELECT : 787e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$v1, V128:$v2, V128:$c), (outs), (ins), [], 7885ffd83dbSDimitry Andric "v128.bitselect\t$dst, $v1, $v2, $c", "v128.bitselect", 82>; 7890b57cec5SDimitry Andric 790e8d8bef9SDimitry Andricforeach vec = AllVecs in 791e8d8bef9SDimitry Andricdef : Pat<(vec.vt (int_wasm_bitselect 792e8d8bef9SDimitry Andric (vec.vt V128:$v1), (vec.vt V128:$v2), (vec.vt V128:$c))), 793e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 794e8d8bef9SDimitry Andric 7950b57cec5SDimitry Andric// Bitselect is equivalent to (c & v1) | (~c & v2) 796e8d8bef9SDimitry Andricforeach vec = IntVecs in 797e8d8bef9SDimitry Andricdef : Pat<(vec.vt (or (and (vec.vt V128:$c), (vec.vt V128:$v1)), 798e8d8bef9SDimitry Andric (and (vnot V128:$c), (vec.vt V128:$v2)))), 799e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 800e8d8bef9SDimitry Andric 801*bdd1243dSDimitry Andric// Bitselect is also equivalent to ((v1 ^ v2) & c) ^ v2 802*bdd1243dSDimitry Andricforeach vec = IntVecs in 803*bdd1243dSDimitry Andricdef : Pat<(vec.vt (xor (and (xor (vec.vt V128:$v1), (vec.vt V128:$v2)), 804*bdd1243dSDimitry Andric (vec.vt V128:$c)), 805*bdd1243dSDimitry Andric (vec.vt V128:$v2))), 806*bdd1243dSDimitry Andric (BITSELECT $v1, $v2, $c)>; 807*bdd1243dSDimitry Andric 808*bdd1243dSDimitry Andric// Same pattern with `c` negated so `a` and `b` get swapped. 809*bdd1243dSDimitry Andricforeach vec = IntVecs in 810*bdd1243dSDimitry Andricdef : Pat<(vec.vt (xor (and (xor (vec.vt V128:$v1), (vec.vt V128:$v2)), 811*bdd1243dSDimitry Andric (vnot (vec.vt V128:$c))), 812*bdd1243dSDimitry Andric (vec.vt V128:$v2))), 813*bdd1243dSDimitry Andric (BITSELECT $v2, $v1, $c)>; 814*bdd1243dSDimitry Andric 815e8d8bef9SDimitry Andric// Also implement vselect in terms of bitselect 816e8d8bef9SDimitry Andricforeach vec = AllVecs in 817e8d8bef9SDimitry Andricdef : Pat<(vec.vt (vselect 818e8d8bef9SDimitry Andric (vec.int_vt V128:$c), (vec.vt V128:$v1), (vec.vt V128:$v2))), 819e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 820e8d8bef9SDimitry Andric 821e8d8bef9SDimitry Andric// MVP select on v128 values 822e8d8bef9SDimitry Andricdefm SELECT_V128 : 823e8d8bef9SDimitry Andric I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, I32:$cond), (outs), (ins), [], 824e8d8bef9SDimitry Andric "v128.select\t$dst, $lhs, $rhs, $cond", "v128.select", 0x1b>; 825e8d8bef9SDimitry Andric 826e8d8bef9SDimitry Andricforeach vec = AllVecs in { 827e8d8bef9SDimitry Andricdef : Pat<(select I32:$cond, (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 828e8d8bef9SDimitry Andric (SELECT_V128 $lhs, $rhs, $cond)>; 829e8d8bef9SDimitry Andric 830e8d8bef9SDimitry Andric// ISD::SELECT requires its operand to conform to getBooleanContents, but 831e8d8bef9SDimitry Andric// WebAssembly's select interprets any non-zero value as true, so we can fold 832e8d8bef9SDimitry Andric// a setne with 0 into a select. 833e8d8bef9SDimitry Andricdef : Pat<(select 834e8d8bef9SDimitry Andric (i32 (setne I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 835e8d8bef9SDimitry Andric (SELECT_V128 $lhs, $rhs, $cond)>; 836e8d8bef9SDimitry Andric 837e8d8bef9SDimitry Andric// And again, this time with seteq instead of setne and the arms reversed. 838e8d8bef9SDimitry Andricdef : Pat<(select 839e8d8bef9SDimitry Andric (i32 (seteq I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 840e8d8bef9SDimitry Andric (SELECT_V128 $rhs, $lhs, $cond)>; 841e8d8bef9SDimitry Andric} // foreach vec 842e8d8bef9SDimitry Andric 8430b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8440b57cec5SDimitry Andric// Integer unary arithmetic 8450b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8460b57cec5SDimitry Andric 847fe6060f1SDimitry Andricmulticlass SIMDUnaryInt<SDPatternOperator node, string name, bits<32> baseInst> { 848e8d8bef9SDimitry Andric defm "" : SIMDUnary<I8x16, node, name, baseInst>; 849e8d8bef9SDimitry Andric defm "" : SIMDUnary<I16x8, node, name, !add(baseInst, 32)>; 850e8d8bef9SDimitry Andric defm "" : SIMDUnary<I32x4, node, name, !add(baseInst, 64)>; 851e8d8bef9SDimitry Andric defm "" : SIMDUnary<I64x2, node, name, !add(baseInst, 96)>; 8520b57cec5SDimitry Andric} 8530b57cec5SDimitry Andric 8540b57cec5SDimitry Andric// Integer vector negation 855e8d8bef9SDimitry Andricdef ivneg : PatFrag<(ops node:$in), (sub immAllZerosV, $in)>; 8560b57cec5SDimitry Andric 8575ffd83dbSDimitry Andric// Integer absolute value: abs 8585ffd83dbSDimitry Andricdefm ABS : SIMDUnaryInt<abs, "abs", 96>; 8595ffd83dbSDimitry Andric 8600b57cec5SDimitry Andric// Integer negation: neg 8615ffd83dbSDimitry Andricdefm NEG : SIMDUnaryInt<ivneg, "neg", 97>; 8620b57cec5SDimitry Andric 863fe6060f1SDimitry Andric// Population count: popcnt 864fe6060f1SDimitry Andricdefm POPCNT : SIMDUnary<I8x16, ctpop, "popcnt", 0x62>; 865fe6060f1SDimitry Andric 8660b57cec5SDimitry Andric// Any lane true: any_true 867fe6060f1SDimitry Andricdefm ANYTRUE : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), [], 868fe6060f1SDimitry Andric "v128.any_true\t$dst, $vec", "v128.any_true", 0x53>; 869fe6060f1SDimitry Andric 870fe6060f1SDimitry Andricforeach vec = IntVecs in 871fe6060f1SDimitry Andricdef : Pat<(int_wasm_anytrue (vec.vt V128:$vec)), (ANYTRUE V128:$vec)>; 8720b57cec5SDimitry Andric 8730b57cec5SDimitry Andric// All lanes true: all_true 874fe6060f1SDimitry Andricmulticlass SIMDAllTrue<Vec vec, bits<32> simdop> { 875fe6060f1SDimitry Andric defm ALLTRUE_#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), 876fe6060f1SDimitry Andric [(set I32:$dst, 877fe6060f1SDimitry Andric (i32 (int_wasm_alltrue (vec.vt V128:$vec))))], 878fe6060f1SDimitry Andric vec.prefix#".all_true\t$dst, $vec", 879fe6060f1SDimitry Andric vec.prefix#".all_true", simdop>; 880fe6060f1SDimitry Andric} 8810b57cec5SDimitry Andric 882fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I8x16, 0x63>; 883fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I16x8, 0x83>; 884fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I32x4, 0xa3>; 885fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I64x2, 0xc3>; 886e8d8bef9SDimitry Andric 8870b57cec5SDimitry Andric// Reductions already return 0 or 1, so and 1, setne 0, and seteq 1 8880b57cec5SDimitry Andric// can be folded out 8890b57cec5SDimitry Andricforeach reduction = 890fe6060f1SDimitry Andric [["int_wasm_anytrue", "ANYTRUE", "I8x16"], 891fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I16x8"], 892fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I32x4"], 893fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I64x2"], 894fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I8x16", "I8x16"], 895fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I16x8", "I16x8"], 896fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I32x4", "I32x4"], 897fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I64x2", "I64x2"]] in { 898e8d8bef9SDimitry Andricdefvar intrinsic = !cast<Intrinsic>(reduction[0]); 899fe6060f1SDimitry Andricdefvar inst = !cast<NI>(reduction[1]); 900fe6060f1SDimitry Andricdefvar vec = !cast<Vec>(reduction[2]); 901e8d8bef9SDimitry Andricdef : Pat<(i32 (and (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>; 902e8d8bef9SDimitry Andricdef : Pat<(i32 (setne (i32 (intrinsic (vec.vt V128:$x))), (i32 0))), (inst $x)>; 903e8d8bef9SDimitry Andricdef : Pat<(i32 (seteq (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>; 9040b57cec5SDimitry Andric} 9050b57cec5SDimitry Andric 906e8d8bef9SDimitry Andricmulticlass SIMDBitmask<Vec vec, bits<32> simdop> { 907e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), 9085ffd83dbSDimitry Andric [(set I32:$dst, 909e8d8bef9SDimitry Andric (i32 (int_wasm_bitmask (vec.vt V128:$vec))))], 910e8d8bef9SDimitry Andric vec.prefix#".bitmask\t$dst, $vec", vec.prefix#".bitmask", 911e8d8bef9SDimitry Andric simdop>; 9125ffd83dbSDimitry Andric} 9135ffd83dbSDimitry Andric 914e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I8x16, 100>; 915e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I16x8, 132>; 916e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I32x4, 164>; 917e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I64x2, 196>; 9185ffd83dbSDimitry Andric 9190b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9200b57cec5SDimitry Andric// Bit shifts 9210b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9220b57cec5SDimitry Andric 923e8d8bef9SDimitry Andricmulticlass SIMDShift<Vec vec, SDNode node, string name, bits<32> simdop> { 924e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$vec, I32:$x), (outs), (ins), 925e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (node V128:$vec, I32:$x))], 926e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec, $x", 927e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 9280b57cec5SDimitry Andric} 9290b57cec5SDimitry Andric 9300b57cec5SDimitry Andricmulticlass SIMDShiftInt<SDNode node, string name, bits<32> baseInst> { 931e8d8bef9SDimitry Andric defm "" : SIMDShift<I8x16, node, name, baseInst>; 932e8d8bef9SDimitry Andric defm "" : SIMDShift<I16x8, node, name, !add(baseInst, 32)>; 933e8d8bef9SDimitry Andric defm "" : SIMDShift<I32x4, node, name, !add(baseInst, 64)>; 934e8d8bef9SDimitry Andric defm "" : SIMDShift<I64x2, node, name, !add(baseInst, 96)>; 9350b57cec5SDimitry Andric} 9360b57cec5SDimitry Andric 9375ffd83dbSDimitry Andric// WebAssembly SIMD shifts are nonstandard in that the shift amount is 9385ffd83dbSDimitry Andric// an i32 rather than a vector, so they need custom nodes. 939e8d8bef9SDimitry Andricdef wasm_shift_t : 940e8d8bef9SDimitry Andric SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, i32>]>; 9410b57cec5SDimitry Andricdef wasm_shl : SDNode<"WebAssemblyISD::VEC_SHL", wasm_shift_t>; 9420b57cec5SDimitry Andricdef wasm_shr_s : SDNode<"WebAssemblyISD::VEC_SHR_S", wasm_shift_t>; 9430b57cec5SDimitry Andricdef wasm_shr_u : SDNode<"WebAssemblyISD::VEC_SHR_U", wasm_shift_t>; 9445ffd83dbSDimitry Andric 9455ffd83dbSDimitry Andric// Left shift by scalar: shl 9465ffd83dbSDimitry Andricdefm SHL : SIMDShiftInt<wasm_shl, "shl", 107>; 9475ffd83dbSDimitry Andric 9485ffd83dbSDimitry Andric// Right shift by scalar: shr_s / shr_u 9495ffd83dbSDimitry Andricdefm SHR_S : SIMDShiftInt<wasm_shr_s, "shr_s", 108>; 9505ffd83dbSDimitry Andricdefm SHR_U : SIMDShiftInt<wasm_shr_u, "shr_u", 109>; 9510b57cec5SDimitry Andric 952fe6060f1SDimitry Andric// Optimize away an explicit mask on a shift count. 953fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v16i8 V128:$lhs), (and I32:$rhs, 7)), 954fe6060f1SDimitry Andric (SHL_I8x16 V128:$lhs, I32:$rhs)>; 955fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v16i8 V128:$lhs), (and I32:$rhs, 7)), 956fe6060f1SDimitry Andric (SHR_S_I8x16 V128:$lhs, I32:$rhs)>; 957fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v16i8 V128:$lhs), (and I32:$rhs, 7)), 958fe6060f1SDimitry Andric (SHR_U_I8x16 V128:$lhs, I32:$rhs)>; 959fe6060f1SDimitry Andric 960fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v8i16 V128:$lhs), (and I32:$rhs, 15)), 961fe6060f1SDimitry Andric (SHL_I16x8 V128:$lhs, I32:$rhs)>; 962fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v8i16 V128:$lhs), (and I32:$rhs, 15)), 963fe6060f1SDimitry Andric (SHR_S_I16x8 V128:$lhs, I32:$rhs)>; 964fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v8i16 V128:$lhs), (and I32:$rhs, 15)), 965fe6060f1SDimitry Andric (SHR_U_I16x8 V128:$lhs, I32:$rhs)>; 966fe6060f1SDimitry Andric 967fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v4i32 V128:$lhs), (and I32:$rhs, 31)), 968fe6060f1SDimitry Andric (SHL_I32x4 V128:$lhs, I32:$rhs)>; 969fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v4i32 V128:$lhs), (and I32:$rhs, 31)), 970fe6060f1SDimitry Andric (SHR_S_I32x4 V128:$lhs, I32:$rhs)>; 971fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v4i32 V128:$lhs), (and I32:$rhs, 31)), 972fe6060f1SDimitry Andric (SHR_U_I32x4 V128:$lhs, I32:$rhs)>; 973fe6060f1SDimitry Andric 974fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 975fe6060f1SDimitry Andric (SHL_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 976fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 977fe6060f1SDimitry Andric (SHR_S_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 978fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 979fe6060f1SDimitry Andric (SHR_U_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 980fe6060f1SDimitry Andric 9810b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9820b57cec5SDimitry Andric// Integer binary arithmetic 9830b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9840b57cec5SDimitry Andric 985fe6060f1SDimitry Andricmulticlass SIMDBinaryIntNoI8x16<SDPatternOperator node, string name, bits<32> baseInst> { 986e8d8bef9SDimitry Andric defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>; 987e8d8bef9SDimitry Andric defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>; 988e8d8bef9SDimitry Andric defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>; 9895ffd83dbSDimitry Andric} 9905ffd83dbSDimitry Andric 991fe6060f1SDimitry Andricmulticlass SIMDBinaryIntSmall<SDPatternOperator node, string name, bits<32> baseInst> { 992e8d8bef9SDimitry Andric defm "" : SIMDBinary<I8x16, node, name, baseInst>; 993e8d8bef9SDimitry Andric defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>; 9940b57cec5SDimitry Andric} 9950b57cec5SDimitry Andric 996fe6060f1SDimitry Andricmulticlass SIMDBinaryIntNoI64x2<SDPatternOperator node, string name, bits<32> baseInst> { 9970b57cec5SDimitry Andric defm "" : SIMDBinaryIntSmall<node, name, baseInst>; 998e8d8bef9SDimitry Andric defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>; 9990b57cec5SDimitry Andric} 10000b57cec5SDimitry Andric 1001fe6060f1SDimitry Andricmulticlass SIMDBinaryInt<SDPatternOperator node, string name, bits<32> baseInst> { 10020b57cec5SDimitry Andric defm "" : SIMDBinaryIntNoI64x2<node, name, baseInst>; 1003e8d8bef9SDimitry Andric defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>; 10040b57cec5SDimitry Andric} 10050b57cec5SDimitry Andric 1006fe6060f1SDimitry Andric// Integer addition: add / add_sat_s / add_sat_u 10070b57cec5SDimitry Andriclet isCommutable = 1 in { 10085ffd83dbSDimitry Andricdefm ADD : SIMDBinaryInt<add, "add", 110>; 1009fe6060f1SDimitry Andricdefm ADD_SAT_S : SIMDBinaryIntSmall<saddsat, "add_sat_s", 111>; 1010fe6060f1SDimitry Andricdefm ADD_SAT_U : SIMDBinaryIntSmall<uaddsat, "add_sat_u", 112>; 10110b57cec5SDimitry Andric} // isCommutable = 1 10120b57cec5SDimitry Andric 1013fe6060f1SDimitry Andric// Integer subtraction: sub / sub_sat_s / sub_sat_u 10145ffd83dbSDimitry Andricdefm SUB : SIMDBinaryInt<sub, "sub", 113>; 10150b57cec5SDimitry Andricdefm SUB_SAT_S : 1016fe6060f1SDimitry Andric SIMDBinaryIntSmall<int_wasm_sub_sat_signed, "sub_sat_s", 114>; 10170b57cec5SDimitry Andricdefm SUB_SAT_U : 1018fe6060f1SDimitry Andric SIMDBinaryIntSmall<int_wasm_sub_sat_unsigned, "sub_sat_u", 115>; 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andric// Integer multiplication: mul 1021480093f4SDimitry Andriclet isCommutable = 1 in 10225ffd83dbSDimitry Andricdefm MUL : SIMDBinaryIntNoI8x16<mul, "mul", 117>; 10230b57cec5SDimitry Andric 1024480093f4SDimitry Andric// Integer min_s / min_u / max_s / max_u 1025480093f4SDimitry Andriclet isCommutable = 1 in { 10265ffd83dbSDimitry Andricdefm MIN_S : SIMDBinaryIntNoI64x2<smin, "min_s", 118>; 10275ffd83dbSDimitry Andricdefm MIN_U : SIMDBinaryIntNoI64x2<umin, "min_u", 119>; 10285ffd83dbSDimitry Andricdefm MAX_S : SIMDBinaryIntNoI64x2<smax, "max_s", 120>; 10295ffd83dbSDimitry Andricdefm MAX_U : SIMDBinaryIntNoI64x2<umax, "max_u", 121>; 1030480093f4SDimitry Andric} // isCommutable = 1 1031480093f4SDimitry Andric 1032480093f4SDimitry Andric// Integer unsigned rounding average: avgr_u 10335ffd83dbSDimitry Andriclet isCommutable = 1 in { 1034e8d8bef9SDimitry Andricdefm AVGR_U : SIMDBinary<I8x16, int_wasm_avgr_unsigned, "avgr_u", 123>; 1035e8d8bef9SDimitry Andricdefm AVGR_U : SIMDBinary<I16x8, int_wasm_avgr_unsigned, "avgr_u", 155>; 1036480093f4SDimitry Andric} 1037480093f4SDimitry Andric 1038e8d8bef9SDimitry Andricdef add_nuw : PatFrag<(ops node:$lhs, node:$rhs), (add $lhs, $rhs), 1039480093f4SDimitry Andric "return N->getFlags().hasNoUnsignedWrap();">; 1040480093f4SDimitry Andric 1041e8d8bef9SDimitry Andricforeach vec = [I8x16, I16x8] in { 1042e8d8bef9SDimitry Andricdefvar inst = !cast<NI>("AVGR_U_"#vec); 10435ffd83dbSDimitry Andricdef : Pat<(wasm_shr_u 1044480093f4SDimitry Andric (add_nuw 1045e8d8bef9SDimitry Andric (add_nuw (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 1046e8d8bef9SDimitry Andric (vec.splat (i32 1))), 1047e8d8bef9SDimitry Andric (i32 1)), 1048e8d8bef9SDimitry Andric (inst $lhs, $rhs)>; 1049e8d8bef9SDimitry Andric} 1050480093f4SDimitry Andric 1051480093f4SDimitry Andric// Widening dot product: i32x4.dot_i16x8_s 1052480093f4SDimitry Andriclet isCommutable = 1 in 1053480093f4SDimitry Andricdefm DOT : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 1054480093f4SDimitry Andric [(set V128:$dst, (int_wasm_dot V128:$lhs, V128:$rhs))], 1055480093f4SDimitry Andric "i32x4.dot_i16x8_s\t$dst, $lhs, $rhs", "i32x4.dot_i16x8_s", 1056e8d8bef9SDimitry Andric 186>; 1057e8d8bef9SDimitry Andric 1058e8d8bef9SDimitry Andric// Extending multiplication: extmul_{low,high}_P, extmul_high 1059fe6060f1SDimitry Andricdef extend_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1060fe6060f1SDimitry Andricdef extend_low_s : SDNode<"WebAssemblyISD::EXTEND_LOW_S", extend_t>; 1061fe6060f1SDimitry Andricdef extend_high_s : SDNode<"WebAssemblyISD::EXTEND_HIGH_S", extend_t>; 1062fe6060f1SDimitry Andricdef extend_low_u : SDNode<"WebAssemblyISD::EXTEND_LOW_U", extend_t>; 1063fe6060f1SDimitry Andricdef extend_high_u : SDNode<"WebAssemblyISD::EXTEND_HIGH_U", extend_t>; 1064fe6060f1SDimitry Andric 1065fe6060f1SDimitry Andricmulticlass SIMDExtBinary<Vec vec, SDPatternOperator node, string name, 1066fe6060f1SDimitry Andric bits<32> simdop> { 1067e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 1068e8d8bef9SDimitry Andric (outs), (ins), 1069e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (node 1070e8d8bef9SDimitry Andric (vec.split.vt V128:$lhs),(vec.split.vt V128:$rhs)))], 1071e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 1072e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 1073e8d8bef9SDimitry Andric} 1074e8d8bef9SDimitry Andric 1075fe6060f1SDimitry Andricclass ExtMulPat<SDNode extend> : 1076fe6060f1SDimitry Andric PatFrag<(ops node:$lhs, node:$rhs), 1077fe6060f1SDimitry Andric (mul (extend $lhs), (extend $rhs))> {} 1078fe6060f1SDimitry Andric 1079fe6060f1SDimitry Andricdef extmul_low_s : ExtMulPat<extend_low_s>; 1080fe6060f1SDimitry Andricdef extmul_high_s : ExtMulPat<extend_high_s>; 1081fe6060f1SDimitry Andricdef extmul_low_u : ExtMulPat<extend_low_u>; 1082fe6060f1SDimitry Andricdef extmul_high_u : ExtMulPat<extend_high_u>; 1083e8d8bef9SDimitry Andric 1084e8d8bef9SDimitry Andricdefm EXTMUL_LOW_S : 1085fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_low_s, "extmul_low_i8x16_s", 0x9c>; 1086e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_S : 1087fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_high_s, "extmul_high_i8x16_s", 0x9d>; 1088e8d8bef9SDimitry Andricdefm EXTMUL_LOW_U : 1089fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_low_u, "extmul_low_i8x16_u", 0x9e>; 1090e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_U : 1091fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_high_u, "extmul_high_i8x16_u", 0x9f>; 1092e8d8bef9SDimitry Andric 1093e8d8bef9SDimitry Andricdefm EXTMUL_LOW_S : 1094fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_low_s, "extmul_low_i16x8_s", 0xbc>; 1095e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_S : 1096fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_high_s, "extmul_high_i16x8_s", 0xbd>; 1097e8d8bef9SDimitry Andricdefm EXTMUL_LOW_U : 1098fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_low_u, "extmul_low_i16x8_u", 0xbe>; 1099e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_U : 1100fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_high_u, "extmul_high_i16x8_u", 0xbf>; 1101fe6060f1SDimitry Andric 1102fe6060f1SDimitry Andricdefm EXTMUL_LOW_S : 1103fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_low_s, "extmul_low_i32x4_s", 0xdc>; 1104fe6060f1SDimitry Andricdefm EXTMUL_HIGH_S : 1105fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_high_s, "extmul_high_i32x4_s", 0xdd>; 1106fe6060f1SDimitry Andricdefm EXTMUL_LOW_U : 1107fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_low_u, "extmul_low_i32x4_u", 0xde>; 1108fe6060f1SDimitry Andricdefm EXTMUL_HIGH_U : 1109fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_high_u, "extmul_high_i32x4_u", 0xdf>; 1110480093f4SDimitry Andric 11110b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11120b57cec5SDimitry Andric// Floating-point unary arithmetic 11130b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11140b57cec5SDimitry Andric 11150b57cec5SDimitry Andricmulticlass SIMDUnaryFP<SDNode node, string name, bits<32> baseInst> { 1116e8d8bef9SDimitry Andric defm "" : SIMDUnary<F32x4, node, name, baseInst>; 1117e8d8bef9SDimitry Andric defm "" : SIMDUnary<F64x2, node, name, !add(baseInst, 12)>; 11180b57cec5SDimitry Andric} 11190b57cec5SDimitry Andric 11200b57cec5SDimitry Andric// Absolute value: abs 11215ffd83dbSDimitry Andricdefm ABS : SIMDUnaryFP<fabs, "abs", 224>; 11220b57cec5SDimitry Andric 11230b57cec5SDimitry Andric// Negation: neg 11245ffd83dbSDimitry Andricdefm NEG : SIMDUnaryFP<fneg, "neg", 225>; 11250b57cec5SDimitry Andric 11260b57cec5SDimitry Andric// Square root: sqrt 11275ffd83dbSDimitry Andricdefm SQRT : SIMDUnaryFP<fsqrt, "sqrt", 227>; 11285ffd83dbSDimitry Andric 11295ffd83dbSDimitry Andric// Rounding: ceil, floor, trunc, nearest 1130fe6060f1SDimitry Andricdefm CEIL : SIMDUnary<F32x4, fceil, "ceil", 0x67>; 1131fe6060f1SDimitry Andricdefm FLOOR : SIMDUnary<F32x4, ffloor, "floor", 0x68>; 1132fe6060f1SDimitry Andricdefm TRUNC: SIMDUnary<F32x4, ftrunc, "trunc", 0x69>; 1133fe6060f1SDimitry Andricdefm NEAREST: SIMDUnary<F32x4, fnearbyint, "nearest", 0x6a>; 1134fe6060f1SDimitry Andricdefm CEIL : SIMDUnary<F64x2, fceil, "ceil", 0x74>; 1135fe6060f1SDimitry Andricdefm FLOOR : SIMDUnary<F64x2, ffloor, "floor", 0x75>; 1136fe6060f1SDimitry Andricdefm TRUNC: SIMDUnary<F64x2, ftrunc, "trunc", 0x7a>; 1137fe6060f1SDimitry Andricdefm NEAREST: SIMDUnary<F64x2, fnearbyint, "nearest", 0x94>; 11380b57cec5SDimitry Andric 11390b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11400b57cec5SDimitry Andric// Floating-point binary arithmetic 11410b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11420b57cec5SDimitry Andric 1143fe6060f1SDimitry Andricmulticlass SIMDBinaryFP<SDPatternOperator node, string name, bits<32> baseInst> { 1144e8d8bef9SDimitry Andric defm "" : SIMDBinary<F32x4, node, name, baseInst>; 1145e8d8bef9SDimitry Andric defm "" : SIMDBinary<F64x2, node, name, !add(baseInst, 12)>; 11460b57cec5SDimitry Andric} 11470b57cec5SDimitry Andric 11480b57cec5SDimitry Andric// Addition: add 11490b57cec5SDimitry Andriclet isCommutable = 1 in 11505ffd83dbSDimitry Andricdefm ADD : SIMDBinaryFP<fadd, "add", 228>; 11510b57cec5SDimitry Andric 11520b57cec5SDimitry Andric// Subtraction: sub 11535ffd83dbSDimitry Andricdefm SUB : SIMDBinaryFP<fsub, "sub", 229>; 11540b57cec5SDimitry Andric 11550b57cec5SDimitry Andric// Multiplication: mul 11560b57cec5SDimitry Andriclet isCommutable = 1 in 11575ffd83dbSDimitry Andricdefm MUL : SIMDBinaryFP<fmul, "mul", 230>; 11580b57cec5SDimitry Andric 11590b57cec5SDimitry Andric// Division: div 11605ffd83dbSDimitry Andricdefm DIV : SIMDBinaryFP<fdiv, "div", 231>; 11610b57cec5SDimitry Andric 11620b57cec5SDimitry Andric// NaN-propagating minimum: min 11635ffd83dbSDimitry Andricdefm MIN : SIMDBinaryFP<fminimum, "min", 232>; 11640b57cec5SDimitry Andric 11650b57cec5SDimitry Andric// NaN-propagating maximum: max 11665ffd83dbSDimitry Andricdefm MAX : SIMDBinaryFP<fmaximum, "max", 233>; 11675ffd83dbSDimitry Andric 11685ffd83dbSDimitry Andric// Pseudo-minimum: pmin 1169fe6060f1SDimitry Andricdef pmin : PatFrag<(ops node:$lhs, node:$rhs), 1170fe6060f1SDimitry Andric (vselect (setolt $rhs, $lhs), $rhs, $lhs)>; 1171fe6060f1SDimitry Andricdefm PMIN : SIMDBinaryFP<pmin, "pmin", 234>; 11725ffd83dbSDimitry Andric 11735ffd83dbSDimitry Andric// Pseudo-maximum: pmax 1174fe6060f1SDimitry Andricdef pmax : PatFrag<(ops node:$lhs, node:$rhs), 1175fe6060f1SDimitry Andric (vselect (setolt $lhs, $rhs), $rhs, $lhs)>; 1176fe6060f1SDimitry Andricdefm PMAX : SIMDBinaryFP<pmax, "pmax", 235>; 1177fe6060f1SDimitry Andric 1178fe6060f1SDimitry Andric// Also match the pmin/pmax cases where the operands are int vectors (but the 1179fe6060f1SDimitry Andric// comparison is still a floating point comparison). This can happen when using 1180fe6060f1SDimitry Andric// the wasm_simd128.h intrinsics because v128_t is an integer vector. 1181fe6060f1SDimitry Andricforeach vec = [F32x4, F64x2] in { 1182fe6060f1SDimitry Andricdefvar pmin = !cast<NI>("PMIN_"#vec); 1183fe6060f1SDimitry Andricdefvar pmax = !cast<NI>("PMAX_"#vec); 1184fe6060f1SDimitry Andricdef : Pat<(vec.int_vt (vselect 1185fe6060f1SDimitry Andric (setolt (vec.vt (bitconvert V128:$rhs)), 1186fe6060f1SDimitry Andric (vec.vt (bitconvert V128:$lhs))), 1187fe6060f1SDimitry Andric V128:$rhs, V128:$lhs)), 1188fe6060f1SDimitry Andric (pmin $lhs, $rhs)>; 1189fe6060f1SDimitry Andricdef : Pat<(vec.int_vt (vselect 1190fe6060f1SDimitry Andric (setolt (vec.vt (bitconvert V128:$lhs)), 1191fe6060f1SDimitry Andric (vec.vt (bitconvert V128:$rhs))), 1192fe6060f1SDimitry Andric V128:$rhs, V128:$lhs)), 1193fe6060f1SDimitry Andric (pmax $lhs, $rhs)>; 1194fe6060f1SDimitry Andric} 11950b57cec5SDimitry Andric 1196349cc55cSDimitry Andric// And match the pmin/pmax LLVM intrinsics as well 1197349cc55cSDimitry Andricdef : Pat<(v4f32 (int_wasm_pmin (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 1198349cc55cSDimitry Andric (PMIN_F32x4 V128:$lhs, V128:$rhs)>; 1199349cc55cSDimitry Andricdef : Pat<(v4f32 (int_wasm_pmax (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 1200349cc55cSDimitry Andric (PMAX_F32x4 V128:$lhs, V128:$rhs)>; 1201349cc55cSDimitry Andricdef : Pat<(v2f64 (int_wasm_pmin (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 1202349cc55cSDimitry Andric (PMIN_F64x2 V128:$lhs, V128:$rhs)>; 1203349cc55cSDimitry Andricdef : Pat<(v2f64 (int_wasm_pmax (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 1204349cc55cSDimitry Andric (PMAX_F64x2 V128:$lhs, V128:$rhs)>; 1205349cc55cSDimitry Andric 12060b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12070b57cec5SDimitry Andric// Conversions 12080b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12090b57cec5SDimitry Andric 1210fe6060f1SDimitry Andricmulticlass SIMDConvert<Vec vec, Vec arg, SDPatternOperator op, string name, 1211e8d8bef9SDimitry Andric bits<32> simdop> { 1212e8d8bef9SDimitry Andric defm op#_#vec : 12130b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins), 1214e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))], 1215e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>; 12160b57cec5SDimitry Andric} 12170b57cec5SDimitry Andric 12180b57cec5SDimitry Andric// Floating point to integer with saturation: trunc_sat 1219e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, F32x4, fp_to_sint, "trunc_sat_f32x4_s", 248>; 1220e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, F32x4, fp_to_uint, "trunc_sat_f32x4_u", 249>; 12215ffd83dbSDimitry Andric 1222fe6060f1SDimitry Andric// Support the saturating variety as well. 1223fe6060f1SDimitry Andricdef trunc_s_sat32 : PatFrag<(ops node:$x), (fp_to_sint_sat $x, i32)>; 1224fe6060f1SDimitry Andricdef trunc_u_sat32 : PatFrag<(ops node:$x), (fp_to_uint_sat $x, i32)>; 1225fe6060f1SDimitry Andricdef : Pat<(v4i32 (trunc_s_sat32 (v4f32 V128:$src))), (fp_to_sint_I32x4 $src)>; 1226fe6060f1SDimitry Andricdef : Pat<(v4i32 (trunc_u_sat32 (v4f32 V128:$src))), (fp_to_uint_I32x4 $src)>; 1227fe6060f1SDimitry Andric 1228fe6060f1SDimitry Andricdef trunc_sat_zero_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1229fe6060f1SDimitry Andricdef trunc_sat_zero_s : 1230fe6060f1SDimitry Andric SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_S", trunc_sat_zero_t>; 1231fe6060f1SDimitry Andricdef trunc_sat_zero_u : 1232fe6060f1SDimitry Andric SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_U", trunc_sat_zero_t>; 123381ad6265SDimitry Andricdefm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_s, "trunc_sat_f64x2_s_zero", 1234fe6060f1SDimitry Andric 0xfc>; 123581ad6265SDimitry Andricdefm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_u, "trunc_sat_f64x2_u_zero", 1236fe6060f1SDimitry Andric 0xfd>; 1237fe6060f1SDimitry Andric 12385ffd83dbSDimitry Andric// Integer to floating point: convert 1239fe6060f1SDimitry Andricdef convert_low_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1240fe6060f1SDimitry Andricdef convert_low_s : SDNode<"WebAssemblyISD::CONVERT_LOW_S", convert_low_t>; 1241fe6060f1SDimitry Andricdef convert_low_u : SDNode<"WebAssemblyISD::CONVERT_LOW_U", convert_low_t>; 1242e8d8bef9SDimitry Andricdefm "" : SIMDConvert<F32x4, I32x4, sint_to_fp, "convert_i32x4_s", 250>; 1243e8d8bef9SDimitry Andricdefm "" : SIMDConvert<F32x4, I32x4, uint_to_fp, "convert_i32x4_u", 251>; 1244fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, I32x4, convert_low_s, "convert_low_i32x4_s", 0xfe>; 1245fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, I32x4, convert_low_u, "convert_low_i32x4_u", 0xff>; 12468bcb0991SDimitry Andric 1247fe6060f1SDimitry Andric// Extending operations 1248e8d8bef9SDimitry Andric// TODO: refactor this to be uniform for i64x2 if the numbering is not changed. 1249fe6060f1SDimitry Andricmulticlass SIMDExtend<Vec vec, bits<32> baseInst> { 1250fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_low_s, 1251fe6060f1SDimitry Andric "extend_low_"#vec.split.prefix#"_s", baseInst>; 1252fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_high_s, 1253fe6060f1SDimitry Andric "extend_high_"#vec.split.prefix#"_s", !add(baseInst, 1)>; 1254fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_low_u, 1255fe6060f1SDimitry Andric "extend_low_"#vec.split.prefix#"_u", !add(baseInst, 2)>; 1256fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_high_u, 1257fe6060f1SDimitry Andric "extend_high_"#vec.split.prefix#"_u", !add(baseInst, 3)>; 1258e8d8bef9SDimitry Andric} 1259e8d8bef9SDimitry Andric 1260fe6060f1SDimitry Andricdefm "" : SIMDExtend<I16x8, 0x87>; 1261fe6060f1SDimitry Andricdefm "" : SIMDExtend<I32x4, 0xa7>; 1262fe6060f1SDimitry Andricdefm "" : SIMDExtend<I64x2, 0xc7>; 1263e8d8bef9SDimitry Andric 1264e8d8bef9SDimitry Andric// Narrowing operations 1265e8d8bef9SDimitry Andricmulticlass SIMDNarrow<Vec vec, bits<32> baseInst> { 1266e8d8bef9SDimitry Andric defvar name = vec.split.prefix#".narrow_"#vec.prefix; 1267e8d8bef9SDimitry Andric defm NARROW_S_#vec.split : 1268e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins), 1269e8d8bef9SDimitry Andric [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_signed 1270e8d8bef9SDimitry Andric (vec.vt V128:$low), (vec.vt V128:$high))))], 1271e8d8bef9SDimitry Andric name#"_s\t$dst, $low, $high", name#"_s", baseInst>; 1272e8d8bef9SDimitry Andric defm NARROW_U_#vec.split : 1273e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins), 1274e8d8bef9SDimitry Andric [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_unsigned 1275e8d8bef9SDimitry Andric (vec.vt V128:$low), (vec.vt V128:$high))))], 1276e8d8bef9SDimitry Andric name#"_u\t$dst, $low, $high", name#"_u", !add(baseInst, 1)>; 1277e8d8bef9SDimitry Andric} 1278e8d8bef9SDimitry Andric 1279e8d8bef9SDimitry Andricdefm "" : SIMDNarrow<I16x8, 101>; 1280e8d8bef9SDimitry Andricdefm "" : SIMDNarrow<I32x4, 133>; 1281e8d8bef9SDimitry Andric 12820eae32dcSDimitry Andric// WebAssemblyISD::NARROW_U 12830eae32dcSDimitry Andricdef wasm_narrow_t : SDTypeProfile<1, 2, []>; 12840eae32dcSDimitry Andricdef wasm_narrow_u : SDNode<"WebAssemblyISD::NARROW_U", wasm_narrow_t>; 12850eae32dcSDimitry Andricdef : Pat<(v16i8 (wasm_narrow_u (v8i16 V128:$left), (v8i16 V128:$right))), 12860eae32dcSDimitry Andric (NARROW_U_I8x16 $left, $right)>; 12870eae32dcSDimitry Andricdef : Pat<(v8i16 (wasm_narrow_u (v4i32 V128:$left), (v4i32 V128:$right))), 12880eae32dcSDimitry Andric (NARROW_U_I16x8 $left, $right)>; 12890eae32dcSDimitry Andric 12900b57cec5SDimitry Andric// Bitcasts are nops 12910b57cec5SDimitry Andric// Matching bitcast t1 to t1 causes strange errors, so avoid repeating types 1292fe6060f1SDimitry Andricforeach t1 = AllVecs in 1293fe6060f1SDimitry Andricforeach t2 = AllVecs in 1294fe6060f1SDimitry Andricif !ne(t1, t2) then 1295fe6060f1SDimitry Andricdef : Pat<(t1.vt (bitconvert (t2.vt V128:$v))), (t1.vt V128:$v)>; 12968bcb0991SDimitry Andric 1297e8d8bef9SDimitry Andric// Extended pairwise addition 1298e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_signed, 1299fe6060f1SDimitry Andric "extadd_pairwise_i8x16_s", 0x7c>; 1300e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_unsigned, 1301fe6060f1SDimitry Andric "extadd_pairwise_i8x16_u", 0x7d>; 1302e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_signed, 1303fe6060f1SDimitry Andric "extadd_pairwise_i16x8_s", 0x7e>; 1304e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_unsigned, 1305fe6060f1SDimitry Andric "extadd_pairwise_i16x8_u", 0x7f>; 1306e8d8bef9SDimitry Andric 1307fe6060f1SDimitry Andric// f64x2 <-> f32x4 conversions 1308fe6060f1SDimitry Andricdef demote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1309fe6060f1SDimitry Andricdef demote_zero : SDNode<"WebAssemblyISD::DEMOTE_ZERO", demote_t>; 1310fe6060f1SDimitry Andricdefm "" : SIMDConvert<F32x4, F64x2, demote_zero, 131181ad6265SDimitry Andric "demote_f64x2_zero", 0x5e>; 1312e8d8bef9SDimitry Andric 1313fe6060f1SDimitry Andricdef promote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1314fe6060f1SDimitry Andricdef promote_low : SDNode<"WebAssemblyISD::PROMOTE_LOW", promote_t>; 1315fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, F32x4, promote_low, "promote_low_f32x4", 0x5f>; 1316e8d8bef9SDimitry Andric 1317349cc55cSDimitry Andric// Lower extending loads to load64_zero + promote_low 1318349cc55cSDimitry Andricdef extloadv2f32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> { 1319349cc55cSDimitry Andric let MemoryVT = v2f32; 1320349cc55cSDimitry Andric} 1321349cc55cSDimitry Andric// Adapted from the body of LoadPatNoOffset 1322349cc55cSDimitry Andric// TODO: other addressing patterns 1323349cc55cSDimitry Andricdef : Pat<(v2f64 (extloadv2f32 (i32 I32:$addr))), 1324349cc55cSDimitry Andric (promote_low_F64x2 (LOAD_ZERO_I64x2_A32 0, 0, I32:$addr))>, 1325349cc55cSDimitry Andric Requires<[HasAddr32]>; 1326349cc55cSDimitry Andricdef : Pat<(v2f64 (extloadv2f32 (i64 I64:$addr))), 1327349cc55cSDimitry Andric (promote_low_F64x2 (LOAD_ZERO_I64x2_A64 0, 0, I64:$addr))>, 1328349cc55cSDimitry Andric Requires<[HasAddr64]>; 1329349cc55cSDimitry Andric 1330e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 1331e8d8bef9SDimitry Andric// Saturating Rounding Q-Format Multiplication 1332e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 1333e8d8bef9SDimitry Andric 1334e8d8bef9SDimitry Andricdefm Q15MULR_SAT_S : 1335fe6060f1SDimitry Andric SIMDBinary<I16x8, int_wasm_q15mulr_sat_signed, "q15mulr_sat_s", 0x82>; 1336349cc55cSDimitry Andric 1337349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 133881ad6265SDimitry Andric// Relaxed swizzle 133981ad6265SDimitry Andric//===----------------------------------------------------------------------===// 134081ad6265SDimitry Andric 134181ad6265SDimitry Andricdefm RELAXED_SWIZZLE : 134281ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins), 134381ad6265SDimitry Andric [(set (v16i8 V128:$dst), 134481ad6265SDimitry Andric (int_wasm_relaxed_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))], 134581ad6265SDimitry Andric "i8x16.relaxed_swizzle\t$dst, $src, $mask", "i8x16.relaxed_swizzle", 0x100>; 134681ad6265SDimitry Andric 134781ad6265SDimitry Andric//===----------------------------------------------------------------------===// 134881ad6265SDimitry Andric// Relaxed floating-point to int conversions 134981ad6265SDimitry Andric//===----------------------------------------------------------------------===// 135081ad6265SDimitry Andric 135181ad6265SDimitry Andricmulticlass RelaxedConvert<Vec vec, Vec arg, SDPatternOperator op, string name, bits<32> simdop> { 135281ad6265SDimitry Andric defm op#_#vec : 135381ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins), 135481ad6265SDimitry Andric [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))], 135581ad6265SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>; 135681ad6265SDimitry Andric} 135781ad6265SDimitry Andric 135881ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F32x4, int_wasm_relaxed_trunc_signed, 135981ad6265SDimitry Andric "relaxed_trunc_f32x4_s", 0x101>; 136081ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F32x4, int_wasm_relaxed_trunc_unsigned, 136181ad6265SDimitry Andric "relaxed_trunc_f32x4_u", 0x102>; 136281ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F64x2, int_wasm_relaxed_trunc_signed_zero, 136381ad6265SDimitry Andric "relaxed_trunc_f64x2_s_zero", 0x103>; 136481ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F64x2, int_wasm_relaxed_trunc_unsigned_zero, 136581ad6265SDimitry Andric "relaxed_trunc_f64x2_u_zero", 0x104>; 136681ad6265SDimitry Andric 136781ad6265SDimitry Andric//===----------------------------------------------------------------------===// 1368*bdd1243dSDimitry Andric// Relaxed (Negative) Multiply-Add (madd/nmadd) 1369349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1370349cc55cSDimitry Andric 1371*bdd1243dSDimitry Andricmulticlass SIMDMADD<Vec vec, bits<32> simdopA, bits<32> simdopS> { 1372*bdd1243dSDimitry Andric defm MADD_#vec : 1373349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1374*bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_madd 1375349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 1376*bdd1243dSDimitry Andric vec.prefix#".relaxed_madd\t$dst, $a, $b, $c", 1377*bdd1243dSDimitry Andric vec.prefix#".relaxed_madd", simdopA>; 1378*bdd1243dSDimitry Andric defm NMADD_#vec : 1379349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1380*bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_nmadd 1381349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 1382*bdd1243dSDimitry Andric vec.prefix#".relaxed_nmadd\t$dst, $a, $b, $c", 1383*bdd1243dSDimitry Andric vec.prefix#".relaxed_nmadd", simdopS>; 1384349cc55cSDimitry Andric} 1385349cc55cSDimitry Andric 1386*bdd1243dSDimitry Andricdefm "" : SIMDMADD<F32x4, 0x105, 0x106>; 1387*bdd1243dSDimitry Andricdefm "" : SIMDMADD<F64x2, 0x107, 0x108>; 1388349cc55cSDimitry Andric 1389349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1390349cc55cSDimitry Andric// Laneselect 1391349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1392349cc55cSDimitry Andric 1393349cc55cSDimitry Andricmulticlass SIMDLANESELECT<Vec vec, bits<32> op> { 1394349cc55cSDimitry Andric defm LANESELECT_#vec : 1395349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1396*bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_laneselect 1397349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 139881ad6265SDimitry Andric vec.prefix#".relaxed_laneselect\t$dst, $a, $b, $c", 139981ad6265SDimitry Andric vec.prefix#".relaxed_laneselect", op>; 1400349cc55cSDimitry Andric} 1401349cc55cSDimitry Andric 140281ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I8x16, 0x109>; 140381ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I16x8, 0x10a>; 140481ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I32x4, 0x10b>; 140581ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I64x2, 0x10c>; 1406349cc55cSDimitry Andric 1407349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1408349cc55cSDimitry Andric// Relaxed floating-point min and max. 1409349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1410349cc55cSDimitry Andric 141181ad6265SDimitry Andricmulticlass RelaxedBinary<Vec vec, SDPatternOperator node, string name, 141281ad6265SDimitry Andric bits<32> simdop> { 141381ad6265SDimitry Andric defm _#vec : RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 141481ad6265SDimitry Andric (outs), (ins), 141581ad6265SDimitry Andric [(set (vec.vt V128:$dst), 141681ad6265SDimitry Andric (node (vec.vt V128:$lhs), (vec.vt V128:$rhs)))], 141781ad6265SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 141881ad6265SDimitry Andric vec.prefix#"."#name, simdop>; 1419349cc55cSDimitry Andric} 1420349cc55cSDimitry Andric 142181ad6265SDimitry Andricdefm SIMD_RELAXED_FMIN : 142281ad6265SDimitry Andric RelaxedBinary<F32x4, int_wasm_relaxed_min, "relaxed_min", 0x10d>; 142381ad6265SDimitry Andricdefm SIMD_RELAXED_FMAX : 142481ad6265SDimitry Andric RelaxedBinary<F32x4, int_wasm_relaxed_max, "relaxed_max", 0x10e>; 142581ad6265SDimitry Andricdefm SIMD_RELAXED_FMIN : 142681ad6265SDimitry Andric RelaxedBinary<F64x2, int_wasm_relaxed_min, "relaxed_min", 0x10f>; 142781ad6265SDimitry Andricdefm SIMD_RELAXED_FMAX : 142881ad6265SDimitry Andric RelaxedBinary<F64x2, int_wasm_relaxed_max, "relaxed_max", 0x110>; 1429349cc55cSDimitry Andric 1430349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 143181ad6265SDimitry Andric// Relaxed rounding q15 multiplication 1432349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1433349cc55cSDimitry Andric 143481ad6265SDimitry Andricdefm RELAXED_Q15MULR_S : 143581ad6265SDimitry Andric RelaxedBinary<I16x8, int_wasm_relaxed_q15mulr_signed, "relaxed_q15mulr_s", 143681ad6265SDimitry Andric 0x111>; 1437349cc55cSDimitry Andric 143881ad6265SDimitry Andric//===----------------------------------------------------------------------===// 143981ad6265SDimitry Andric// Relaxed integer dot product 144081ad6265SDimitry Andric//===----------------------------------------------------------------------===// 1441349cc55cSDimitry Andric 144281ad6265SDimitry Andricdefm RELAXED_DOT : 144381ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 1444*bdd1243dSDimitry Andric [(set (v8i16 V128:$dst), (int_wasm_relaxed_dot_i8x16_i7x16_signed 144581ad6265SDimitry Andric (v16i8 V128:$lhs), (v16i8 V128:$rhs)))], 1446*bdd1243dSDimitry Andric "i16x8.relaxed_dot_i8x16_i7x16_s\t$dst, $lhs, $rhs", 1447*bdd1243dSDimitry Andric "i16x8.relaxed_dot_i8x16_i7x16_s", 0x112>; 144881ad6265SDimitry Andric 144981ad6265SDimitry Andricdefm RELAXED_DOT_ADD : 145081ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, V128:$acc), 145181ad6265SDimitry Andric (outs), (ins), 1452*bdd1243dSDimitry Andric [(set (v4i32 V128:$dst), (int_wasm_relaxed_dot_i8x16_i7x16_add_signed 145381ad6265SDimitry Andric (v16i8 V128:$lhs), (v16i8 V128:$rhs), (v4i32 V128:$acc)))], 1454*bdd1243dSDimitry Andric "i32x4.relaxed_dot_i8x16_i7x16_add_s\t$dst, $lhs, $rhs, $acc", 1455*bdd1243dSDimitry Andric "i32x4.relaxed_dot_i8x16_i7x16_add_s", 0x113>; 1456*bdd1243dSDimitry Andric 1457*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===// 1458*bdd1243dSDimitry Andric// Relaxed BFloat16 dot product 1459*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===// 1460*bdd1243dSDimitry Andric 1461*bdd1243dSDimitry Andricdefm RELAXED_DOT_BFLOAT : 1462*bdd1243dSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, V128:$acc), 1463*bdd1243dSDimitry Andric (outs), (ins), 1464*bdd1243dSDimitry Andric [(set (v4f32 V128:$dst), (int_wasm_relaxed_dot_bf16x8_add_f32 1465*bdd1243dSDimitry Andric (v8i16 V128:$lhs), (v8i16 V128:$rhs), (v4f32 V128:$acc)))], 1466*bdd1243dSDimitry Andric "f32x4.relaxed_dot_bf16x8_add_f32\t$dst, $lhs, $rhs, $acc", 1467*bdd1243dSDimitry Andric "f32x4.relaxed_dot_bf16x8_add_f32", 0x114>; 1468