[PATCH] D52913: [WebAssembly] abs and sqrt builtins

Thomas Lively via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 4 15:58:29 PDT 2018


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

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


Repository:
  rC Clang

https://reviews.llvm.org/D52913

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
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12548,6 +12548,18 @@
     Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
     return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+    return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+    return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
     return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===================================================================
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN


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


More information about the cfe-commits mailing list