Skip to content

Commit f650d7a

Browse files
tlivelyshravanrn
authored andcommitted
Update WebAssembly SIMD opcodes (#56)
* [WebAssembly] Enable recently implemented SIMD operations Summary: Moves a batch of instructions from unimplemented-simd128 to simd128 because they have recently become available in V8. Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73926 * [WebAssembly] Simplify extract_vector lowering Summary: Removes patterns that were not doing useful work, changes the default extract instructions to be the unsigned versions now that they are enabled by default, fixes PR44988, and adds tests for sext_inreg lowering. Reviewers: aheejin Reviewed By: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75005 * [WebAssembly] Renumber SIMD opcodes Summary: As described in WebAssembly/simd#209. This is the final reorganization of the SIMD opcode space before standardization. It has been landed in concert with corresponding changes in other projects in the WebAssembly SIMD ecosystem. Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79224
1 parent d561d49 commit f650d7a

File tree

8 files changed

+378
-438
lines changed

8 files changed

+378
-438
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ TARGET_BUILTIN(__builtin_wasm_qfms_f64x2, "V2dV2dV2dV2d", "nc", "unimplemented-s
145145

146146
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc", "simd128")
147147
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc", "simd128")
148-
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc", "unimplemented-simd128")
149-
TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc", "unimplemented-simd128")
150148

151149
TARGET_BUILTIN(__builtin_wasm_narrow_s_i8x16_i16x8, "V16cV8sV8s", "nc", "simd128")
152150
TARGET_BUILTIN(__builtin_wasm_narrow_u_i8x16_i16x8, "V16cV8sV8s", "nc", "simd128")

clang/lib/CodeGen/CGBuiltin.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -14881,8 +14881,7 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1488114881
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
1488214882
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
1488314883
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
14884-
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4:
14885-
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64x2_f64x2: {
14884+
case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4: {
1488614885
Value *Src = EmitScalarExpr(E->getArg(0));
1488714886
llvm::Type *ResT = ConvertType(E->getType());
1488814887
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -14893,8 +14892,7 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1489314892
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
1489414893
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
1489514894
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
14896-
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4:
14897-
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64x2_f64x2: {
14895+
case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4: {
1489814896
Value *Src = EmitScalarExpr(E->getArg(0));
1489914897
llvm::Type *ResT = ConvertType(E->getType());
1490014898
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,

clang/test/CodeGen/builtins-wasm.c

-12
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,6 @@ i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
603603
// WEBASSEMBLY-NEXT: ret
604604
}
605605

606-
i64x2 trunc_saturate_s_i64x2_f64x2(f64x2 f) {
607-
return __builtin_wasm_trunc_saturate_s_i64x2_f64x2(f);
608-
// WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
609-
// WEBASSEMBLY-NEXT: ret
610-
}
611-
612-
i64x2 trunc_saturate_u_i64x2_f64x2(f64x2 f) {
613-
return __builtin_wasm_trunc_saturate_u_i64x2_f64x2(f);
614-
// WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
615-
// WEBASSEMBLY-NEXT: ret
616-
}
617-
618606
i8x16 narrow_s_i8x16_i16x8(i16x8 low, i16x8 high) {
619607
return __builtin_wasm_narrow_s_i8x16_i16x8(low, high);
620608
// WEBASSEMBLY: call <16 x i8> @llvm.wasm.narrow.signed.v16i8.v8i16(

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

+111-122
Large diffs are not rendered by default.

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

-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ define <4 x float> @convert_u_v4f32(<4 x i32> %x) {
3131
; NO-SIMD128-NOT: i64x2
3232
; SIMD128-VM-NOT: f64x2.convert_i64x2_s
3333
; SIMD128-NEXT: .functype convert_s_v2f64 (v128) -> (v128){{$}}
34-
; SIMD128-NEXT: f64x2.convert_i64x2_s $push[[R:[0-9]+]]=, $0
35-
; SIMD128-NEXT: return $pop[[R]]
3634
define <2 x double> @convert_s_v2f64(<2 x i64> %x) {
3735
%a = sitofp <2 x i64> %x to <2 x double>
3836
ret <2 x double> %a
@@ -42,8 +40,6 @@ define <2 x double> @convert_s_v2f64(<2 x i64> %x) {
4240
; NO-SIMD128-NOT: i64x2
4341
; SIMD128-VM-NOT: f64x2.convert_i64x2_u
4442
; SIMD128-NEXT: .functype convert_u_v2f64 (v128) -> (v128){{$}}
45-
; SIMD128-NEXT: f64x2.convert_i64x2_u $push[[R:[0-9]+]]=, $0
46-
; SIMD128-NEXT: return $pop[[R]]
4743
define <2 x double> @convert_u_v2f64(<2 x i64> %x) {
4844
%a = uitofp <2 x i64> %x to <2 x double>
4945
ret <2 x double> %a
@@ -73,8 +69,6 @@ define <4 x i32> @trunc_sat_u_v4i32(<4 x float> %x) {
7369
; NO-SIMD128-NOT: f64x2
7470
; SIMD128-VM-NOT: i64x2.trunc_sat_f64x2_s
7571
; SIMD128-NEXT: .functype trunc_sat_s_v2i64 (v128) -> (v128){{$}}
76-
; SIMD128-NEXT: i64x2.trunc_sat_f64x2_s $push[[R:[0-9]+]]=, $0
77-
; SIMD128-NEXT: return $pop[[R]]
7872
define <2 x i64> @trunc_sat_s_v2i64(<2 x double> %x) {
7973
%a = fptosi <2 x double> %x to <2 x i64>
8074
ret <2 x i64> %a
@@ -84,8 +78,6 @@ define <2 x i64> @trunc_sat_s_v2i64(<2 x double> %x) {
8478
; NO-SIMD128-NOT: f64x2
8579
; SIMD128-VM-NOT: i64x2.trunc_sat_f64x2_u
8680
; SIMD128-NEXT: .functype trunc_sat_u_v2i64 (v128) -> (v128){{$}}
87-
; SIMD128-NEXT: i64x2.trunc_sat_f64x2_u $push[[R:[0-9]+]]=, $0
88-
; SIMD128-NEXT: return $pop[[R]]
8981
define <2 x i64> @trunc_sat_u_v2i64(<2 x double> %x) {
9082
%a = fptoui <2 x double> %x to <2 x i64>
9183
ret <2 x i64> %a

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

-22
Original file line numberDiff line numberDiff line change
@@ -426,28 +426,6 @@ define <2 x i64> @bitselect_v2i64(<2 x i64> %v1, <2 x i64> %v2, <2 x i64> %c) {
426426
ret <2 x i64> %a
427427
}
428428

429-
; CHECK-LABEL: trunc_sat_s_v2i64:
430-
; NO-SIMD128-NOT: f32x4
431-
; SIMD128-NEXT: .functype trunc_sat_s_v2i64 (v128) -> (v128){{$}}
432-
; SIMD128-NEXT: i64x2.trunc_sat_f64x2_s $push[[R:[0-9]+]]=, $0
433-
; SIMD128-NEXT: return $pop[[R]]
434-
declare <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double>)
435-
define <2 x i64> @trunc_sat_s_v2i64(<2 x double> %x) {
436-
%a = call <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %x)
437-
ret <2 x i64> %a
438-
}
439-
440-
; CHECK-LABEL: trunc_sat_u_v2i64:
441-
; NO-SIMD128-NOT: f32x4
442-
; SIMD128-NEXT: .functype trunc_sat_u_v2i64 (v128) -> (v128){{$}}
443-
; SIMD128-NEXT: i64x2.trunc_sat_f64x2_u $push[[R:[0-9]+]]=, $0
444-
; SIMD128-NEXT: return $pop[[R]]
445-
declare <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double>)
446-
define <2 x i64> @trunc_sat_u_v2i64(<2 x double> %x) {
447-
%a = call <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %x)
448-
ret <2 x i64> %a
449-
}
450-
451429
; ==============================================================================
452430
; 4 x f32
453431
; ==============================================================================

llvm/test/MC/Disassembler/WebAssembly/wasm.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
0xFC 0x07
3535

3636
# CHECK: v128.const 50462976, 117835012, 185207048, 252579084
37-
0xFD 0x02 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
37+
0xFD 0x0C 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
3838

3939
# CHECK: v8x16.shuffle 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
40-
0xFD 0x03 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
40+
0xFD 0x0D 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
4141

4242
# Check LEB128 encoding of SIMD instructions
43-
# CHECK: i64x2.all_true
44-
0xFD 0x86 0x01
43+
# CHECK: i16x8.all_true
44+
0xFD 0x83 0x01
4545

4646
# Including non-canonical LEB128 encodings
47-
# CHECK: i64x2.any_true
48-
# CHECK-NOT: i64.div_u
49-
0xFD 0x85 0x81 0x80 0x80 0x80 0x80 0x00
47+
# CHECK: i16x8.any_true
48+
# CHECK-NOT: i16x8.neg
49+
0xFD 0x82 0x81 0x80 0x80 0x80 0x80 0x00
5050

5151
# Check br_table, which has its own operand type.
5252
# CHECK: br_table {0, 1, 2}

0 commit comments

Comments
 (0)