[WebAssembly] Prototype i64x2.bitmask
authorThomas Lively <tlively@google.com>
Sat, 31 Oct 2020 00:23:30 +0000 (17:23 -0700)
committerThomas Lively <tlively@google.com>
Sat, 31 Oct 2020 00:23:30 +0000 (17:23 -0700)
As proposed in https://github.com/WebAssembly/simd/pull/368.

Differential Revision: https://reviews.llvm.org/D90514

clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-wasm.c
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
llvm/test/MC/WebAssembly/simd-encodings.s

index 4f448df..21a67d8 100644 (file)
@@ -154,6 +154,7 @@ TARGET_BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc", "unimplemented-sim
 TARGET_BUILTIN(__builtin_wasm_bitmask_i8x16, "iV16Sc", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_bitmask_i16x8, "iV8s", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_bitmask_i32x4, "iV4i", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_bitmask_i64x2, "iV2LLi", "nc", "simd128")
 
 TARGET_BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc", "simd128")
index 448eab7..a7c07e0 100644 (file)
@@ -16734,7 +16734,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_bitmask_i8x16:
   case WebAssembly::BI__builtin_wasm_bitmask_i16x8:
-  case WebAssembly::BI__builtin_wasm_bitmask_i32x4: {
+  case WebAssembly::BI__builtin_wasm_bitmask_i32x4:
+  case WebAssembly::BI__builtin_wasm_bitmask_i64x2: {
     Value *Vec = EmitScalarExpr(E->getArg(0));
     Function *Callee =
         CGM.getIntrinsic(Intrinsic::wasm_bitmask, Vec->getType());
index 4a7efaf..a915887 100644 (file)
@@ -728,6 +728,12 @@ int bitmask_i32x4(i32x4 x) {
   // WEBASSEMBLY: ret
 }
 
+int bitmask_i64x2(i64x2 x) {
+  return __builtin_wasm_bitmask_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.bitmask.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
 f32x4 abs_f32x4(f32x4 x) {
   return __builtin_wasm_abs_f32x4(x);
   // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
index 05f4c28..191cdea 100644 (file)
@@ -848,6 +848,7 @@ multiclass SIMDBitmask<ValueType vec_t, string vec, bits<32> simdop> {
 defm BITMASK : SIMDBitmask<v16i8, "i8x16", 100>;
 defm BITMASK : SIMDBitmask<v8i16, "i16x8", 132>;
 defm BITMASK : SIMDBitmask<v4i32, "i32x4", 164>;
+defm BITMASK : SIMDBitmask<v2i64, "i64x2", 196>;
 
 //===----------------------------------------------------------------------===//
 // Bit shifts
index 625ccf5..23a7bfb 100644 (file)
@@ -646,6 +646,16 @@ define i32 @all_v2i64(<2 x i64> %x) {
   ret i32 %a
 }
 
+; CHECK-LABEL: bitmask_v2i64:
+; SIMD128-NEXT: .functype bitmask_v2i64 (v128) -> (i32){{$}}
+; SIMD128-NEXT: i64x2.bitmask $push[[R:[0-9]+]]=, $0{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare i32 @llvm.wasm.bitmask.v2i64(<2 x i64>)
+define i32 @bitmask_v2i64(<2 x i64> %x) {
+  %a = call i32 @llvm.wasm.bitmask.v2i64(<2 x i64> %x)
+  ret i32 %a
+}
+
 ; CHECK-LABEL: bitselect_v2i64:
 ; SIMD128-NEXT: .functype bitselect_v2i64 (v128, v128, v128) -> (v128){{$}}
 ; SIMD128-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $0, $1, $2{{$}}
index a0560b5..509f424 100644 (file)
@@ -523,6 +523,9 @@ main:
     # CHECK: i64x2.all_true # encoding: [0xfd,0xc3,0x01]
     i64x2.all_true
 
+    # CHECK: i64x2.bitmask # encoding: [0xfd,0xc4,0x01]
+    i64x2.bitmask
+
     # CHECK: i64x2.widen_low_i32x4_s # encoding: [0xfd,0xc7,0x01]
     i64x2.widen_low_i32x4_s