[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

Thomas Lively via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 3 18:03:15 PDT 2018


tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, sbc100.

Depends on https://reviews.llvm.org/D52852.


Repository:
  rC Clang

https://reviews.llvm.org/D52856

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


Index: test/CodeGen/builtins-wasm.c
===================================================================
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -134,3 +134,41 @@
   // 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
+}
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12449,6 +12449,24 @@
     Value *Lane = EmitScalarExpr(E->getArg(1));
     return Builder.CreateExtractElement(Vec, Lane);
   }
+  case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Lane = EmitScalarExpr(E->getArg(1));
+    Value *Val = EmitScalarExpr(E->getArg(2));
+    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: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Lane = EmitScalarExpr(E->getArg(1));
+    Value *Val = EmitScalarExpr(E->getArg(2));
+    return Builder.CreateInsertElement(Vec, Val, Lane);
+  }
 
   default:
     return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===================================================================
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -49,4 +49,11 @@
 BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "ncV:128:")
 BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "ncV:128:")
 
+BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2WiV2WiIiWi", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "ncV:128:")
+
 #undef BUILTIN


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52856.168214.patch
Type: text/x-patch
Size: 3496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181004/cbbab936/attachment-0001.bin>


More information about the cfe-commits mailing list