r343834 - [WebAssembly] __builtin_wasm_extract_lane_* builtins

Thomas Lively via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 4 17:54:44 PDT 2018


Author: tlively
Date: Thu Oct  4 17:54:44 2018
New Revision: 343834

URL: http://llvm.org/viewvc/llvm-project?rev=343834&view=rev
Log:
[WebAssembly] __builtin_wasm_extract_lane_* builtins

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
    cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343834&r1=343833&r2=343834&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:54:44 2018
@@ -39,4 +39,14 @@ BUILTIN(__builtin_wasm_atomic_wait_i32,
 BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
 
+// SIMD builtins
+BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343834&r1=343833&r2=343834&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:54:44 2018
@@ -12444,6 +12444,36 @@ Value *CodeGenFunction::EmitWebAssemblyB
     Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
     return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
+    llvm::APSInt LaneConst;
+    if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+      llvm_unreachable("Constant arg isn't actually constant?");
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+    Value *Extract = Builder.CreateExtractElement(Vec, Lane);
+    switch (BuiltinID) {
+    case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+    case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+      return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+    case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+    case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+      return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+    case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+    case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+    case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+    case WebAssembly::BI__builtin_wasm_extract_lane_f64x2:
+      return Extract;
+    default:
+      llvm_unreachable("unexpected builtin ID");
+    }
+  }
 
   default:
     return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343834&r1=343833&r2=343834&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:54:44 2018
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@ unsigned int f10(int *addr, int count) {
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}




More information about the cfe-commits mailing list