Skip to content

Commit 0d947b4

Browse files
tlivelymemfrob
authored andcommitted
[WebAssembly] Implement i64x2.mul and remove i8x16.mul
Summary: This reflects changes in the spec proposal made since basic arithmetic was first implemented. Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D80174
1 parent da97a56 commit 0d947b4

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

clang/lib/Headers/wasm_simd128.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,6 @@ wasm_u8x16_sub_saturate(v128_t __a, v128_t __b) {
637637
(__i8x16)__b);
638638
}
639639

640-
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_mul(v128_t __a,
641-
v128_t __b) {
642-
return (v128_t)((__u8x16)__a * (__u8x16)__b);
643-
}
644-
645640
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_min(v128_t __a,
646641
v128_t __b) {
647642
return (v128_t)__builtin_wasm_min_s_i8x16((__i8x16)__a, (__i8x16)__b);

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
153153
MVT::v2f64})
154154
setOperationAction(Op, T, Custom);
155155

156-
// There is no i64x2.mul instruction
157-
// TODO: Actually, there is now. Implement it.
158-
setOperationAction(ISD::MUL, MVT::v2i64, Expand);
156+
// There is no i8x16.mul instruction
157+
setOperationAction(ISD::MUL, MVT::v16i8, Expand);
159158

160159
// There are no vector select instructions
161160
for (auto Op : {ISD::VSELECT, ISD::SELECT_CC, ISD::SELECT})

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,12 @@ def : Pat<(v2i64 (shifts[0] (v2i64 V128:$vec), I32:$x)),
673673
// Integer binary arithmetic
674674
//===----------------------------------------------------------------------===//
675675

676+
multiclass SIMDBinaryIntNoI8x16<SDNode node, string name, bits<32> baseInst> {
677+
defm "" : SIMDBinary<v8i16, "i16x8", node, name, !add(baseInst, 32)>;
678+
defm "" : SIMDBinary<v4i32, "i32x4", node, name, !add(baseInst, 64)>;
679+
defm "" : SIMDBinary<v2i64, "i64x2", node, name, !add(baseInst, 96)>;
680+
}
681+
676682
multiclass SIMDBinaryIntSmall<SDNode node, string name, bits<32> baseInst> {
677683
defm "" : SIMDBinary<v16i8, "i8x16", node, name, baseInst>;
678684
defm "" : SIMDBinary<v8i16, "i16x8", node, name, !add(baseInst, 32)>;
@@ -704,7 +710,7 @@ defm SUB_SAT_U :
704710

705711
// Integer multiplication: mul
706712
let isCommutable = 1 in
707-
defm MUL : SIMDBinaryIntNoI64x2<mul, "mul", 117>;
713+
defm MUL : SIMDBinaryIntNoI8x16<mul, "mul", 117>;
708714

709715
// Integer min_s / min_u / max_s / max_u
710716
let isCommutable = 1 in {

llvm/test/CodeGen/WebAssembly/simd-arith.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ define <16 x i8> @sub_v16i8(<16 x i8> %x, <16 x i8> %y) {
3737
ret <16 x i8> %a
3838
}
3939

40+
; i8x16.mul is not in spec
4041
; CHECK-LABEL: mul_v16i8:
4142
; NO-SIMD128-NOT: i8x16
42-
; SIMD128-NEXT: .functype mul_v16i8 (v128, v128) -> (v128){{$}}
43-
; SIMD128-NEXT: i8x16.mul $push[[R:[0-9]+]]=, $0, $1{{$}}
44-
; SIMD128-NEXT: return $pop[[R]]{{$}}
43+
; SIMD128-NOT: i8x16.mul
44+
; SIMD128: i8x16.extract_lane_u
45+
; SIMD128: i32.mul
4546
define <16 x i8> @mul_v16i8(<16 x i8> %x, <16 x i8> %y) {
4647
%a = mul <16 x i8> %x, %y
4748
ret <16 x i8> %a
@@ -956,12 +957,11 @@ define <2 x i64> @sub_v2i64(<2 x i64> %x, <2 x i64> %y) {
956957
ret <2 x i64> %a
957958
}
958959

959-
; v2i64.mul is not in spec
960960
; CHECK-LABEL: mul_v2i64:
961961
; NO-SIMD128-NOT: i64x2
962-
; SIMD128-NOT: i64x2.mul
963-
; SIMD128: i64x2.extract_lane
964-
; SIMD128: i64.mul
962+
; SIMD128-NEXT: .functype mul_v2i64 (v128, v128) -> (v128){{$}}
963+
; SIMD128: i64x2.mul $push[[R:[0-9]+]]=, $0, $1{{$}}
964+
; SIMD128-NEXT: return $pop[[R]]{{$}}
965965
define <2 x i64> @mul_v2i64(<2 x i64> %x, <2 x i64> %y) {
966966
%a = mul <2 x i64> %x, %y
967967
ret <2 x i64> %a

llvm/test/CodeGen/WebAssembly/simd-unsupported.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ define <2 x i64> @cttz_v2i64_undef(<2 x i64> %x) {
308308
}
309309

310310
; CHECK-LABEL: ctpop_v2i64:
311-
; CHECK: i64.popcnt
311+
; Note: expansion does not use i64.popcnt
312+
; CHECK: v128.and
312313
declare <2 x i64> @llvm.ctpop.v2i64(<2 x i64>)
313314
define <2 x i64> @ctpop_v2i64(<2 x i64> %x) {
314315
%v = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %x)

llvm/test/MC/WebAssembly/simd-encodings.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ main:
328328
# CHECK: i8x16.sub_saturate_u # encoding: [0xfd,0x73]
329329
i8x16.sub_saturate_u
330330

331-
# CHECK: i8x16.mul # encoding: [0xfd,0x75]
332-
i8x16.mul
333-
334331
# CHECK: i8x16.min_s # encoding: [0xfd,0x76]
335332
i8x16.min_s
336333

@@ -508,6 +505,9 @@ main:
508505
# CHECK: i64x2.sub # encoding: [0xfd,0xd1,0x01]
509506
i64x2.sub
510507

508+
# CHECK: i64x2.mul # encoding: [0xfd,0xd5,0x01]
509+
i64x2.mul
510+
511511
# CHECK: f32x4.abs # encoding: [0xfd,0xe0,0x01]
512512
f32x4.abs
513513

0 commit comments

Comments
 (0)