r343835 - [WebAssembly] __builtin_wasm_replace_lane_* builtins

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


Author: tlively
Date: Thu Oct  4 17:58:07 2018
New Revision: 343835

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

Summary: Depends on D52852.

Reviewers: aheejin, dschuff

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

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

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=343835&r1=343834&r2=343835&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:58:07 2018
@@ -49,4 +49,11 @@ BUILTIN(__builtin_wasm_extract_lane_i64x
 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

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343835&r1=343834&r2=343835&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:58:07 2018
@@ -12474,6 +12474,34 @@ Value *CodeGenFunction::EmitWebAssemblyB
       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;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343835&r1=343834&r2=343835&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:58:07 2018
@@ -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
+}




More information about the cfe-commits mailing list