]> granicus.if.org Git - clang/commitdiff
[WebAssembly] __builtin_wasm_replace_lane_* builtins
authorThomas Lively <tlively@google.com>
Fri, 5 Oct 2018 00:58:07 +0000 (00:58 +0000)
committerThomas Lively <tlively@google.com>
Fri, 5 Oct 2018 00:58:07 +0000 (00:58 +0000)
Summary: Depends on D52852.

Reviewers: aheejin, dschuff

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343835 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b5197a7c14d29f787f1e54c082d827b39e5be991..948426dbd505c60c548d20cc207221e7189bb6c4 100644 (file)
@@ -49,4 +49,11 @@ BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
 
+BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
+
 #undef BUILTIN
index a52efd251b47864a3a8bde32fe1e24b8fef8feae..04d25837c8e8d6e6e58024c4c15a200b288405d0 100644 (file)
@@ -12474,6 +12474,34 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
       llvm_unreachable("unexpected builtin ID");
     }
   }
+  case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i16x8:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_replace_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 *Val = EmitScalarExpr(E->getArg(2));
+    switch (BuiltinID) {
+    case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+    case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
+      llvm::Type *ElemType = ConvertType(E->getType())->getVectorElementType();
+      Value *Trunc = Builder.CreateTrunc(Val, ElemType);
+      return Builder.CreateInsertElement(Vec, Trunc, Lane);
+    }
+    case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+    case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+    case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+    case WebAssembly::BI__builtin_wasm_replace_lane_f64x2:
+      return Builder.CreateInsertElement(Vec, Val, Lane);
+    default:
+      llvm_unreachable("unexpected builtin ID");
+    }
+  }
 
   default:
     return nullptr;
index a96f6705f7326ddfb0148ca81a71f9b06bff89b8..6a4fcc101130fd7b5bf8d7c827d94186358c2c0c 100644 (file)
@@ -134,3 +134,41 @@ double f18(f64x2 v) {
   // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f19(i8x16 v, int x) {
+  return __builtin_wasm_replace_lane_i8x16(v, 13, x);
+  // WEBASSEMBLY: trunc i32 %x to i8
+  // WEBASSEMBLY-NEXT: insertelement <16 x i8> %v, i8 %{{.*}}, i32 13
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f20(i16x8 v, int x) {
+  return __builtin_wasm_replace_lane_i16x8(v, 7, x);
+  // WEBASSEMBLY: trunc i32 %x to i16
+  // WEBASSEMBLY-NEXT: insertelement <8 x i16> %v, i16 %{{.*}}, i32 7
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 f21(i32x4 v, int x) {
+  return __builtin_wasm_replace_lane_i32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x i32> %v, i32 %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 f22(i64x2 v, long long x) {
+  return __builtin_wasm_replace_lane_i64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x i64> %v, i64 %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f32x4 f23(f32x4 v, float x) {
+  return __builtin_wasm_replace_lane_f32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x float> %v, float %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 f24(f64x2 v, double x) {
+  return __builtin_wasm_replace_lane_f64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}