Index: lib/Target/WebAssembly/WebAssemblyInstrFormats.td =================================================================== --- lib/Target/WebAssembly/WebAssemblyInstrFormats.td +++ lib/Target/WebAssembly/WebAssemblyInstrFormats.td @@ -119,49 +119,6 @@ !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs")), !strconcat("f64.", name), f64Inst>; } -multiclass SIMDBinaryIntNoI64x2 baseInst> { - defm _I8x16 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v16i8 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("i8x16.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("i8x16.", name), baseInst>; - defm _I16x8 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v8i16 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("i16x8.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("i16x8.", name), !add(baseInst, 1)>; - defm _I32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v4i32 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("i32x4.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("i32x4.", name), !add(baseInst, 2)>; -} -multiclass SIMDBinaryInt baseInst> { - defm "" : SIMDBinaryIntNoI64x2; - defm _I64x2 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v2i64 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("i64x2.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("i64x2.", name), !add(baseInst, 3)>; -} -multiclass SIMDBinaryFP baseInst> { - defm _F32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v4f32 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("f32x4.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("f32x4.", name), baseInst>; - defm _F64x2 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), - (outs), (ins), - [(set (v2f64 V128:$dst), (node V128:$lhs, V128:$rhs))], - !strconcat("f64x2.", - !strconcat(name, "\t$dst, $lhs, $rhs")), - !strconcat("f64x2.", name), !add(baseInst, 1)>; -} multiclass ComparisonInt i32Inst, bits<32> i64Inst> { defm _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), (outs), (ins), [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))], Index: lib/Target/WebAssembly/WebAssemblyInstrSIMD.td =================================================================== --- lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -18,59 +18,12 @@ foreach SIZE = [2, 4, 8, 16, 32] in def LaneIdx#SIZE : ImmLeaf; -// const vectors multiclass ConstVec { defm CONST_V128_#vec_t : SIMD_I<(outs V128:$dst), ops, (outs), ops, [(set V128:$dst, (vec_t pat))], "v128.const\t$dst, "#args, "v128.const\t"#args, 0>; } -defm "" : ConstVec; -defm "" : ConstVec; -defm "" : ConstVec; -defm "" : ConstVec; -defm "" : ConstVec; -defm "" : ConstVec; - -// lane extraction multiclass ExtractLane simdop, string suffix = "", SDNode extract = vector_extract> { @@ -107,24 +60,9 @@ defm "" : ExtractLane("extract_i16x8"#sign)>; } -let Defs = [ARGUMENTS] in { -defm "" : ExtractLaneExtended<"_s", 9>; -defm "" : ExtractLaneExtended<"_u", 10>; -defm "" : ExtractLane; -defm "" : ExtractLane; -defm "" : ExtractLane; -defm "" : ExtractLane; -} // Defs = [ARGUMENTS] - -// follow convention of making implicit expansions unsigned -def : Pat<(i32 (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx))), - (EXTRACT_LANE_v16i8_u V128:$vec, (i32 LaneIdx16:$idx))>; -def : Pat<(i32 (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx))), - (EXTRACT_LANE_v8i16_u V128:$vec, (i32 LaneIdx8:$idx))>; - -// lane replacement -multiclass ReplaceLane simdop> { +multiclass ReplaceLane simdop> { defm REPLACE_LANE_#vec_t : SIMD_I<(outs V128:$dst), (ins V128:$vec, i32imm_op:$idx, reg_t:$x), (outs), (ins i32imm_op:$idx), @@ -133,16 +71,6 @@ vec#".replace_lane\t$dst, $vec, $idx, $x", vec#".replace_lane\t$idx", simdop>; } -let Defs = [ARGUMENTS] in { -defm "" : ReplaceLane; -defm "" : ReplaceLane; -defm "" : ReplaceLane; -defm "" : ReplaceLane; -defm "" : ReplaceLane; -defm "" : ReplaceLane; -} // Defs = [ARGUMENTS] - -// splats def splat2 : PatFrag<(ops node:$x), (build_vector node:$x, node:$x)>; def splat4 : PatFrag<(ops node:$x), (build_vector node:$x, node:$x, node:$x, node:$x)>; @@ -160,15 +88,108 @@ [(set (vec_t V128:$dst), (splat_pat reg_t:$x))], vec#".splat\t$dst, $x", vec#".splat", simdop>; } +multiclass SIMDBinary simdop> { + defm _#vec_t : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), + (outs), (ins), + [(set (vec_t V128:$dst), (node V128:$lhs, V128:$rhs))], + vec#"."#name#"\t$dst, $lhs, $rhs", vec#"."#name, + simdop>; +} +multiclass SIMDBinaryIntNoI64x2 baseInst> { + defm "" : SIMDBinary; + defm "" : SIMDBinary; + defm "" : SIMDBinary; +} +multiclass SIMDBinaryInt baseInst> { + defm "" : SIMDBinaryIntNoI64x2; + defm "" : SIMDBinary; +} +multiclass SIMDBinaryFP baseInst> { + defm "" : SIMDBinary; + defm "" : SIMDBinary; +} + let Defs = [ARGUMENTS] in { +defm "" : ConstVec; +defm "" : ConstVec; +defm "" : ConstVec; +defm "" : ConstVec; +defm "" : ConstVec; +defm "" : ConstVec; +defm "" : ExtractLaneExtended<"_s", 9>; +defm "" : ExtractLaneExtended<"_u", 10>; +defm "" : ExtractLane; +defm "" : ExtractLane; +defm "" : ExtractLane; +defm "" : ExtractLane; +defm "" : ReplaceLane; +defm "" : ReplaceLane; +defm "" : ReplaceLane; +defm "" : ReplaceLane; +defm "" : ReplaceLane; +defm "" : ReplaceLane; defm "" : Splat; defm "" : Splat; defm "" : Splat; defm "" : Splat; defm "" : Splat; defm "" : Splat; +let isCommutable = 1 in { +defm ADD : SIMDBinaryInt; +defm ADD : SIMDBinaryFP; +defm MUL : SIMDBinaryIntNoI64x2; +defm MUL : SIMDBinaryFP; +} // isCommutable = 1 +defm SUB : SIMDBinaryInt; +defm SUB : SIMDBinaryFP; +defm DIV : SIMDBinaryFP; } // Defs = [ARGUMENTS] +// follow convention of making implicit expansions unsigned +def : Pat<(i32 (vector_extract (v16i8 V128:$vec), (i32 LaneIdx16:$idx))), + (EXTRACT_LANE_v16i8_u V128:$vec, (i32 LaneIdx16:$idx))>; +def : Pat<(i32 (vector_extract (v8i16 V128:$vec), (i32 LaneIdx8:$idx))), + (EXTRACT_LANE_v8i16_u V128:$vec, (i32 LaneIdx8:$idx))>; + // arbitrary other BUILD_VECTOR patterns def : Pat<(v16i8 (build_vector (i32 I32:$x0), (i32 I32:$x1), (i32 I32:$x2), (i32 I32:$x3), @@ -280,19 +301,3 @@ def : Pat<(v2f64 (build_vector (f64 F64:$x0), (f64 F64:$x1))), (v2f64 (REPLACE_LANE_v2f64 (v2f64 (SPLAT_v2f64 (f64 F64:$x0))), 1, F64:$x1))>; - -// arithmetic -let Defs = [ARGUMENTS] in { -let isCommutable = 1 in -defm ADD : SIMDBinaryInt; -defm SUB : SIMDBinaryInt; -let isCommutable = 1 in -defm MUL : SIMDBinaryIntNoI64x2; - -let isCommutable = 1 in -defm ADD : SIMDBinaryFP; -defm SUB : SIMDBinaryFP; -defm DIV : SIMDBinaryFP; -let isCommutable = 1 in -defm MUL : SIMDBinaryFP; -} // Defs = [ARGUMENTS]