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; 64bdd1243dSDimitry 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; 77bdd1243dSDimitry Andric let lane_load = extloadi8; 78bdd1243dSDimitry 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; 89bdd1243dSDimitry Andric let lane_load = extloadi16; 90bdd1243dSDimitry 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; 102bdd1243dSDimitry Andric let lane_load = load; 103bdd1243dSDimitry 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; 115bdd1243dSDimitry Andric let lane_load = load; 116bdd1243dSDimitry 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; 128bdd1243dSDimitry Andric let lane_load = load; 129bdd1243dSDimitry 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; 140bdd1243dSDimitry Andric let lane_load = load; 141bdd1243dSDimitry 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 { 168bdd1243dSDimitry 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"; 198bdd1243dSDimitry Andric defm : LoadPat<vec.vt, 199bdd1243dSDimitry Andric PatFrag<(ops node:$addr), (splat_vector (vec.lane_vt (vec.lane_load node:$addr)))>, 200bdd1243dSDimitry 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; 245bdd1243dSDimitry 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. 271bdd1243dSDimitry Andric// TODO: i16, and i8 scalars 272bdd1243dSDimitry Andricforeach vec = [I32x4, I64x2] in { 273bdd1243dSDimitry Andric defvar inst = "LOAD_ZERO_"#vec; 274bdd1243dSDimitry Andric defvar pat = PatFrag<(ops node:$addr), (scalar_to_vector (vec.lane_vt (load $addr)))>; 275bdd1243dSDimitry Andric defm : LoadPat<vec.vt, pat, inst>; 276bdd1243dSDimitry 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)>; 283bdd1243dSDimitry 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 { 364bdd1243dSDimitry 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 : 379*06c3fb27SDimitry Andric SIMD_I<(outs), 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 393bdd1243dSDimitry Andricmulticlass StoreLanePat<Vec vec, SDPatternOperator kind> { 394bdd1243dSDimitry Andric def : Pat<(kind (AddrOps32 offset32_op:$offset, I32:$addr), 395bdd1243dSDimitry Andric (vec.vt V128:$vec), 396bdd1243dSDimitry Andric (i32 vec.lane_idx:$idx)), 397bdd1243dSDimitry Andric (!cast<NI>("STORE_LANE_"#vec#"_A32") 0, $offset, imm:$idx, $addr, $vec)>, 398e8d8bef9SDimitry Andric Requires<[HasAddr32]>; 399bdd1243dSDimitry Andric def : Pat<(kind (AddrOps64 offset64_op:$offset, I64:$addr), 400bdd1243dSDimitry Andric (vec.vt V128:$vec), 401bdd1243dSDimitry Andric (i32 vec.lane_idx:$idx)), 402bdd1243dSDimitry 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 { 421bdd1243dSDimitry Andricdefm : StoreLanePat<I8x16, store8_lane>; 422bdd1243dSDimitry Andricdefm : StoreLanePat<I16x8, store16_lane>; 423bdd1243dSDimitry Andricdefm : StoreLanePat<I32x4, store32_lane>; 424bdd1243dSDimitry 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 486bdd1243dSDimitry Andric// Match splat(x) -> const.v128(x, ..., x) 487bdd1243dSDimitry Andricforeach vec = AllVecs in { 488bdd1243dSDimitry Andric defvar numEls = !div(vec.vt.Size, vec.lane_bits); 489bdd1243dSDimitry Andric defvar isFloat = !or(!eq(vec.lane_vt, f32), !eq(vec.lane_vt, f64)); 490bdd1243dSDimitry Andric defvar immKind = !if(isFloat, fpimm, imm); 491bdd1243dSDimitry Andric def : Pat<(vec.splat (vec.lane_vt immKind:$x)), 492bdd1243dSDimitry Andric !dag(!cast<NI>("CONST_V128_"#vec), 493bdd1243dSDimitry Andric !listsplat((vec.lane_vt immKind:$x), numEls), 494bdd1243dSDimitry Andric ?)>; 495bdd1243dSDimitry Andric} 496bdd1243dSDimitry 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 { 532*06c3fb27SDimitry Andric// The @llvm.wasm.shuffle intrinsic has immediate arguments that become TargetConstants. 533*06c3fb27SDimitry Andricdef : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y), 534*06c3fb27SDimitry Andric (i32 timm:$m0), (i32 timm:$m1), 535*06c3fb27SDimitry Andric (i32 timm:$m2), (i32 timm:$m3), 536*06c3fb27SDimitry Andric (i32 timm:$m4), (i32 timm:$m5), 537*06c3fb27SDimitry Andric (i32 timm:$m6), (i32 timm:$m7), 538*06c3fb27SDimitry Andric (i32 timm:$m8), (i32 timm:$m9), 539*06c3fb27SDimitry Andric (i32 timm:$mA), (i32 timm:$mB), 540*06c3fb27SDimitry Andric (i32 timm:$mC), (i32 timm:$mD), 541*06c3fb27SDimitry Andric (i32 timm:$mE), (i32 timm:$mF))), 542*06c3fb27SDimitry Andric (SHUFFLE $x, $y, 543*06c3fb27SDimitry Andric imm:$m0, imm:$m1, imm:$m2, imm:$m3, 544*06c3fb27SDimitry Andric imm:$m4, imm:$m5, imm:$m6, imm:$m7, 545*06c3fb27SDimitry Andric imm:$m8, imm:$m9, imm:$mA, imm:$mB, 546*06c3fb27SDimitry Andric imm:$mC, imm:$mD, imm:$mE, imm:$mF)>; 547*06c3fb27SDimitry Andric// Normal shufflevector instructions may have normal constant arguemnts. 548e8d8bef9SDimitry Andricdef : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y), 5490b57cec5SDimitry Andric (i32 LaneIdx32:$m0), (i32 LaneIdx32:$m1), 5500b57cec5SDimitry Andric (i32 LaneIdx32:$m2), (i32 LaneIdx32:$m3), 5510b57cec5SDimitry Andric (i32 LaneIdx32:$m4), (i32 LaneIdx32:$m5), 5520b57cec5SDimitry Andric (i32 LaneIdx32:$m6), (i32 LaneIdx32:$m7), 5530b57cec5SDimitry Andric (i32 LaneIdx32:$m8), (i32 LaneIdx32:$m9), 5540b57cec5SDimitry Andric (i32 LaneIdx32:$mA), (i32 LaneIdx32:$mB), 5550b57cec5SDimitry Andric (i32 LaneIdx32:$mC), (i32 LaneIdx32:$mD), 5560b57cec5SDimitry Andric (i32 LaneIdx32:$mE), (i32 LaneIdx32:$mF))), 557e8d8bef9SDimitry Andric (SHUFFLE $x, $y, 558e8d8bef9SDimitry Andric imm:$m0, imm:$m1, imm:$m2, imm:$m3, 559e8d8bef9SDimitry Andric imm:$m4, imm:$m5, imm:$m6, imm:$m7, 560e8d8bef9SDimitry Andric imm:$m8, imm:$m9, imm:$mA, imm:$mB, 561e8d8bef9SDimitry Andric imm:$mC, imm:$mD, imm:$mE, imm:$mF)>; 5620b57cec5SDimitry Andric} 5630b57cec5SDimitry Andric 564e8d8bef9SDimitry Andric// Swizzle lanes: i8x16.swizzle 5658bcb0991SDimitry Andricdef wasm_swizzle_t : SDTypeProfile<1, 2, []>; 5668bcb0991SDimitry Andricdef wasm_swizzle : SDNode<"WebAssemblyISD::SWIZZLE", wasm_swizzle_t>; 5678bcb0991SDimitry Andricdefm SWIZZLE : 5688bcb0991SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins), 5698bcb0991SDimitry Andric [(set (v16i8 V128:$dst), 5708bcb0991SDimitry Andric (wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))], 571e8d8bef9SDimitry Andric "i8x16.swizzle\t$dst, $src, $mask", "i8x16.swizzle", 14>; 5728bcb0991SDimitry Andric 5738bcb0991SDimitry Andricdef : Pat<(int_wasm_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)), 574e8d8bef9SDimitry Andric (SWIZZLE $src, $mask)>; 5758bcb0991SDimitry Andric 576e8d8bef9SDimitry Andricmulticlass Splat<Vec vec, bits<32> simdop> { 577e8d8bef9SDimitry Andric defm SPLAT_#vec : SIMD_I<(outs V128:$dst), (ins vec.lane_rc:$x), 578e8d8bef9SDimitry Andric (outs), (ins), 579e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 580e8d8bef9SDimitry Andric (vec.splat vec.lane_rc:$x))], 581e8d8bef9SDimitry Andric vec.prefix#".splat\t$dst, $x", vec.prefix#".splat", 582e8d8bef9SDimitry Andric simdop>; 5830b57cec5SDimitry Andric} 5840b57cec5SDimitry Andric 585e8d8bef9SDimitry Andricdefm "" : Splat<I8x16, 15>; 586e8d8bef9SDimitry Andricdefm "" : Splat<I16x8, 16>; 587e8d8bef9SDimitry Andricdefm "" : Splat<I32x4, 17>; 588e8d8bef9SDimitry Andricdefm "" : Splat<I64x2, 18>; 589e8d8bef9SDimitry Andricdefm "" : Splat<F32x4, 19>; 590e8d8bef9SDimitry Andricdefm "" : Splat<F64x2, 20>; 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andric// scalar_to_vector leaves high lanes undefined, so can be a splat 593e8d8bef9SDimitry Andricforeach vec = AllVecs in 594e8d8bef9SDimitry Andricdef : Pat<(vec.vt (scalar_to_vector (vec.lane_vt vec.lane_rc:$x))), 595e8d8bef9SDimitry Andric (!cast<Instruction>("SPLAT_"#vec) $x)>; 5960b57cec5SDimitry Andric 5970b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 5980b57cec5SDimitry Andric// Accessing lanes 5990b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6000b57cec5SDimitry Andric 6010b57cec5SDimitry Andric// Extract lane as a scalar: extract_lane / extract_lane_s / extract_lane_u 602e8d8bef9SDimitry Andricmulticlass ExtractLane<Vec vec, bits<32> simdop, string suffix = ""> { 603e8d8bef9SDimitry Andric defm EXTRACT_LANE_#vec#suffix : 604e8d8bef9SDimitry Andric SIMD_I<(outs vec.lane_rc:$dst), (ins V128:$vec, vec_i8imm_op:$idx), 6055ffd83dbSDimitry Andric (outs), (ins vec_i8imm_op:$idx), [], 606e8d8bef9SDimitry Andric vec.prefix#".extract_lane"#suffix#"\t$dst, $vec, $idx", 607e8d8bef9SDimitry Andric vec.prefix#".extract_lane"#suffix#"\t$idx", simdop>; 6080b57cec5SDimitry Andric} 6090b57cec5SDimitry Andric 610e8d8bef9SDimitry Andricdefm "" : ExtractLane<I8x16, 21, "_s">; 611e8d8bef9SDimitry Andricdefm "" : ExtractLane<I8x16, 22, "_u">; 612e8d8bef9SDimitry Andricdefm "" : ExtractLane<I16x8, 24, "_s">; 613e8d8bef9SDimitry Andricdefm "" : ExtractLane<I16x8, 25, "_u">; 614e8d8bef9SDimitry Andricdefm "" : ExtractLane<I32x4, 27>; 615e8d8bef9SDimitry Andricdefm "" : ExtractLane<I64x2, 29>; 616e8d8bef9SDimitry Andricdefm "" : ExtractLane<F32x4, 31>; 617e8d8bef9SDimitry Andricdefm "" : ExtractLane<F64x2, 33>; 6180b57cec5SDimitry Andric 6195ffd83dbSDimitry Andricdef : Pat<(vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), 620e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>; 6215ffd83dbSDimitry Andricdef : Pat<(vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), 622e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>; 6235ffd83dbSDimitry Andricdef : Pat<(vector_extract (v4i32 V128:$vec), (i32 LaneIdx4:$idx)), 624e8d8bef9SDimitry Andric (EXTRACT_LANE_I32x4 $vec, imm:$idx)>; 6255ffd83dbSDimitry Andricdef : Pat<(vector_extract (v4f32 V128:$vec), (i32 LaneIdx4:$idx)), 626e8d8bef9SDimitry Andric (EXTRACT_LANE_F32x4 $vec, imm:$idx)>; 6275ffd83dbSDimitry Andricdef : Pat<(vector_extract (v2i64 V128:$vec), (i32 LaneIdx2:$idx)), 628e8d8bef9SDimitry Andric (EXTRACT_LANE_I64x2 $vec, imm:$idx)>; 6295ffd83dbSDimitry Andricdef : Pat<(vector_extract (v2f64 V128:$vec), (i32 LaneIdx2:$idx)), 630e8d8bef9SDimitry Andric (EXTRACT_LANE_F64x2 $vec, imm:$idx)>; 6310b57cec5SDimitry Andric 6325ffd83dbSDimitry Andricdef : Pat< 6335ffd83dbSDimitry Andric (sext_inreg (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), i8), 634e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_s $vec, imm:$idx)>; 6355ffd83dbSDimitry Andricdef : Pat< 6365ffd83dbSDimitry Andric (and (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx)), (i32 0xff)), 637e8d8bef9SDimitry Andric (EXTRACT_LANE_I8x16_u $vec, imm:$idx)>; 6385ffd83dbSDimitry Andricdef : Pat< 6395ffd83dbSDimitry Andric (sext_inreg (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), i16), 640e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_s $vec, imm:$idx)>; 6415ffd83dbSDimitry Andricdef : Pat< 6425ffd83dbSDimitry Andric (and (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx)), (i32 0xffff)), 643e8d8bef9SDimitry Andric (EXTRACT_LANE_I16x8_u $vec, imm:$idx)>; 6440b57cec5SDimitry Andric 6450b57cec5SDimitry Andric// Replace lane value: replace_lane 646e8d8bef9SDimitry Andricmulticlass ReplaceLane<Vec vec, bits<32> simdop> { 647e8d8bef9SDimitry Andric defm REPLACE_LANE_#vec : 648e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$vec, vec_i8imm_op:$idx, vec.lane_rc:$x), 6490b57cec5SDimitry Andric (outs), (ins vec_i8imm_op:$idx), 6500b57cec5SDimitry Andric [(set V128:$dst, (vector_insert 651e8d8bef9SDimitry Andric (vec.vt V128:$vec), 652e8d8bef9SDimitry Andric (vec.lane_vt vec.lane_rc:$x), 653e8d8bef9SDimitry Andric (i32 vec.lane_idx:$idx)))], 654e8d8bef9SDimitry Andric vec.prefix#".replace_lane\t$dst, $vec, $idx, $x", 655e8d8bef9SDimitry Andric vec.prefix#".replace_lane\t$idx", simdop>; 6560b57cec5SDimitry Andric} 6570b57cec5SDimitry Andric 658e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I8x16, 23>; 659e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I16x8, 26>; 660e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I32x4, 28>; 661e8d8bef9SDimitry Andricdefm "" : ReplaceLane<I64x2, 30>; 662e8d8bef9SDimitry Andricdefm "" : ReplaceLane<F32x4, 32>; 663e8d8bef9SDimitry Andricdefm "" : ReplaceLane<F64x2, 34>; 6640b57cec5SDimitry Andric 6650b57cec5SDimitry Andric// Lower undef lane indices to zero 6660b57cec5SDimitry Andricdef : Pat<(vector_insert (v16i8 V128:$vec), I32:$x, undef), 667e8d8bef9SDimitry Andric (REPLACE_LANE_I8x16 $vec, 0, $x)>; 6680b57cec5SDimitry Andricdef : Pat<(vector_insert (v8i16 V128:$vec), I32:$x, undef), 669e8d8bef9SDimitry Andric (REPLACE_LANE_I16x8 $vec, 0, $x)>; 6700b57cec5SDimitry Andricdef : Pat<(vector_insert (v4i32 V128:$vec), I32:$x, undef), 671e8d8bef9SDimitry Andric (REPLACE_LANE_I32x4 $vec, 0, $x)>; 6720b57cec5SDimitry Andricdef : Pat<(vector_insert (v2i64 V128:$vec), I64:$x, undef), 673e8d8bef9SDimitry Andric (REPLACE_LANE_I64x2 $vec, 0, $x)>; 6740b57cec5SDimitry Andricdef : Pat<(vector_insert (v4f32 V128:$vec), F32:$x, undef), 675e8d8bef9SDimitry Andric (REPLACE_LANE_F32x4 $vec, 0, $x)>; 6760b57cec5SDimitry Andricdef : Pat<(vector_insert (v2f64 V128:$vec), F64:$x, undef), 677e8d8bef9SDimitry Andric (REPLACE_LANE_F64x2 $vec, 0, $x)>; 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6800b57cec5SDimitry Andric// Comparisons 6810b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6820b57cec5SDimitry Andric 683e8d8bef9SDimitry Andricmulticlass SIMDCondition<Vec vec, string name, CondCode cond, bits<32> simdop> { 684e8d8bef9SDimitry Andric defm _#vec : 6850b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 686e8d8bef9SDimitry Andric [(set (vec.int_vt V128:$dst), 687e8d8bef9SDimitry Andric (setcc (vec.vt V128:$lhs), (vec.vt V128:$rhs), cond))], 688e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 689e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 6900b57cec5SDimitry Andric} 6910b57cec5SDimitry Andric 6920b57cec5SDimitry Andricmulticlass SIMDConditionInt<string name, CondCode cond, bits<32> baseInst> { 693e8d8bef9SDimitry Andric defm "" : SIMDCondition<I8x16, name, cond, baseInst>; 694e8d8bef9SDimitry Andric defm "" : SIMDCondition<I16x8, name, cond, !add(baseInst, 10)>; 695e8d8bef9SDimitry Andric defm "" : SIMDCondition<I32x4, name, cond, !add(baseInst, 20)>; 6960b57cec5SDimitry Andric} 6970b57cec5SDimitry Andric 6980b57cec5SDimitry Andricmulticlass SIMDConditionFP<string name, CondCode cond, bits<32> baseInst> { 699e8d8bef9SDimitry Andric defm "" : SIMDCondition<F32x4, name, cond, baseInst>; 700e8d8bef9SDimitry Andric defm "" : SIMDCondition<F64x2, name, cond, !add(baseInst, 6)>; 7010b57cec5SDimitry Andric} 7020b57cec5SDimitry Andric 7030b57cec5SDimitry Andric// Equality: eq 7040b57cec5SDimitry Andriclet isCommutable = 1 in { 7055ffd83dbSDimitry Andricdefm EQ : SIMDConditionInt<"eq", SETEQ, 35>; 706fe6060f1SDimitry Andricdefm EQ : SIMDCondition<I64x2, "eq", SETEQ, 214>; 7075ffd83dbSDimitry Andricdefm EQ : SIMDConditionFP<"eq", SETOEQ, 65>; 7080b57cec5SDimitry Andric} // isCommutable = 1 7090b57cec5SDimitry Andric 7100b57cec5SDimitry Andric// Non-equality: ne 7110b57cec5SDimitry Andriclet isCommutable = 1 in { 7125ffd83dbSDimitry Andricdefm NE : SIMDConditionInt<"ne", SETNE, 36>; 713fe6060f1SDimitry Andricdefm NE : SIMDCondition<I64x2, "ne", SETNE, 215>; 7145ffd83dbSDimitry Andricdefm NE : SIMDConditionFP<"ne", SETUNE, 66>; 7150b57cec5SDimitry Andric} // isCommutable = 1 7160b57cec5SDimitry Andric 7170b57cec5SDimitry Andric// Less than: lt_s / lt_u / lt 7185ffd83dbSDimitry Andricdefm LT_S : SIMDConditionInt<"lt_s", SETLT, 37>; 719fe6060f1SDimitry Andricdefm LT_S : SIMDCondition<I64x2, "lt_s", SETLT, 216>; 7205ffd83dbSDimitry Andricdefm LT_U : SIMDConditionInt<"lt_u", SETULT, 38>; 7215ffd83dbSDimitry Andricdefm LT : SIMDConditionFP<"lt", SETOLT, 67>; 7220b57cec5SDimitry Andric 7230b57cec5SDimitry Andric// Greater than: gt_s / gt_u / gt 7245ffd83dbSDimitry Andricdefm GT_S : SIMDConditionInt<"gt_s", SETGT, 39>; 725fe6060f1SDimitry Andricdefm GT_S : SIMDCondition<I64x2, "gt_s", SETGT, 217>; 7265ffd83dbSDimitry Andricdefm GT_U : SIMDConditionInt<"gt_u", SETUGT, 40>; 7275ffd83dbSDimitry Andricdefm GT : SIMDConditionFP<"gt", SETOGT, 68>; 7280b57cec5SDimitry Andric 7290b57cec5SDimitry Andric// Less than or equal: le_s / le_u / le 7305ffd83dbSDimitry Andricdefm LE_S : SIMDConditionInt<"le_s", SETLE, 41>; 731fe6060f1SDimitry Andricdefm LE_S : SIMDCondition<I64x2, "le_s", SETLE, 218>; 7325ffd83dbSDimitry Andricdefm LE_U : SIMDConditionInt<"le_u", SETULE, 42>; 7335ffd83dbSDimitry Andricdefm LE : SIMDConditionFP<"le", SETOLE, 69>; 7340b57cec5SDimitry Andric 7350b57cec5SDimitry Andric// Greater than or equal: ge_s / ge_u / ge 7365ffd83dbSDimitry Andricdefm GE_S : SIMDConditionInt<"ge_s", SETGE, 43>; 737fe6060f1SDimitry Andricdefm GE_S : SIMDCondition<I64x2, "ge_s", SETGE, 219>; 7385ffd83dbSDimitry Andricdefm GE_U : SIMDConditionInt<"ge_u", SETUGE, 44>; 7395ffd83dbSDimitry Andricdefm GE : SIMDConditionFP<"ge", SETOGE, 70>; 7400b57cec5SDimitry Andric 7410b57cec5SDimitry Andric// Lower float comparisons that don't care about NaN to standard WebAssembly 7420b57cec5SDimitry Andric// float comparisons. These instructions are generated with nnan and in the 7430b57cec5SDimitry Andric// target-independent expansion of unordered comparisons and ordered ne. 744e8d8bef9SDimitry Andricforeach nodes = [[seteq, EQ_F32x4], [setne, NE_F32x4], [setlt, LT_F32x4], 745e8d8bef9SDimitry Andric [setgt, GT_F32x4], [setle, LE_F32x4], [setge, GE_F32x4]] in 7460b57cec5SDimitry Andricdef : Pat<(v4i32 (nodes[0] (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 747e8d8bef9SDimitry Andric (nodes[1] $lhs, $rhs)>; 7480b57cec5SDimitry Andric 749e8d8bef9SDimitry Andricforeach nodes = [[seteq, EQ_F64x2], [setne, NE_F64x2], [setlt, LT_F64x2], 750e8d8bef9SDimitry Andric [setgt, GT_F64x2], [setle, LE_F64x2], [setge, GE_F64x2]] in 7510b57cec5SDimitry Andricdef : Pat<(v2i64 (nodes[0] (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 752e8d8bef9SDimitry Andric (nodes[1] $lhs, $rhs)>; 753e8d8bef9SDimitry Andric 7540b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7550b57cec5SDimitry Andric// Bitwise operations 7560b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7570b57cec5SDimitry Andric 758fe6060f1SDimitry Andricmulticlass SIMDBinary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> { 759e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 7600b57cec5SDimitry Andric (outs), (ins), 761e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 762e8d8bef9SDimitry Andric (node (vec.vt V128:$lhs), (vec.vt V128:$rhs)))], 763e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 764e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 7650b57cec5SDimitry Andric} 7660b57cec5SDimitry Andric 767fe6060f1SDimitry Andricmulticlass SIMDBitwise<SDPatternOperator node, string name, bits<32> simdop, 768fe6060f1SDimitry Andric bit commutable = false> { 769e8d8bef9SDimitry Andric let isCommutable = commutable in 770e8d8bef9SDimitry Andric defm "" : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 771e8d8bef9SDimitry Andric (outs), (ins), [], 772e8d8bef9SDimitry Andric "v128."#name#"\t$dst, $lhs, $rhs", "v128."#name, simdop>; 773e8d8bef9SDimitry Andric foreach vec = IntVecs in 774e8d8bef9SDimitry Andric def : Pat<(node (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 775e8d8bef9SDimitry Andric (!cast<NI>(NAME) $lhs, $rhs)>; 7760b57cec5SDimitry Andric} 7770b57cec5SDimitry Andric 778fe6060f1SDimitry Andricmulticlass SIMDUnary<Vec vec, SDPatternOperator node, string name, bits<32> simdop> { 779e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins), 780e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), 781e8d8bef9SDimitry Andric (vec.vt (node (vec.vt V128:$v))))], 782e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $v", 783e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 7840b57cec5SDimitry Andric} 7850b57cec5SDimitry Andric 7860b57cec5SDimitry Andric// Bitwise logic: v128.not 787e8d8bef9SDimitry Andricdefm NOT : SIMD_I<(outs V128:$dst), (ins V128:$v), (outs), (ins), [], 788e8d8bef9SDimitry Andric "v128.not\t$dst, $v", "v128.not", 77>; 789e8d8bef9SDimitry Andricforeach vec = IntVecs in 790e8d8bef9SDimitry Andricdef : Pat<(vnot (vec.vt V128:$v)), (NOT $v)>; 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric// Bitwise logic: v128.and / v128.or / v128.xor 793e8d8bef9SDimitry Andricdefm AND : SIMDBitwise<and, "and", 78, true>; 794e8d8bef9SDimitry Andricdefm OR : SIMDBitwise<or, "or", 80, true>; 795e8d8bef9SDimitry Andricdefm XOR : SIMDBitwise<xor, "xor", 81, true>; 7960b57cec5SDimitry Andric 7978bcb0991SDimitry Andric// Bitwise logic: v128.andnot 7988bcb0991SDimitry Andricdef andnot : PatFrag<(ops node:$left, node:$right), (and $left, (vnot $right))>; 7995ffd83dbSDimitry Andricdefm ANDNOT : SIMDBitwise<andnot, "andnot", 79>; 8008bcb0991SDimitry Andric 8010b57cec5SDimitry Andric// Bitwise select: v128.bitselect 802e8d8bef9SDimitry Andricdefm BITSELECT : 803e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$v1, V128:$v2, V128:$c), (outs), (ins), [], 8045ffd83dbSDimitry Andric "v128.bitselect\t$dst, $v1, $v2, $c", "v128.bitselect", 82>; 8050b57cec5SDimitry Andric 806e8d8bef9SDimitry Andricforeach vec = AllVecs in 807e8d8bef9SDimitry Andricdef : Pat<(vec.vt (int_wasm_bitselect 808e8d8bef9SDimitry Andric (vec.vt V128:$v1), (vec.vt V128:$v2), (vec.vt V128:$c))), 809e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 810e8d8bef9SDimitry Andric 8110b57cec5SDimitry Andric// Bitselect is equivalent to (c & v1) | (~c & v2) 812e8d8bef9SDimitry Andricforeach vec = IntVecs in 813e8d8bef9SDimitry Andricdef : Pat<(vec.vt (or (and (vec.vt V128:$c), (vec.vt V128:$v1)), 814e8d8bef9SDimitry Andric (and (vnot V128:$c), (vec.vt V128:$v2)))), 815e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 816e8d8bef9SDimitry Andric 817bdd1243dSDimitry Andric// Bitselect is also equivalent to ((v1 ^ v2) & c) ^ v2 818bdd1243dSDimitry Andricforeach vec = IntVecs in 819bdd1243dSDimitry Andricdef : Pat<(vec.vt (xor (and (xor (vec.vt V128:$v1), (vec.vt V128:$v2)), 820bdd1243dSDimitry Andric (vec.vt V128:$c)), 821bdd1243dSDimitry Andric (vec.vt V128:$v2))), 822bdd1243dSDimitry Andric (BITSELECT $v1, $v2, $c)>; 823bdd1243dSDimitry Andric 824bdd1243dSDimitry Andric// Same pattern with `c` negated so `a` and `b` get swapped. 825bdd1243dSDimitry Andricforeach vec = IntVecs in 826bdd1243dSDimitry Andricdef : Pat<(vec.vt (xor (and (xor (vec.vt V128:$v1), (vec.vt V128:$v2)), 827bdd1243dSDimitry Andric (vnot (vec.vt V128:$c))), 828bdd1243dSDimitry Andric (vec.vt V128:$v2))), 829bdd1243dSDimitry Andric (BITSELECT $v2, $v1, $c)>; 830bdd1243dSDimitry Andric 831e8d8bef9SDimitry Andric// Also implement vselect in terms of bitselect 832e8d8bef9SDimitry Andricforeach vec = AllVecs in 833e8d8bef9SDimitry Andricdef : Pat<(vec.vt (vselect 834e8d8bef9SDimitry Andric (vec.int_vt V128:$c), (vec.vt V128:$v1), (vec.vt V128:$v2))), 835e8d8bef9SDimitry Andric (BITSELECT $v1, $v2, $c)>; 836e8d8bef9SDimitry Andric 837e8d8bef9SDimitry Andric// MVP select on v128 values 838e8d8bef9SDimitry Andricdefm SELECT_V128 : 839e8d8bef9SDimitry Andric I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, I32:$cond), (outs), (ins), [], 840e8d8bef9SDimitry Andric "v128.select\t$dst, $lhs, $rhs, $cond", "v128.select", 0x1b>; 841e8d8bef9SDimitry Andric 842e8d8bef9SDimitry Andricforeach vec = AllVecs in { 843e8d8bef9SDimitry Andricdef : Pat<(select I32:$cond, (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 844e8d8bef9SDimitry Andric (SELECT_V128 $lhs, $rhs, $cond)>; 845e8d8bef9SDimitry Andric 846e8d8bef9SDimitry Andric// ISD::SELECT requires its operand to conform to getBooleanContents, but 847e8d8bef9SDimitry Andric// WebAssembly's select interprets any non-zero value as true, so we can fold 848e8d8bef9SDimitry Andric// a setne with 0 into a select. 849e8d8bef9SDimitry Andricdef : Pat<(select 850e8d8bef9SDimitry Andric (i32 (setne I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 851e8d8bef9SDimitry Andric (SELECT_V128 $lhs, $rhs, $cond)>; 852e8d8bef9SDimitry Andric 853e8d8bef9SDimitry Andric// And again, this time with seteq instead of setne and the arms reversed. 854e8d8bef9SDimitry Andricdef : Pat<(select 855e8d8bef9SDimitry Andric (i32 (seteq I32:$cond, 0)), (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 856e8d8bef9SDimitry Andric (SELECT_V128 $rhs, $lhs, $cond)>; 857e8d8bef9SDimitry Andric} // foreach vec 858e8d8bef9SDimitry Andric 8590b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8600b57cec5SDimitry Andric// Integer unary arithmetic 8610b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8620b57cec5SDimitry Andric 863fe6060f1SDimitry Andricmulticlass SIMDUnaryInt<SDPatternOperator node, string name, bits<32> baseInst> { 864e8d8bef9SDimitry Andric defm "" : SIMDUnary<I8x16, node, name, baseInst>; 865e8d8bef9SDimitry Andric defm "" : SIMDUnary<I16x8, node, name, !add(baseInst, 32)>; 866e8d8bef9SDimitry Andric defm "" : SIMDUnary<I32x4, node, name, !add(baseInst, 64)>; 867e8d8bef9SDimitry Andric defm "" : SIMDUnary<I64x2, node, name, !add(baseInst, 96)>; 8680b57cec5SDimitry Andric} 8690b57cec5SDimitry Andric 8700b57cec5SDimitry Andric// Integer vector negation 871e8d8bef9SDimitry Andricdef ivneg : PatFrag<(ops node:$in), (sub immAllZerosV, $in)>; 8720b57cec5SDimitry Andric 8735ffd83dbSDimitry Andric// Integer absolute value: abs 8745ffd83dbSDimitry Andricdefm ABS : SIMDUnaryInt<abs, "abs", 96>; 8755ffd83dbSDimitry Andric 8760b57cec5SDimitry Andric// Integer negation: neg 8775ffd83dbSDimitry Andricdefm NEG : SIMDUnaryInt<ivneg, "neg", 97>; 8780b57cec5SDimitry Andric 879fe6060f1SDimitry Andric// Population count: popcnt 880fe6060f1SDimitry Andricdefm POPCNT : SIMDUnary<I8x16, ctpop, "popcnt", 0x62>; 881fe6060f1SDimitry Andric 8820b57cec5SDimitry Andric// Any lane true: any_true 883fe6060f1SDimitry Andricdefm ANYTRUE : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), [], 884fe6060f1SDimitry Andric "v128.any_true\t$dst, $vec", "v128.any_true", 0x53>; 885fe6060f1SDimitry Andric 886fe6060f1SDimitry Andricforeach vec = IntVecs in 887fe6060f1SDimitry Andricdef : Pat<(int_wasm_anytrue (vec.vt V128:$vec)), (ANYTRUE V128:$vec)>; 8880b57cec5SDimitry Andric 8890b57cec5SDimitry Andric// All lanes true: all_true 890fe6060f1SDimitry Andricmulticlass SIMDAllTrue<Vec vec, bits<32> simdop> { 891fe6060f1SDimitry Andric defm ALLTRUE_#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), 892fe6060f1SDimitry Andric [(set I32:$dst, 893fe6060f1SDimitry Andric (i32 (int_wasm_alltrue (vec.vt V128:$vec))))], 894fe6060f1SDimitry Andric vec.prefix#".all_true\t$dst, $vec", 895fe6060f1SDimitry Andric vec.prefix#".all_true", simdop>; 896fe6060f1SDimitry Andric} 8970b57cec5SDimitry Andric 898fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I8x16, 0x63>; 899fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I16x8, 0x83>; 900fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I32x4, 0xa3>; 901fe6060f1SDimitry Andricdefm "" : SIMDAllTrue<I64x2, 0xc3>; 902e8d8bef9SDimitry Andric 9030b57cec5SDimitry Andric// Reductions already return 0 or 1, so and 1, setne 0, and seteq 1 9040b57cec5SDimitry Andric// can be folded out 9050b57cec5SDimitry Andricforeach reduction = 906fe6060f1SDimitry Andric [["int_wasm_anytrue", "ANYTRUE", "I8x16"], 907fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I16x8"], 908fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I32x4"], 909fe6060f1SDimitry Andric ["int_wasm_anytrue", "ANYTRUE", "I64x2"], 910fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I8x16", "I8x16"], 911fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I16x8", "I16x8"], 912fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I32x4", "I32x4"], 913fe6060f1SDimitry Andric ["int_wasm_alltrue", "ALLTRUE_I64x2", "I64x2"]] in { 914e8d8bef9SDimitry Andricdefvar intrinsic = !cast<Intrinsic>(reduction[0]); 915fe6060f1SDimitry Andricdefvar inst = !cast<NI>(reduction[1]); 916fe6060f1SDimitry Andricdefvar vec = !cast<Vec>(reduction[2]); 917e8d8bef9SDimitry Andricdef : Pat<(i32 (and (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>; 918e8d8bef9SDimitry Andricdef : Pat<(i32 (setne (i32 (intrinsic (vec.vt V128:$x))), (i32 0))), (inst $x)>; 919e8d8bef9SDimitry Andricdef : Pat<(i32 (seteq (i32 (intrinsic (vec.vt V128:$x))), (i32 1))), (inst $x)>; 9200b57cec5SDimitry Andric} 9210b57cec5SDimitry Andric 922e8d8bef9SDimitry Andricmulticlass SIMDBitmask<Vec vec, bits<32> simdop> { 923e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), 9245ffd83dbSDimitry Andric [(set I32:$dst, 925e8d8bef9SDimitry Andric (i32 (int_wasm_bitmask (vec.vt V128:$vec))))], 926e8d8bef9SDimitry Andric vec.prefix#".bitmask\t$dst, $vec", vec.prefix#".bitmask", 927e8d8bef9SDimitry Andric simdop>; 9285ffd83dbSDimitry Andric} 9295ffd83dbSDimitry Andric 930e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I8x16, 100>; 931e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I16x8, 132>; 932e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I32x4, 164>; 933e8d8bef9SDimitry Andricdefm BITMASK : SIMDBitmask<I64x2, 196>; 9345ffd83dbSDimitry Andric 9350b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9360b57cec5SDimitry Andric// Bit shifts 9370b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9380b57cec5SDimitry Andric 939e8d8bef9SDimitry Andricmulticlass SIMDShift<Vec vec, SDNode node, string name, bits<32> simdop> { 940e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$vec, I32:$x), (outs), (ins), 941e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (node V128:$vec, I32:$x))], 942e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec, $x", 943e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 9440b57cec5SDimitry Andric} 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andricmulticlass SIMDShiftInt<SDNode node, string name, bits<32> baseInst> { 947e8d8bef9SDimitry Andric defm "" : SIMDShift<I8x16, node, name, baseInst>; 948e8d8bef9SDimitry Andric defm "" : SIMDShift<I16x8, node, name, !add(baseInst, 32)>; 949e8d8bef9SDimitry Andric defm "" : SIMDShift<I32x4, node, name, !add(baseInst, 64)>; 950e8d8bef9SDimitry Andric defm "" : SIMDShift<I64x2, node, name, !add(baseInst, 96)>; 9510b57cec5SDimitry Andric} 9520b57cec5SDimitry Andric 9535ffd83dbSDimitry Andric// WebAssembly SIMD shifts are nonstandard in that the shift amount is 9545ffd83dbSDimitry Andric// an i32 rather than a vector, so they need custom nodes. 955e8d8bef9SDimitry Andricdef wasm_shift_t : 956e8d8bef9SDimitry Andric SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, i32>]>; 9570b57cec5SDimitry Andricdef wasm_shl : SDNode<"WebAssemblyISD::VEC_SHL", wasm_shift_t>; 9580b57cec5SDimitry Andricdef wasm_shr_s : SDNode<"WebAssemblyISD::VEC_SHR_S", wasm_shift_t>; 9590b57cec5SDimitry Andricdef wasm_shr_u : SDNode<"WebAssemblyISD::VEC_SHR_U", wasm_shift_t>; 9605ffd83dbSDimitry Andric 9615ffd83dbSDimitry Andric// Left shift by scalar: shl 9625ffd83dbSDimitry Andricdefm SHL : SIMDShiftInt<wasm_shl, "shl", 107>; 9635ffd83dbSDimitry Andric 9645ffd83dbSDimitry Andric// Right shift by scalar: shr_s / shr_u 9655ffd83dbSDimitry Andricdefm SHR_S : SIMDShiftInt<wasm_shr_s, "shr_s", 108>; 9665ffd83dbSDimitry Andricdefm SHR_U : SIMDShiftInt<wasm_shr_u, "shr_u", 109>; 9670b57cec5SDimitry Andric 968fe6060f1SDimitry Andric// Optimize away an explicit mask on a shift count. 969fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v16i8 V128:$lhs), (and I32:$rhs, 7)), 970fe6060f1SDimitry Andric (SHL_I8x16 V128:$lhs, I32:$rhs)>; 971fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v16i8 V128:$lhs), (and I32:$rhs, 7)), 972fe6060f1SDimitry Andric (SHR_S_I8x16 V128:$lhs, I32:$rhs)>; 973fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v16i8 V128:$lhs), (and I32:$rhs, 7)), 974fe6060f1SDimitry Andric (SHR_U_I8x16 V128:$lhs, I32:$rhs)>; 975fe6060f1SDimitry Andric 976fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v8i16 V128:$lhs), (and I32:$rhs, 15)), 977fe6060f1SDimitry Andric (SHL_I16x8 V128:$lhs, I32:$rhs)>; 978fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v8i16 V128:$lhs), (and I32:$rhs, 15)), 979fe6060f1SDimitry Andric (SHR_S_I16x8 V128:$lhs, I32:$rhs)>; 980fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v8i16 V128:$lhs), (and I32:$rhs, 15)), 981fe6060f1SDimitry Andric (SHR_U_I16x8 V128:$lhs, I32:$rhs)>; 982fe6060f1SDimitry Andric 983fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v4i32 V128:$lhs), (and I32:$rhs, 31)), 984fe6060f1SDimitry Andric (SHL_I32x4 V128:$lhs, I32:$rhs)>; 985fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v4i32 V128:$lhs), (and I32:$rhs, 31)), 986fe6060f1SDimitry Andric (SHR_S_I32x4 V128:$lhs, I32:$rhs)>; 987fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v4i32 V128:$lhs), (and I32:$rhs, 31)), 988fe6060f1SDimitry Andric (SHR_U_I32x4 V128:$lhs, I32:$rhs)>; 989fe6060f1SDimitry Andric 990*06c3fb27SDimitry Andricdef : Pat<(wasm_shl (v2i64 V128:$lhs), (and I32:$rhs, 63)), 991*06c3fb27SDimitry Andric (SHL_I64x2 V128:$lhs, I32:$rhs)>; 992*06c3fb27SDimitry Andricdef : Pat<(wasm_shr_s (v2i64 V128:$lhs), (and I32:$rhs, 63)), 993*06c3fb27SDimitry Andric (SHR_S_I64x2 V128:$lhs, I32:$rhs)>; 994*06c3fb27SDimitry Andricdef : Pat<(wasm_shr_u (v2i64 V128:$lhs), (and I32:$rhs, 63)), 995*06c3fb27SDimitry Andric (SHR_U_I64x2 V128:$lhs, I32:$rhs)>; 996fe6060f1SDimitry Andricdef : Pat<(wasm_shl (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 997fe6060f1SDimitry Andric (SHL_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 998fe6060f1SDimitry Andricdef : Pat<(wasm_shr_s (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 999fe6060f1SDimitry Andric (SHR_S_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 1000fe6060f1SDimitry Andricdef : Pat<(wasm_shr_u (v2i64 V128:$lhs), (trunc (and I64:$rhs, 63))), 1001fe6060f1SDimitry Andric (SHR_U_I64x2 V128:$lhs, (I32_WRAP_I64 I64:$rhs))>; 1002fe6060f1SDimitry Andric 10030b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 10040b57cec5SDimitry Andric// Integer binary arithmetic 10050b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 10060b57cec5SDimitry Andric 1007fe6060f1SDimitry Andricmulticlass SIMDBinaryIntNoI8x16<SDPatternOperator node, string name, bits<32> baseInst> { 1008e8d8bef9SDimitry Andric defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>; 1009e8d8bef9SDimitry Andric defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>; 1010e8d8bef9SDimitry Andric defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>; 10115ffd83dbSDimitry Andric} 10125ffd83dbSDimitry Andric 1013fe6060f1SDimitry Andricmulticlass SIMDBinaryIntSmall<SDPatternOperator node, string name, bits<32> baseInst> { 1014e8d8bef9SDimitry Andric defm "" : SIMDBinary<I8x16, node, name, baseInst>; 1015e8d8bef9SDimitry Andric defm "" : SIMDBinary<I16x8, node, name, !add(baseInst, 32)>; 10160b57cec5SDimitry Andric} 10170b57cec5SDimitry Andric 1018fe6060f1SDimitry Andricmulticlass SIMDBinaryIntNoI64x2<SDPatternOperator node, string name, bits<32> baseInst> { 10190b57cec5SDimitry Andric defm "" : SIMDBinaryIntSmall<node, name, baseInst>; 1020e8d8bef9SDimitry Andric defm "" : SIMDBinary<I32x4, node, name, !add(baseInst, 64)>; 10210b57cec5SDimitry Andric} 10220b57cec5SDimitry Andric 1023fe6060f1SDimitry Andricmulticlass SIMDBinaryInt<SDPatternOperator node, string name, bits<32> baseInst> { 10240b57cec5SDimitry Andric defm "" : SIMDBinaryIntNoI64x2<node, name, baseInst>; 1025e8d8bef9SDimitry Andric defm "" : SIMDBinary<I64x2, node, name, !add(baseInst, 96)>; 10260b57cec5SDimitry Andric} 10270b57cec5SDimitry Andric 1028fe6060f1SDimitry Andric// Integer addition: add / add_sat_s / add_sat_u 10290b57cec5SDimitry Andriclet isCommutable = 1 in { 10305ffd83dbSDimitry Andricdefm ADD : SIMDBinaryInt<add, "add", 110>; 1031fe6060f1SDimitry Andricdefm ADD_SAT_S : SIMDBinaryIntSmall<saddsat, "add_sat_s", 111>; 1032fe6060f1SDimitry Andricdefm ADD_SAT_U : SIMDBinaryIntSmall<uaddsat, "add_sat_u", 112>; 10330b57cec5SDimitry Andric} // isCommutable = 1 10340b57cec5SDimitry Andric 1035fe6060f1SDimitry Andric// Integer subtraction: sub / sub_sat_s / sub_sat_u 10365ffd83dbSDimitry Andricdefm SUB : SIMDBinaryInt<sub, "sub", 113>; 10370b57cec5SDimitry Andricdefm SUB_SAT_S : 1038fe6060f1SDimitry Andric SIMDBinaryIntSmall<int_wasm_sub_sat_signed, "sub_sat_s", 114>; 10390b57cec5SDimitry Andricdefm SUB_SAT_U : 1040fe6060f1SDimitry Andric SIMDBinaryIntSmall<int_wasm_sub_sat_unsigned, "sub_sat_u", 115>; 10410b57cec5SDimitry Andric 10420b57cec5SDimitry Andric// Integer multiplication: mul 1043480093f4SDimitry Andriclet isCommutable = 1 in 10445ffd83dbSDimitry Andricdefm MUL : SIMDBinaryIntNoI8x16<mul, "mul", 117>; 10450b57cec5SDimitry Andric 1046480093f4SDimitry Andric// Integer min_s / min_u / max_s / max_u 1047480093f4SDimitry Andriclet isCommutable = 1 in { 10485ffd83dbSDimitry Andricdefm MIN_S : SIMDBinaryIntNoI64x2<smin, "min_s", 118>; 10495ffd83dbSDimitry Andricdefm MIN_U : SIMDBinaryIntNoI64x2<umin, "min_u", 119>; 10505ffd83dbSDimitry Andricdefm MAX_S : SIMDBinaryIntNoI64x2<smax, "max_s", 120>; 10515ffd83dbSDimitry Andricdefm MAX_U : SIMDBinaryIntNoI64x2<umax, "max_u", 121>; 1052480093f4SDimitry Andric} // isCommutable = 1 1053480093f4SDimitry Andric 1054480093f4SDimitry Andric// Integer unsigned rounding average: avgr_u 10555ffd83dbSDimitry Andriclet isCommutable = 1 in { 1056e8d8bef9SDimitry Andricdefm AVGR_U : SIMDBinary<I8x16, int_wasm_avgr_unsigned, "avgr_u", 123>; 1057e8d8bef9SDimitry Andricdefm AVGR_U : SIMDBinary<I16x8, int_wasm_avgr_unsigned, "avgr_u", 155>; 1058480093f4SDimitry Andric} 1059480093f4SDimitry Andric 1060e8d8bef9SDimitry Andricdef add_nuw : PatFrag<(ops node:$lhs, node:$rhs), (add $lhs, $rhs), 1061480093f4SDimitry Andric "return N->getFlags().hasNoUnsignedWrap();">; 1062480093f4SDimitry Andric 1063e8d8bef9SDimitry Andricforeach vec = [I8x16, I16x8] in { 1064e8d8bef9SDimitry Andricdefvar inst = !cast<NI>("AVGR_U_"#vec); 10655ffd83dbSDimitry Andricdef : Pat<(wasm_shr_u 1066480093f4SDimitry Andric (add_nuw 1067e8d8bef9SDimitry Andric (add_nuw (vec.vt V128:$lhs), (vec.vt V128:$rhs)), 1068e8d8bef9SDimitry Andric (vec.splat (i32 1))), 1069e8d8bef9SDimitry Andric (i32 1)), 1070e8d8bef9SDimitry Andric (inst $lhs, $rhs)>; 1071e8d8bef9SDimitry Andric} 1072480093f4SDimitry Andric 1073480093f4SDimitry Andric// Widening dot product: i32x4.dot_i16x8_s 1074480093f4SDimitry Andriclet isCommutable = 1 in 1075480093f4SDimitry Andricdefm DOT : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 1076480093f4SDimitry Andric [(set V128:$dst, (int_wasm_dot V128:$lhs, V128:$rhs))], 1077480093f4SDimitry Andric "i32x4.dot_i16x8_s\t$dst, $lhs, $rhs", "i32x4.dot_i16x8_s", 1078e8d8bef9SDimitry Andric 186>; 1079e8d8bef9SDimitry Andric 1080e8d8bef9SDimitry Andric// Extending multiplication: extmul_{low,high}_P, extmul_high 1081fe6060f1SDimitry Andricdef extend_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1082fe6060f1SDimitry Andricdef extend_low_s : SDNode<"WebAssemblyISD::EXTEND_LOW_S", extend_t>; 1083fe6060f1SDimitry Andricdef extend_high_s : SDNode<"WebAssemblyISD::EXTEND_HIGH_S", extend_t>; 1084fe6060f1SDimitry Andricdef extend_low_u : SDNode<"WebAssemblyISD::EXTEND_LOW_U", extend_t>; 1085fe6060f1SDimitry Andricdef extend_high_u : SDNode<"WebAssemblyISD::EXTEND_HIGH_U", extend_t>; 1086fe6060f1SDimitry Andric 1087fe6060f1SDimitry Andricmulticlass SIMDExtBinary<Vec vec, SDPatternOperator node, string name, 1088fe6060f1SDimitry Andric bits<32> simdop> { 1089e8d8bef9SDimitry Andric defm _#vec : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 1090e8d8bef9SDimitry Andric (outs), (ins), 1091e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (node 1092e8d8bef9SDimitry Andric (vec.split.vt V128:$lhs),(vec.split.vt V128:$rhs)))], 1093e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 1094e8d8bef9SDimitry Andric vec.prefix#"."#name, simdop>; 1095e8d8bef9SDimitry Andric} 1096e8d8bef9SDimitry Andric 1097fe6060f1SDimitry Andricclass ExtMulPat<SDNode extend> : 1098fe6060f1SDimitry Andric PatFrag<(ops node:$lhs, node:$rhs), 1099fe6060f1SDimitry Andric (mul (extend $lhs), (extend $rhs))> {} 1100fe6060f1SDimitry Andric 1101fe6060f1SDimitry Andricdef extmul_low_s : ExtMulPat<extend_low_s>; 1102fe6060f1SDimitry Andricdef extmul_high_s : ExtMulPat<extend_high_s>; 1103fe6060f1SDimitry Andricdef extmul_low_u : ExtMulPat<extend_low_u>; 1104fe6060f1SDimitry Andricdef extmul_high_u : ExtMulPat<extend_high_u>; 1105e8d8bef9SDimitry Andric 1106e8d8bef9SDimitry Andricdefm EXTMUL_LOW_S : 1107fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_low_s, "extmul_low_i8x16_s", 0x9c>; 1108e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_S : 1109fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_high_s, "extmul_high_i8x16_s", 0x9d>; 1110e8d8bef9SDimitry Andricdefm EXTMUL_LOW_U : 1111fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_low_u, "extmul_low_i8x16_u", 0x9e>; 1112e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_U : 1113fe6060f1SDimitry Andric SIMDExtBinary<I16x8, extmul_high_u, "extmul_high_i8x16_u", 0x9f>; 1114e8d8bef9SDimitry Andric 1115e8d8bef9SDimitry Andricdefm EXTMUL_LOW_S : 1116fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_low_s, "extmul_low_i16x8_s", 0xbc>; 1117e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_S : 1118fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_high_s, "extmul_high_i16x8_s", 0xbd>; 1119e8d8bef9SDimitry Andricdefm EXTMUL_LOW_U : 1120fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_low_u, "extmul_low_i16x8_u", 0xbe>; 1121e8d8bef9SDimitry Andricdefm EXTMUL_HIGH_U : 1122fe6060f1SDimitry Andric SIMDExtBinary<I32x4, extmul_high_u, "extmul_high_i16x8_u", 0xbf>; 1123fe6060f1SDimitry Andric 1124fe6060f1SDimitry Andricdefm EXTMUL_LOW_S : 1125fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_low_s, "extmul_low_i32x4_s", 0xdc>; 1126fe6060f1SDimitry Andricdefm EXTMUL_HIGH_S : 1127fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_high_s, "extmul_high_i32x4_s", 0xdd>; 1128fe6060f1SDimitry Andricdefm EXTMUL_LOW_U : 1129fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_low_u, "extmul_low_i32x4_u", 0xde>; 1130fe6060f1SDimitry Andricdefm EXTMUL_HIGH_U : 1131fe6060f1SDimitry Andric SIMDExtBinary<I64x2, extmul_high_u, "extmul_high_i32x4_u", 0xdf>; 1132480093f4SDimitry Andric 11330b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11340b57cec5SDimitry Andric// Floating-point unary arithmetic 11350b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andricmulticlass SIMDUnaryFP<SDNode node, string name, bits<32> baseInst> { 1138e8d8bef9SDimitry Andric defm "" : SIMDUnary<F32x4, node, name, baseInst>; 1139e8d8bef9SDimitry Andric defm "" : SIMDUnary<F64x2, node, name, !add(baseInst, 12)>; 11400b57cec5SDimitry Andric} 11410b57cec5SDimitry Andric 11420b57cec5SDimitry Andric// Absolute value: abs 11435ffd83dbSDimitry Andricdefm ABS : SIMDUnaryFP<fabs, "abs", 224>; 11440b57cec5SDimitry Andric 11450b57cec5SDimitry Andric// Negation: neg 11465ffd83dbSDimitry Andricdefm NEG : SIMDUnaryFP<fneg, "neg", 225>; 11470b57cec5SDimitry Andric 11480b57cec5SDimitry Andric// Square root: sqrt 11495ffd83dbSDimitry Andricdefm SQRT : SIMDUnaryFP<fsqrt, "sqrt", 227>; 11505ffd83dbSDimitry Andric 11515ffd83dbSDimitry Andric// Rounding: ceil, floor, trunc, nearest 1152fe6060f1SDimitry Andricdefm CEIL : SIMDUnary<F32x4, fceil, "ceil", 0x67>; 1153fe6060f1SDimitry Andricdefm FLOOR : SIMDUnary<F32x4, ffloor, "floor", 0x68>; 1154fe6060f1SDimitry Andricdefm TRUNC: SIMDUnary<F32x4, ftrunc, "trunc", 0x69>; 1155fe6060f1SDimitry Andricdefm NEAREST: SIMDUnary<F32x4, fnearbyint, "nearest", 0x6a>; 1156fe6060f1SDimitry Andricdefm CEIL : SIMDUnary<F64x2, fceil, "ceil", 0x74>; 1157fe6060f1SDimitry Andricdefm FLOOR : SIMDUnary<F64x2, ffloor, "floor", 0x75>; 1158fe6060f1SDimitry Andricdefm TRUNC: SIMDUnary<F64x2, ftrunc, "trunc", 0x7a>; 1159fe6060f1SDimitry Andricdefm NEAREST: SIMDUnary<F64x2, fnearbyint, "nearest", 0x94>; 11600b57cec5SDimitry Andric 1161*06c3fb27SDimitry Andric// WebAssembly doesn't expose inexact exceptions, so map frint to fnearbyint. 1162*06c3fb27SDimitry Andricdef : Pat<(v4f32 (frint (v4f32 V128:$src))), (NEAREST_F32x4 V128:$src)>; 1163*06c3fb27SDimitry Andricdef : Pat<(v2f64 (frint (v2f64 V128:$src))), (NEAREST_F64x2 V128:$src)>; 1164*06c3fb27SDimitry Andric 1165*06c3fb27SDimitry Andric// WebAssembly always rounds ties-to-even, so map froundeven to fnearbyint. 1166*06c3fb27SDimitry Andricdef : Pat<(v4f32 (froundeven (v4f32 V128:$src))), (NEAREST_F32x4 V128:$src)>; 1167*06c3fb27SDimitry Andricdef : Pat<(v2f64 (froundeven (v2f64 V128:$src))), (NEAREST_F64x2 V128:$src)>; 1168*06c3fb27SDimitry Andric 11690b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11700b57cec5SDimitry Andric// Floating-point binary arithmetic 11710b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 11720b57cec5SDimitry Andric 1173fe6060f1SDimitry Andricmulticlass SIMDBinaryFP<SDPatternOperator node, string name, bits<32> baseInst> { 1174e8d8bef9SDimitry Andric defm "" : SIMDBinary<F32x4, node, name, baseInst>; 1175e8d8bef9SDimitry Andric defm "" : SIMDBinary<F64x2, node, name, !add(baseInst, 12)>; 11760b57cec5SDimitry Andric} 11770b57cec5SDimitry Andric 11780b57cec5SDimitry Andric// Addition: add 11790b57cec5SDimitry Andriclet isCommutable = 1 in 11805ffd83dbSDimitry Andricdefm ADD : SIMDBinaryFP<fadd, "add", 228>; 11810b57cec5SDimitry Andric 11820b57cec5SDimitry Andric// Subtraction: sub 11835ffd83dbSDimitry Andricdefm SUB : SIMDBinaryFP<fsub, "sub", 229>; 11840b57cec5SDimitry Andric 11850b57cec5SDimitry Andric// Multiplication: mul 11860b57cec5SDimitry Andriclet isCommutable = 1 in 11875ffd83dbSDimitry Andricdefm MUL : SIMDBinaryFP<fmul, "mul", 230>; 11880b57cec5SDimitry Andric 11890b57cec5SDimitry Andric// Division: div 11905ffd83dbSDimitry Andricdefm DIV : SIMDBinaryFP<fdiv, "div", 231>; 11910b57cec5SDimitry Andric 11920b57cec5SDimitry Andric// NaN-propagating minimum: min 11935ffd83dbSDimitry Andricdefm MIN : SIMDBinaryFP<fminimum, "min", 232>; 11940b57cec5SDimitry Andric 11950b57cec5SDimitry Andric// NaN-propagating maximum: max 11965ffd83dbSDimitry Andricdefm MAX : SIMDBinaryFP<fmaximum, "max", 233>; 11975ffd83dbSDimitry Andric 11985ffd83dbSDimitry Andric// Pseudo-minimum: pmin 1199*06c3fb27SDimitry Andricdef pmin : PatFrags<(ops node:$lhs, node:$rhs), [ 1200*06c3fb27SDimitry Andric (vselect (setolt $rhs, $lhs), $rhs, $lhs), 1201*06c3fb27SDimitry Andric (vselect (setole $rhs, $lhs), $rhs, $lhs), 1202*06c3fb27SDimitry Andric (vselect (setogt $lhs, $rhs), $rhs, $lhs), 1203*06c3fb27SDimitry Andric (vselect (setoge $lhs, $rhs), $rhs, $lhs) 1204*06c3fb27SDimitry Andric]>; 1205fe6060f1SDimitry Andricdefm PMIN : SIMDBinaryFP<pmin, "pmin", 234>; 12065ffd83dbSDimitry Andric 12075ffd83dbSDimitry Andric// Pseudo-maximum: pmax 1208*06c3fb27SDimitry Andricdef pmax : PatFrags<(ops node:$lhs, node:$rhs), [ 1209*06c3fb27SDimitry Andric (vselect (setogt $rhs, $lhs), $rhs, $lhs), 1210*06c3fb27SDimitry Andric (vselect (setoge $rhs, $lhs), $rhs, $lhs), 1211*06c3fb27SDimitry Andric (vselect (setolt $lhs, $rhs), $rhs, $lhs), 1212*06c3fb27SDimitry Andric (vselect (setole $lhs, $rhs), $rhs, $lhs) 1213*06c3fb27SDimitry Andric]>; 1214fe6060f1SDimitry Andricdefm PMAX : SIMDBinaryFP<pmax, "pmax", 235>; 1215fe6060f1SDimitry Andric 1216fe6060f1SDimitry Andric// Also match the pmin/pmax cases where the operands are int vectors (but the 1217fe6060f1SDimitry Andric// comparison is still a floating point comparison). This can happen when using 1218fe6060f1SDimitry Andric// the wasm_simd128.h intrinsics because v128_t is an integer vector. 1219fe6060f1SDimitry Andricforeach vec = [F32x4, F64x2] in { 1220fe6060f1SDimitry Andricdefvar pmin = !cast<NI>("PMIN_"#vec); 1221fe6060f1SDimitry Andricdefvar pmax = !cast<NI>("PMAX_"#vec); 1222fe6060f1SDimitry Andricdef : Pat<(vec.int_vt (vselect 1223fe6060f1SDimitry Andric (setolt (vec.vt (bitconvert V128:$rhs)), 1224fe6060f1SDimitry Andric (vec.vt (bitconvert V128:$lhs))), 1225fe6060f1SDimitry Andric V128:$rhs, V128:$lhs)), 1226fe6060f1SDimitry Andric (pmin $lhs, $rhs)>; 1227fe6060f1SDimitry Andricdef : Pat<(vec.int_vt (vselect 1228fe6060f1SDimitry Andric (setolt (vec.vt (bitconvert V128:$lhs)), 1229fe6060f1SDimitry Andric (vec.vt (bitconvert V128:$rhs))), 1230fe6060f1SDimitry Andric V128:$rhs, V128:$lhs)), 1231fe6060f1SDimitry Andric (pmax $lhs, $rhs)>; 1232fe6060f1SDimitry Andric} 12330b57cec5SDimitry Andric 1234349cc55cSDimitry Andric// And match the pmin/pmax LLVM intrinsics as well 1235349cc55cSDimitry Andricdef : Pat<(v4f32 (int_wasm_pmin (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 1236349cc55cSDimitry Andric (PMIN_F32x4 V128:$lhs, V128:$rhs)>; 1237349cc55cSDimitry Andricdef : Pat<(v4f32 (int_wasm_pmax (v4f32 V128:$lhs), (v4f32 V128:$rhs))), 1238349cc55cSDimitry Andric (PMAX_F32x4 V128:$lhs, V128:$rhs)>; 1239349cc55cSDimitry Andricdef : Pat<(v2f64 (int_wasm_pmin (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 1240349cc55cSDimitry Andric (PMIN_F64x2 V128:$lhs, V128:$rhs)>; 1241349cc55cSDimitry Andricdef : Pat<(v2f64 (int_wasm_pmax (v2f64 V128:$lhs), (v2f64 V128:$rhs))), 1242349cc55cSDimitry Andric (PMAX_F64x2 V128:$lhs, V128:$rhs)>; 1243349cc55cSDimitry Andric 12440b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12450b57cec5SDimitry Andric// Conversions 12460b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12470b57cec5SDimitry Andric 1248fe6060f1SDimitry Andricmulticlass SIMDConvert<Vec vec, Vec arg, SDPatternOperator op, string name, 1249e8d8bef9SDimitry Andric bits<32> simdop> { 1250e8d8bef9SDimitry Andric defm op#_#vec : 12510b57cec5SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins), 1252e8d8bef9SDimitry Andric [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))], 1253e8d8bef9SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>; 12540b57cec5SDimitry Andric} 12550b57cec5SDimitry Andric 12560b57cec5SDimitry Andric// Floating point to integer with saturation: trunc_sat 1257e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, F32x4, fp_to_sint, "trunc_sat_f32x4_s", 248>; 1258e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, F32x4, fp_to_uint, "trunc_sat_f32x4_u", 249>; 12595ffd83dbSDimitry Andric 1260fe6060f1SDimitry Andric// Support the saturating variety as well. 1261fe6060f1SDimitry Andricdef trunc_s_sat32 : PatFrag<(ops node:$x), (fp_to_sint_sat $x, i32)>; 1262fe6060f1SDimitry Andricdef trunc_u_sat32 : PatFrag<(ops node:$x), (fp_to_uint_sat $x, i32)>; 1263fe6060f1SDimitry Andricdef : Pat<(v4i32 (trunc_s_sat32 (v4f32 V128:$src))), (fp_to_sint_I32x4 $src)>; 1264fe6060f1SDimitry Andricdef : Pat<(v4i32 (trunc_u_sat32 (v4f32 V128:$src))), (fp_to_uint_I32x4 $src)>; 1265fe6060f1SDimitry Andric 1266fe6060f1SDimitry Andricdef trunc_sat_zero_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1267fe6060f1SDimitry Andricdef trunc_sat_zero_s : 1268fe6060f1SDimitry Andric SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_S", trunc_sat_zero_t>; 1269fe6060f1SDimitry Andricdef trunc_sat_zero_u : 1270fe6060f1SDimitry Andric SDNode<"WebAssemblyISD::TRUNC_SAT_ZERO_U", trunc_sat_zero_t>; 127181ad6265SDimitry Andricdefm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_s, "trunc_sat_f64x2_s_zero", 1272fe6060f1SDimitry Andric 0xfc>; 127381ad6265SDimitry Andricdefm "" : SIMDConvert<I32x4, F64x2, trunc_sat_zero_u, "trunc_sat_f64x2_u_zero", 1274fe6060f1SDimitry Andric 0xfd>; 1275fe6060f1SDimitry Andric 12765ffd83dbSDimitry Andric// Integer to floating point: convert 1277fe6060f1SDimitry Andricdef convert_low_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1278fe6060f1SDimitry Andricdef convert_low_s : SDNode<"WebAssemblyISD::CONVERT_LOW_S", convert_low_t>; 1279fe6060f1SDimitry Andricdef convert_low_u : SDNode<"WebAssemblyISD::CONVERT_LOW_U", convert_low_t>; 1280e8d8bef9SDimitry Andricdefm "" : SIMDConvert<F32x4, I32x4, sint_to_fp, "convert_i32x4_s", 250>; 1281e8d8bef9SDimitry Andricdefm "" : SIMDConvert<F32x4, I32x4, uint_to_fp, "convert_i32x4_u", 251>; 1282fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, I32x4, convert_low_s, "convert_low_i32x4_s", 0xfe>; 1283fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, I32x4, convert_low_u, "convert_low_i32x4_u", 0xff>; 12848bcb0991SDimitry Andric 1285fe6060f1SDimitry Andric// Extending operations 1286e8d8bef9SDimitry Andric// TODO: refactor this to be uniform for i64x2 if the numbering is not changed. 1287fe6060f1SDimitry Andricmulticlass SIMDExtend<Vec vec, bits<32> baseInst> { 1288fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_low_s, 1289fe6060f1SDimitry Andric "extend_low_"#vec.split.prefix#"_s", baseInst>; 1290fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_high_s, 1291fe6060f1SDimitry Andric "extend_high_"#vec.split.prefix#"_s", !add(baseInst, 1)>; 1292fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_low_u, 1293fe6060f1SDimitry Andric "extend_low_"#vec.split.prefix#"_u", !add(baseInst, 2)>; 1294fe6060f1SDimitry Andric defm "" : SIMDConvert<vec, vec.split, extend_high_u, 1295fe6060f1SDimitry Andric "extend_high_"#vec.split.prefix#"_u", !add(baseInst, 3)>; 1296e8d8bef9SDimitry Andric} 1297e8d8bef9SDimitry Andric 1298fe6060f1SDimitry Andricdefm "" : SIMDExtend<I16x8, 0x87>; 1299fe6060f1SDimitry Andricdefm "" : SIMDExtend<I32x4, 0xa7>; 1300fe6060f1SDimitry Andricdefm "" : SIMDExtend<I64x2, 0xc7>; 1301e8d8bef9SDimitry Andric 1302e8d8bef9SDimitry Andric// Narrowing operations 1303e8d8bef9SDimitry Andricmulticlass SIMDNarrow<Vec vec, bits<32> baseInst> { 1304e8d8bef9SDimitry Andric defvar name = vec.split.prefix#".narrow_"#vec.prefix; 1305e8d8bef9SDimitry Andric defm NARROW_S_#vec.split : 1306e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins), 1307e8d8bef9SDimitry Andric [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_signed 1308e8d8bef9SDimitry Andric (vec.vt V128:$low), (vec.vt V128:$high))))], 1309e8d8bef9SDimitry Andric name#"_s\t$dst, $low, $high", name#"_s", baseInst>; 1310e8d8bef9SDimitry Andric defm NARROW_U_#vec.split : 1311e8d8bef9SDimitry Andric SIMD_I<(outs V128:$dst), (ins V128:$low, V128:$high), (outs), (ins), 1312e8d8bef9SDimitry Andric [(set (vec.split.vt V128:$dst), (vec.split.vt (int_wasm_narrow_unsigned 1313e8d8bef9SDimitry Andric (vec.vt V128:$low), (vec.vt V128:$high))))], 1314e8d8bef9SDimitry Andric name#"_u\t$dst, $low, $high", name#"_u", !add(baseInst, 1)>; 1315e8d8bef9SDimitry Andric} 1316e8d8bef9SDimitry Andric 1317e8d8bef9SDimitry Andricdefm "" : SIMDNarrow<I16x8, 101>; 1318e8d8bef9SDimitry Andricdefm "" : SIMDNarrow<I32x4, 133>; 1319e8d8bef9SDimitry Andric 13200eae32dcSDimitry Andric// WebAssemblyISD::NARROW_U 13210eae32dcSDimitry Andricdef wasm_narrow_t : SDTypeProfile<1, 2, []>; 13220eae32dcSDimitry Andricdef wasm_narrow_u : SDNode<"WebAssemblyISD::NARROW_U", wasm_narrow_t>; 13230eae32dcSDimitry Andricdef : Pat<(v16i8 (wasm_narrow_u (v8i16 V128:$left), (v8i16 V128:$right))), 13240eae32dcSDimitry Andric (NARROW_U_I8x16 $left, $right)>; 13250eae32dcSDimitry Andricdef : Pat<(v8i16 (wasm_narrow_u (v4i32 V128:$left), (v4i32 V128:$right))), 13260eae32dcSDimitry Andric (NARROW_U_I16x8 $left, $right)>; 13270eae32dcSDimitry Andric 13280b57cec5SDimitry Andric// Bitcasts are nops 13290b57cec5SDimitry Andric// Matching bitcast t1 to t1 causes strange errors, so avoid repeating types 1330fe6060f1SDimitry Andricforeach t1 = AllVecs in 1331fe6060f1SDimitry Andricforeach t2 = AllVecs in 1332fe6060f1SDimitry Andricif !ne(t1, t2) then 1333fe6060f1SDimitry Andricdef : Pat<(t1.vt (bitconvert (t2.vt V128:$v))), (t1.vt V128:$v)>; 13348bcb0991SDimitry Andric 1335e8d8bef9SDimitry Andric// Extended pairwise addition 1336e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_signed, 1337fe6060f1SDimitry Andric "extadd_pairwise_i8x16_s", 0x7c>; 1338e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I16x8, I8x16, int_wasm_extadd_pairwise_unsigned, 1339fe6060f1SDimitry Andric "extadd_pairwise_i8x16_u", 0x7d>; 1340e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_signed, 1341fe6060f1SDimitry Andric "extadd_pairwise_i16x8_s", 0x7e>; 1342e8d8bef9SDimitry Andricdefm "" : SIMDConvert<I32x4, I16x8, int_wasm_extadd_pairwise_unsigned, 1343fe6060f1SDimitry Andric "extadd_pairwise_i16x8_u", 0x7f>; 1344e8d8bef9SDimitry Andric 1345fe6060f1SDimitry Andric// f64x2 <-> f32x4 conversions 1346fe6060f1SDimitry Andricdef demote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1347fe6060f1SDimitry Andricdef demote_zero : SDNode<"WebAssemblyISD::DEMOTE_ZERO", demote_t>; 1348fe6060f1SDimitry Andricdefm "" : SIMDConvert<F32x4, F64x2, demote_zero, 134981ad6265SDimitry Andric "demote_f64x2_zero", 0x5e>; 1350e8d8bef9SDimitry Andric 1351fe6060f1SDimitry Andricdef promote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>; 1352fe6060f1SDimitry Andricdef promote_low : SDNode<"WebAssemblyISD::PROMOTE_LOW", promote_t>; 1353fe6060f1SDimitry Andricdefm "" : SIMDConvert<F64x2, F32x4, promote_low, "promote_low_f32x4", 0x5f>; 1354e8d8bef9SDimitry Andric 1355349cc55cSDimitry Andric// Lower extending loads to load64_zero + promote_low 1356349cc55cSDimitry Andricdef extloadv2f32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> { 1357349cc55cSDimitry Andric let MemoryVT = v2f32; 1358349cc55cSDimitry Andric} 1359349cc55cSDimitry Andric// Adapted from the body of LoadPatNoOffset 1360349cc55cSDimitry Andric// TODO: other addressing patterns 1361349cc55cSDimitry Andricdef : Pat<(v2f64 (extloadv2f32 (i32 I32:$addr))), 1362349cc55cSDimitry Andric (promote_low_F64x2 (LOAD_ZERO_I64x2_A32 0, 0, I32:$addr))>, 1363349cc55cSDimitry Andric Requires<[HasAddr32]>; 1364349cc55cSDimitry Andricdef : Pat<(v2f64 (extloadv2f32 (i64 I64:$addr))), 1365349cc55cSDimitry Andric (promote_low_F64x2 (LOAD_ZERO_I64x2_A64 0, 0, I64:$addr))>, 1366349cc55cSDimitry Andric Requires<[HasAddr64]>; 1367349cc55cSDimitry Andric 1368e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 1369e8d8bef9SDimitry Andric// Saturating Rounding Q-Format Multiplication 1370e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 1371e8d8bef9SDimitry Andric 1372e8d8bef9SDimitry Andricdefm Q15MULR_SAT_S : 1373fe6060f1SDimitry Andric SIMDBinary<I16x8, int_wasm_q15mulr_sat_signed, "q15mulr_sat_s", 0x82>; 1374349cc55cSDimitry Andric 1375349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 137681ad6265SDimitry Andric// Relaxed swizzle 137781ad6265SDimitry Andric//===----------------------------------------------------------------------===// 137881ad6265SDimitry Andric 137981ad6265SDimitry Andricdefm RELAXED_SWIZZLE : 138081ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins), 138181ad6265SDimitry Andric [(set (v16i8 V128:$dst), 138281ad6265SDimitry Andric (int_wasm_relaxed_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))], 138381ad6265SDimitry Andric "i8x16.relaxed_swizzle\t$dst, $src, $mask", "i8x16.relaxed_swizzle", 0x100>; 138481ad6265SDimitry Andric 138581ad6265SDimitry Andric//===----------------------------------------------------------------------===// 138681ad6265SDimitry Andric// Relaxed floating-point to int conversions 138781ad6265SDimitry Andric//===----------------------------------------------------------------------===// 138881ad6265SDimitry Andric 138981ad6265SDimitry Andricmulticlass RelaxedConvert<Vec vec, Vec arg, SDPatternOperator op, string name, bits<32> simdop> { 139081ad6265SDimitry Andric defm op#_#vec : 139181ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins), 139281ad6265SDimitry Andric [(set (vec.vt V128:$dst), (vec.vt (op (arg.vt V128:$vec))))], 139381ad6265SDimitry Andric vec.prefix#"."#name#"\t$dst, $vec", vec.prefix#"."#name, simdop>; 139481ad6265SDimitry Andric} 139581ad6265SDimitry Andric 139681ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F32x4, int_wasm_relaxed_trunc_signed, 139781ad6265SDimitry Andric "relaxed_trunc_f32x4_s", 0x101>; 139881ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F32x4, int_wasm_relaxed_trunc_unsigned, 139981ad6265SDimitry Andric "relaxed_trunc_f32x4_u", 0x102>; 140081ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F64x2, int_wasm_relaxed_trunc_signed_zero, 140181ad6265SDimitry Andric "relaxed_trunc_f64x2_s_zero", 0x103>; 140281ad6265SDimitry Andricdefm "" : RelaxedConvert<I32x4, F64x2, int_wasm_relaxed_trunc_unsigned_zero, 140381ad6265SDimitry Andric "relaxed_trunc_f64x2_u_zero", 0x104>; 140481ad6265SDimitry Andric 140581ad6265SDimitry Andric//===----------------------------------------------------------------------===// 1406bdd1243dSDimitry Andric// Relaxed (Negative) Multiply-Add (madd/nmadd) 1407349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1408349cc55cSDimitry Andric 1409bdd1243dSDimitry Andricmulticlass SIMDMADD<Vec vec, bits<32> simdopA, bits<32> simdopS> { 1410bdd1243dSDimitry Andric defm MADD_#vec : 1411349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1412bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_madd 1413349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 1414bdd1243dSDimitry Andric vec.prefix#".relaxed_madd\t$dst, $a, $b, $c", 1415bdd1243dSDimitry Andric vec.prefix#".relaxed_madd", simdopA>; 1416bdd1243dSDimitry Andric defm NMADD_#vec : 1417349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1418bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_nmadd 1419349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 1420bdd1243dSDimitry Andric vec.prefix#".relaxed_nmadd\t$dst, $a, $b, $c", 1421bdd1243dSDimitry Andric vec.prefix#".relaxed_nmadd", simdopS>; 1422349cc55cSDimitry Andric} 1423349cc55cSDimitry Andric 1424bdd1243dSDimitry Andricdefm "" : SIMDMADD<F32x4, 0x105, 0x106>; 1425bdd1243dSDimitry Andricdefm "" : SIMDMADD<F64x2, 0x107, 0x108>; 1426349cc55cSDimitry Andric 1427349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1428349cc55cSDimitry Andric// Laneselect 1429349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1430349cc55cSDimitry Andric 1431349cc55cSDimitry Andricmulticlass SIMDLANESELECT<Vec vec, bits<32> op> { 1432349cc55cSDimitry Andric defm LANESELECT_#vec : 1433349cc55cSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), 1434bdd1243dSDimitry Andric [(set (vec.vt V128:$dst), (int_wasm_relaxed_laneselect 1435349cc55cSDimitry Andric (vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], 143681ad6265SDimitry Andric vec.prefix#".relaxed_laneselect\t$dst, $a, $b, $c", 143781ad6265SDimitry Andric vec.prefix#".relaxed_laneselect", op>; 1438349cc55cSDimitry Andric} 1439349cc55cSDimitry Andric 144081ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I8x16, 0x109>; 144181ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I16x8, 0x10a>; 144281ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I32x4, 0x10b>; 144381ad6265SDimitry Andricdefm "" : SIMDLANESELECT<I64x2, 0x10c>; 1444349cc55cSDimitry Andric 1445349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1446349cc55cSDimitry Andric// Relaxed floating-point min and max. 1447349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1448349cc55cSDimitry Andric 144981ad6265SDimitry Andricmulticlass RelaxedBinary<Vec vec, SDPatternOperator node, string name, 145081ad6265SDimitry Andric bits<32> simdop> { 145181ad6265SDimitry Andric defm _#vec : RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), 145281ad6265SDimitry Andric (outs), (ins), 145381ad6265SDimitry Andric [(set (vec.vt V128:$dst), 145481ad6265SDimitry Andric (node (vec.vt V128:$lhs), (vec.vt V128:$rhs)))], 145581ad6265SDimitry Andric vec.prefix#"."#name#"\t$dst, $lhs, $rhs", 145681ad6265SDimitry Andric vec.prefix#"."#name, simdop>; 1457349cc55cSDimitry Andric} 1458349cc55cSDimitry Andric 145981ad6265SDimitry Andricdefm SIMD_RELAXED_FMIN : 146081ad6265SDimitry Andric RelaxedBinary<F32x4, int_wasm_relaxed_min, "relaxed_min", 0x10d>; 146181ad6265SDimitry Andricdefm SIMD_RELAXED_FMAX : 146281ad6265SDimitry Andric RelaxedBinary<F32x4, int_wasm_relaxed_max, "relaxed_max", 0x10e>; 146381ad6265SDimitry Andricdefm SIMD_RELAXED_FMIN : 146481ad6265SDimitry Andric RelaxedBinary<F64x2, int_wasm_relaxed_min, "relaxed_min", 0x10f>; 146581ad6265SDimitry Andricdefm SIMD_RELAXED_FMAX : 146681ad6265SDimitry Andric RelaxedBinary<F64x2, int_wasm_relaxed_max, "relaxed_max", 0x110>; 1467349cc55cSDimitry Andric 1468349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 146981ad6265SDimitry Andric// Relaxed rounding q15 multiplication 1470349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1471349cc55cSDimitry Andric 147281ad6265SDimitry Andricdefm RELAXED_Q15MULR_S : 147381ad6265SDimitry Andric RelaxedBinary<I16x8, int_wasm_relaxed_q15mulr_signed, "relaxed_q15mulr_s", 147481ad6265SDimitry Andric 0x111>; 1475349cc55cSDimitry Andric 147681ad6265SDimitry Andric//===----------------------------------------------------------------------===// 147781ad6265SDimitry Andric// Relaxed integer dot product 147881ad6265SDimitry Andric//===----------------------------------------------------------------------===// 1479349cc55cSDimitry Andric 148081ad6265SDimitry Andricdefm RELAXED_DOT : 148181ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins), 1482bdd1243dSDimitry Andric [(set (v8i16 V128:$dst), (int_wasm_relaxed_dot_i8x16_i7x16_signed 148381ad6265SDimitry Andric (v16i8 V128:$lhs), (v16i8 V128:$rhs)))], 1484bdd1243dSDimitry Andric "i16x8.relaxed_dot_i8x16_i7x16_s\t$dst, $lhs, $rhs", 1485bdd1243dSDimitry Andric "i16x8.relaxed_dot_i8x16_i7x16_s", 0x112>; 148681ad6265SDimitry Andric 148781ad6265SDimitry Andricdefm RELAXED_DOT_ADD : 148881ad6265SDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, V128:$acc), 148981ad6265SDimitry Andric (outs), (ins), 1490bdd1243dSDimitry Andric [(set (v4i32 V128:$dst), (int_wasm_relaxed_dot_i8x16_i7x16_add_signed 149181ad6265SDimitry Andric (v16i8 V128:$lhs), (v16i8 V128:$rhs), (v4i32 V128:$acc)))], 1492bdd1243dSDimitry Andric "i32x4.relaxed_dot_i8x16_i7x16_add_s\t$dst, $lhs, $rhs, $acc", 1493bdd1243dSDimitry Andric "i32x4.relaxed_dot_i8x16_i7x16_add_s", 0x113>; 1494bdd1243dSDimitry Andric 1495bdd1243dSDimitry Andric//===----------------------------------------------------------------------===// 1496bdd1243dSDimitry Andric// Relaxed BFloat16 dot product 1497bdd1243dSDimitry Andric//===----------------------------------------------------------------------===// 1498bdd1243dSDimitry Andric 1499bdd1243dSDimitry Andricdefm RELAXED_DOT_BFLOAT : 1500bdd1243dSDimitry Andric RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, V128:$acc), 1501bdd1243dSDimitry Andric (outs), (ins), 1502bdd1243dSDimitry Andric [(set (v4f32 V128:$dst), (int_wasm_relaxed_dot_bf16x8_add_f32 1503bdd1243dSDimitry Andric (v8i16 V128:$lhs), (v8i16 V128:$rhs), (v4f32 V128:$acc)))], 1504bdd1243dSDimitry Andric "f32x4.relaxed_dot_bf16x8_add_f32\t$dst, $lhs, $rhs, $acc", 1505bdd1243dSDimitry Andric "f32x4.relaxed_dot_bf16x8_add_f32", 0x114>; 1506