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

Repository:
  rC Clang

https://reviews.llvm.org/D53685

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
@@ -131,6 +131,31 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+float min_f32(float x, float y) {
+  return __builtin_wasm_min_f32(x, y);
+  // WEBASSEMBLY: call float @llvm.minimum.f32(float %x, float %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float max_f32(float x, float y) {
+  return __builtin_wasm_max_f32(x, y);
+  // WEBASSEMBLY: call float @llvm.maximum.f32(float %x, float %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double min_f64(double x, double y) {
+  return __builtin_wasm_min_f64(x, y);
+  // WEBASSEMBLY: call double @llvm.minimum.f64(double %x, double %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double max_f64(double x, double y) {
+  return __builtin_wasm_max_f64(x, y);
+  // WEBASSEMBLY: call double @llvm.maximum.f64(double %x, double %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
@@ -277,6 +302,13 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i32x4 bitselect(i32x4 x, i32x4 y, i32x4 c) {
+  return __builtin_wasm_bitselect(x, y, c);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.bitselect.v4i32(
+  // WEBASSEMBLY-SAME: <4 x i32> %x, <4 x i32> %y, <4 x i32> %c)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 int any_true_i8x16(i8x16 x) {
   return __builtin_wasm_any_true_i8x16(x);
   // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
@@ -337,6 +369,34 @@
   // WEBASSEMBLY: ret
 }
 
+f32x4 min_f32x4(f32x4 x, f32x4 y) {
+  return __builtin_wasm_min_f32x4(x, y);
+  // WEBASSEMBLY: call <4 x float> @llvm.minimum.v4f32(
+  // WEBASSEMBLY-SAME: <4 x float> %x, <4 x float> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f32x4 max_f32x4(f32x4 x, f32x4 y) {
+  return __builtin_wasm_max_f32x4(x, y);
+  // WEBASSEMBLY: call <4 x float> @llvm.maximum.v4f32(
+  // WEBASSEMBLY-SAME: <4 x float> %x, <4 x float> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 min_f64x2(f64x2 x, f64x2 y) {
+  return __builtin_wasm_min_f64x2(x, y);
+  // WEBASSEMBLY: call <2 x double> @llvm.minimum.v2f64(
+  // WEBASSEMBLY-SAME: <2 x double> %x, <2 x double> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 max_f64x2(f64x2 x, f64x2 y) {
+  return __builtin_wasm_max_f64x2(x, y);
+  // WEBASSEMBLY: call <2 x double> @llvm.maximum.v2f64(
+  // WEBASSEMBLY-SAME: <2 x double> %x, <2 x double> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 f32x4 sqrt_f32x4(f32x4 x) {
   return __builtin_wasm_sqrt_f32x4(x);
   // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12544,6 +12544,26 @@
                                      {ResT, Src->getType()});
     return Builder.CreateCall(Callee, {Src});
   }
+  case WebAssembly::BI__builtin_wasm_min_f32:
+  case WebAssembly::BI__builtin_wasm_min_f64:
+  case WebAssembly::BI__builtin_wasm_min_f32x4:
+  case WebAssembly::BI__builtin_wasm_min_f64x2: {
+    Value *LHS = EmitScalarExpr(E->getArg(0));
+    Value *RHS = EmitScalarExpr(E->getArg(1));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::minimum,
+                                     ConvertType(E->getType()));
+    return Builder.CreateCall(Callee, {LHS, RHS});
+  }
+  case WebAssembly::BI__builtin_wasm_max_f32:
+  case WebAssembly::BI__builtin_wasm_max_f64:
+  case WebAssembly::BI__builtin_wasm_max_f32x4:
+  case WebAssembly::BI__builtin_wasm_max_f64x2: {
+    Value *LHS = EmitScalarExpr(E->getArg(0));
+    Value *RHS = EmitScalarExpr(E->getArg(1));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::maximum,
+                                     ConvertType(E->getType()));
+    return Builder.CreateCall(Callee, {LHS, RHS});
+  }
   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:
@@ -12636,6 +12656,14 @@
     Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
     return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_bitselect: {
+    Value *V1 = EmitScalarExpr(E->getArg(0));
+    Value *V2 = EmitScalarExpr(E->getArg(1));
+    Value *C = EmitScalarExpr(E->getArg(2));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_bitselect,
+                                     ConvertType(E->getType()));
+    return Builder.CreateCall(Callee, {V1, V2, C});
+  }
   case WebAssembly::BI__builtin_wasm_any_true_i8x16:
   case WebAssembly::BI__builtin_wasm_any_true_i16x8:
   case WebAssembly::BI__builtin_wasm_any_true_i32x4:
Index: include/clang/Basic/BuiltinsWebAssembly.def
===================================================================
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -49,6 +49,12 @@
 BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, "LLid", "nc")
 BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc")
 
+// Floating point min/max
+BUILTIN(__builtin_wasm_min_f32, "fff", "nc")
+BUILTIN(__builtin_wasm_max_f32, "fff", "nc")
+BUILTIN(__builtin_wasm_min_f64, "ddd", "nc")
+BUILTIN(__builtin_wasm_max_f64, "ddd", "nc")
+
 // SIMD builtins
 BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
@@ -76,6 +82,8 @@
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
 
+BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc")
+
 BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc")
 BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc")
 BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc")
@@ -88,6 +96,11 @@
 BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
 
+BUILTIN(__builtin_wasm_min_f32x4, "V4fV4fV4f", "nc")
+BUILTIN(__builtin_wasm_max_f32x4, "V4fV4fV4f", "nc")
+BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc")
+BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc")
+
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to