[PATCH] D53009: [WebAssembly] Saturating float-to-int builtins

2018-10-10 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC344205: [WebAssembly] Saturating float-to-int builtins 
(authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53009?vs=168738&id=169132#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53009

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

Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -39,6 +39,16 @@
 BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
 
+// Saturating fp-to-int conversions
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f64, "id", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f64, "id", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f32, "LLif", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f32, "LLif", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, "LLid", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc")
+
 // SIMD builtins
 BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
@@ -81,4 +91,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
+BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+
 #undef BUILTIN
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -83,6 +83,54 @@
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
 
+int trunc_saturate_s_i32_f32(float f) {
+  return __builtin_wasm_trunc_saturate_s_i32_f32(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f32(float f) {
+  return __builtin_wasm_trunc_saturate_u_i32_f32(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_s_i32_f64(double f) {
+  return __builtin_wasm_trunc_saturate_s_i32_f64(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f64(double f) {
+  return __builtin_wasm_trunc_saturate_u_i32_f64(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f32(float f) {
+  return __builtin_wasm_trunc_saturate_s_i64_f32(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f32(float f) {
+  return __builtin_wasm_trunc_saturate_u_i64_f32(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f64(double f) {
+  return __builtin_wasm_trunc_saturate_s_i64_f64(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f64(double f) {
+  return __builtin_wasm_trunc_saturate_u_i64_f64(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double %f)
+  // 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
@@ -300,3 +348,27 @@
   // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
   // WEBASSEMBLY: ret
 }
+
+i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+  // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+  // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trun

[PATCH] D53685: [WebAssembly] Bitselect and min/max intrinsics

2018-10-24 Thread Thomas Lively via Phabricator via cfe-commits
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_a

[PATCH] D53685: [WebAssembly] Bitselect and min/max builtins

2018-10-24 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:85
 
+BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc")
+

aheejin wrote:
> Do you think we need to provide this builtin also for other vector types?
This builtin is interesting because there is basically no reason for the mask 
to be the same type as the vectors. So we could have 36 versions of this, one 
for each pair of vector types. Or if we required the mask to be a vector of 
integers we could cut that down to just 24 versions. But no matter what types 
you use, this builtin does the exact same thing to the bits. So in the end it 
seems simpler to have just one version and have users convert between vector 
types. Without the `-fno-lax-vector-conversions` flag, clang will silently 
convert between vector types for you anyway, so there's no real ergonomic loss 
either (not that ergonomics really matter for builtins).


Repository:
  rC Clang

https://reviews.llvm.org/D53685



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53722: [WebAssembly] Lower to target-independent saturating add

2018-10-25 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.

Goes along with https://reviews.llvm.org/D53721.


Repository:
  rC Clang

https://reviews.llvm.org/D53722

Files:
  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
@@ -223,28 +223,28 @@
 
 i8x16 add_saturate_s_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_s_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i8x16 add_saturate_u_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_u_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.uadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_s_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_s_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.sadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_u_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_u_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.uadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12614,11 +12614,11 @@
 switch (BuiltinID) {
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_signed;
+  IntNo = Intrinsic::sadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  IntNo = Intrinsic::uadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -223,28 +223,28 @@
 
 i8x16 add_saturate_s_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_s_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i8x16 add_saturate_u_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_u_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.uadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_s_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_s_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.sadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_u_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_u_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.uadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12614,11 +12614,11 @@
 switch (BuiltinID) {
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_signed;
+  IntNo = Intrinsic::sadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  IntNo = Intrinsic::uadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53724: [WebAssembly] Fix type names in truncation builtins

2018-10-25 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, 
sbc100.

Use the same convention as all the other WebAssembly builtin names.


Repository:
  rC Clang

https://reviews.llvm.org/D53724

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
@@ -349,26 +349,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+i64x2 trunc_saturate_s_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+i64x2 trunc_saturate_u_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12524,8 +12524,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -12536,8 +12536,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -91,9 +91,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_f64x2, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_f64x2, "V2LLiV2d", "nc")
 
 #undef BUILTIN


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -349,26 +349,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_f32x4(f32x4 f

[PATCH] D53722: [WebAssembly] Lower to target-independent saturating add

2018-10-25 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345300: [WebAssembly] Lower to target-independent saturating 
add (authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53722

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -223,28 +223,28 @@
 
 i8x16 add_saturate_s_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_s_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i8x16 add_saturate_u_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_u_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.uadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_s_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_s_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.sadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_u_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_u_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.uadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12614,11 +12614,11 @@
 switch (BuiltinID) {
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_signed;
+  IntNo = Intrinsic::sadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  IntNo = Intrinsic::uadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -223,28 +223,28 @@
 
 i8x16 add_saturate_s_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_s_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i8x16 add_saturate_u_i8x16(i8x16 x, i8x16 y) {
   return __builtin_wasm_add_saturate_u_i8x16(x, y);
-  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY: call <16 x i8> @llvm.uadd.sat.v16i8(
   // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_s_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_s_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.sadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 add_saturate_u_i16x8(i16x8 x, i16x8 y) {
   return __builtin_wasm_add_saturate_u_i16x8(x, y);
-  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY: call <8 x i16> @llvm.uadd.sat.v8i16(
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12614,11 +12614,11 @@
 switch (BuiltinID) {
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_signed;
+  IntNo = Intrinsic::sadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
 case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
-  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  IntNo = Intrinsic::uadd_sat;
   break;
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
 case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:

[PATCH] D53685: [WebAssembly] Bitselect and min/max builtins

2018-10-25 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345301: [WebAssembly] Bitselect and min/max builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53685

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

Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/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")
 
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12544,6 +12544,26 @@
  {ResT, Src->getType()});
 return Builder.CreateCall(Callee, {Src});
   }
+  case WebAs

[PATCH] D53724: [WebAssembly] Fix type names in truncation builtins

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:12528
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));

aheejin wrote:
> But unlike others, isn't the input type different from the output type for 
> this builtin? It seems other non-SIMD `saturate_s` intrinsics follow the same 
> convention, `trunc_saturate_s_output_input`. 
Ok, I can put the return type back in. My rationale for removing it was that 
for the SIMD truncations, the return type is uniquely determined by the input 
type, so specifying both in the name is redundant.


Repository:
  rC Clang

https://reviews.llvm.org/D53724



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 172060.
tlively added a comment.
Herald added a subscriber: cfe-commits.

- Restore return types in names


Repository:
  rC Clang

https://reviews.llvm.org/D53675

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
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+i64x2 trunc_saturate_s_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+i64x2 trunc_saturate_u_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12605,8 +12605,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -12617,8 +12617,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -104,9 +104,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc")
 
 #undef BUILTIN


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trun

[PATCH] D53724: [WebAssembly] Fix type names in truncation builtins

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 172061.
tlively added a comment.

- Restore return types in names


Repository:
  rC Clang

https://reviews.llvm.org/D53724

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
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+i64x2 trunc_saturate_s_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+i64x2 trunc_saturate_u_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12605,8 +12605,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -12617,8 +12617,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -104,9 +104,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc")
 
 #undef BUILTIN


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
+  r

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Target/WebAssembly/WebAssemblyInstrSIMD.td:587
 
+multiclass SIMDSelectPat {

aheejin wrote:
> Why do we need this pattern? Can't we also expand `SELECT` as we did for 
> `SELECT_CC` and `VSELECT`?
It looks like the expansions bottom out with `SELECT`. Even when select is set 
to expand, it still shows up in instruction selection.


Repository:
  rC Clang

https://reviews.llvm.org/D53675



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 172072.
tlively added a comment.

- Wrap comments at col 80. Restore proper revision contents.


Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  test/CodeGen/WebAssembly/simd-select.ll
  test/CodeGen/WebAssembly/simd-vselect.ll

Index: test/CodeGen/WebAssembly/simd-vselect.ll
===
--- test/CodeGen/WebAssembly/simd-vselect.ll
+++ /dev/null
@@ -1,90 +0,0 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
-
-; Test that lanewise vector selects lower correctly to bitselects
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
-; CHECK-LABEL: vselect_v16i8:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
-  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
-  ret <16 x i8> %res
-}
-
-; CHECK-LABEL: vselect_v8i16:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
-  %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
-  ret <8 x i16> %res
-}
-
-; CHECK-LABEL: vselect_v4i32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
-  %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
-  ret <4 x i32> %res
-}
-
-; CHECK-LABEL: vselect_v2i64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
-  %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
-  ret <2 x i64> %res
-}
-
-; CHECK-LABEL: vselect_v4f32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
-  %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
-  ret <4 x float> %res
-}
-
-; CHECK-LABEL: vselect_v2f64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
-  %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
-  ret <2 x double> %res
-}
Index: test/CodeGen/WebAssembly/simd-select.ll
===
--- /dev/null
+++ test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,427 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthroug

[PATCH] D53724: [WebAssembly] Fix type names in truncation builtins

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345804: [WebAssembly] Fix type names in truncation builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53724

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


Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -104,9 +104,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc")
 
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+i64x2 trunc_saturate_s_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+i64x2 trunc_saturate_u_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12605,8 +12605,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -12617,8 +12617,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,


Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -104,9 +104,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_tr

[PATCH] D53724: [WebAssembly] Fix type names in truncation builtins

2018-10-31 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345804: [WebAssembly] Fix type names in truncation builtins 
(authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53724?vs=172061&id=172074#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53724

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


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12605,8 +12605,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
@@ -12617,8 +12617,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64x2_f64x2: {
 Value *Src = EmitScalarExpr(E->getArg(0));
 llvm::Type *ResT = ConvertType(E->getType());
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -104,9 +104,9 @@
 BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
 BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
 
-BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc")
 
 #undef BUILTIN
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -409,26 +409,26 @@
   // WEBASSEMBLY: ret
 }
 
-i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+i32x4 trunc_saturate_s_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
-  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+i32x4 trunc_saturate_u_i32x4_f32x4(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_i32x4_f32x4(f);
   // WEBASSEMBLY: call <4 x i32> 
@llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+i64x2 trunc_saturate_s_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
 
-i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
-  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+i64x2 trunc_saturate_u_i64x2_f64x2(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_i64x2_f64x2(f);
   // WEBASSEMBLY: call <2 x i64> 
@llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12605,8 +12605,8 @@
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
   case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
-  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+  case WebAssembly::BI__buil

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-01 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 172280.
tlively added a comment.

- Wrap comment to 80 chars.


Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  test/CodeGen/WebAssembly/simd-select.ll
  test/CodeGen/WebAssembly/simd-vselect.ll

Index: test/CodeGen/WebAssembly/simd-vselect.ll
===
--- test/CodeGen/WebAssembly/simd-vselect.ll
+++ /dev/null
@@ -1,90 +0,0 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
-
-; Test that lanewise vector selects lower correctly to bitselects
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
-; CHECK-LABEL: vselect_v16i8:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
-  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
-  ret <16 x i8> %res
-}
-
-; CHECK-LABEL: vselect_v8i16:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
-  %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
-  ret <8 x i16> %res
-}
-
-; CHECK-LABEL: vselect_v4i32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
-  %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
-  ret <4 x i32> %res
-}
-
-; CHECK-LABEL: vselect_v2i64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
-  %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
-  ret <2 x i64> %res
-}
-
-; CHECK-LABEL: vselect_v4f32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
-  %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
-  ret <4 x float> %res
-}
-
-; CHECK-LABEL: vselect_v2f64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
-  %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
-  ret <2 x double> %res
-}
Index: test/CodeGen/WebAssembly/simd-select.ll
===
--- /dev/null
+++ test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,427 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explic

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-05 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 172708.
tlively added a dependency: D53630: [WebAssembly] Lower vselect.
tlively added a comment.

- Rebase onto SIMD reorganization


Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  test/CodeGen/WebAssembly/simd-select.ll
  test/CodeGen/WebAssembly/simd-vselect.ll

Index: test/CodeGen/WebAssembly/simd-vselect.ll
===
--- test/CodeGen/WebAssembly/simd-vselect.ll
+++ /dev/null
@@ -1,90 +0,0 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
-
-; Test that lanewise vector selects lower correctly to bitselects
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
-; CHECK-LABEL: vselect_v16i8:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
-  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
-  ret <16 x i8> %res
-}
-
-; CHECK-LABEL: vselect_v8i16:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
-  %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
-  ret <8 x i16> %res
-}
-
-; CHECK-LABEL: vselect_v4i32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
-  %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
-  ret <4 x i32> %res
-}
-
-; CHECK-LABEL: vselect_v2i64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
-  %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
-  ret <2 x i64> %res
-}
-
-; CHECK-LABEL: vselect_v4f32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
-  %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
-  ret <4 x float> %res
-}
-
-; CHECK-LABEL: vselect_v2f64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
-  %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
-  ret <2 x double> %res
-}
Index: test/CodeGen/WebAssembly/simd-select.ll
===
--- /dev/null
+++ test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,427 @@
+; RUN: llc < %s -asm-

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-07 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 173119.
tlively added a comment.

- Use automatic expansion instead of patterns


Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  test/CodeGen/WebAssembly/simd-select.ll
  test/CodeGen/WebAssembly/simd-vselect.ll

Index: test/CodeGen/WebAssembly/simd-vselect.ll
===
--- test/CodeGen/WebAssembly/simd-vselect.ll
+++ /dev/null
@@ -1,90 +0,0 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
-
-; Test that lanewise vector selects lower correctly to bitselects
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
-; CHECK-LABEL: vselect_v16i8:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
-  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
-  ret <16 x i8> %res
-}
-
-; CHECK-LABEL: vselect_v8i16:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
-  %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
-  ret <8 x i16> %res
-}
-
-; CHECK-LABEL: vselect_v4i32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
-  %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
-  ret <4 x i32> %res
-}
-
-; CHECK-LABEL: vselect_v2i64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
-  %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
-  ret <2 x i64> %res
-}
-
-; CHECK-LABEL: vselect_v4f32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
-  %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
-  ret <4 x float> %res
-}
-
-; CHECK-LABEL: vselect_v2f64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
-  %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
-  ret <2 x double> %res
-}
Index: test/CodeGen/WebAssembly/simd-select.ll
===
--- /dev/null
+++ test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,463 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers 

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-07 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In https://reviews.llvm.org/D53675#1290660, @aheejin wrote:

> I tried to add `ISD::SELECT` in the expansion list, like
>
>   for (auto Op : {ISD::VSELECT, ISD::SELECT_CC, ISD::SELECT}) {
> ...
>   }
>   
>
> And the code generation apparently works for current test `simd-select.ll`. 
> I'm not sure if it's optimal though. Could you check again?


I'm not sure what I did before, but you're totally right. Letting the expander 
take care of selects yields the same code in most places and actually allows 
some DAGCombine optimizations that weren't possible before.


Repository:
  rL LLVM

https://reviews.llvm.org/D53675



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-07 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 173120.
tlively added a comment.

- Update comment


Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  test/CodeGen/WebAssembly/simd-select.ll
  test/CodeGen/WebAssembly/simd-vselect.ll

Index: test/CodeGen/WebAssembly/simd-vselect.ll
===
--- test/CodeGen/WebAssembly/simd-vselect.ll
+++ /dev/null
@@ -1,90 +0,0 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
-
-; Test that lanewise vector selects lower correctly to bitselects
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
-; CHECK-LABEL: vselect_v16i8:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
-; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
-  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
-  ret <16 x i8> %res
-}
-
-; CHECK-LABEL: vselect_v8i16:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
-; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
-  %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
-  ret <8 x i16> %res
-}
-
-; CHECK-LABEL: vselect_v4i32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
-  %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
-  ret <4 x i32> %res
-}
-
-; CHECK-LABEL: vselect_v2i64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
-  %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
-  ret <2 x i64> %res
-}
-
-; CHECK-LABEL: vselect_v4f32:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
-; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
-  %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
-  ret <4 x float> %res
-}
-
-; CHECK-LABEL: vselect_v2f64:
-; CHECK-NEXT: .param v128, v128, v128{{$}}
-; CHECK-NEXT: .result v128{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
-; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
-; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
-; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
-  %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
-  ret <2 x double> %res
-}
Index: test/CodeGen/WebAssembly/simd-select.ll
===
--- /dev/null
+++ test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,463 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-si

[PATCH] D53675: [WebAssembly] Lower select for vectors

2018-11-08 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL346462: [WebAssembly] Lower select for vectors (authored by 
tlively, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D53675

Files:
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/trunk/test/CodeGen/WebAssembly/simd-select.ll
  llvm/trunk/test/CodeGen/WebAssembly/simd-vselect.ll

Index: llvm/trunk/test/CodeGen/WebAssembly/simd-select.ll
===
--- llvm/trunk/test/CodeGen/WebAssembly/simd-select.ll
+++ llvm/trunk/test/CodeGen/WebAssembly/simd-select.ll
@@ -0,0 +1,463 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext | FileCheck %s
+
+; Test that vector selects of various varieties lower correctly to bitselects.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; ==
+; 16 x i8
+; ==
+; CHECK-LABEL: vselect_v16i8:
+; CHECK-NEXT: .param v128, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
+; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
+; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
+; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
+  %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
+  ret <16 x i8> %res
+}
+
+; CHECK-LABEL: select_v16i8:
+; CHECK-NEXT: .param i32, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
+; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
+; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <16 x i8> @select_v16i8(i1 %c, <16 x i8> %x, <16 x i8> %y) {
+  %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
+  ret <16 x i8> %res
+}
+
+; CHECK-LABEL: select_cmp_v16i8:
+; CHECK-NEXT: .param i32, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31
+; CHECK-NEXT: i32.shr_s $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
+; CHECK-NEXT: i8x16.splat $push[[L2:[0-9]+]]=, $pop[[L1]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L2]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <16 x i8> @select_cmp_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
+  %c = icmp slt i32 %i, 0
+  %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
+  ret <16 x i8> %res
+}
+
+; CHECK-LABEL: select_ne_v16i8:
+; CHECK-NEXT: .param i32, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
+; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
+; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <16 x i8> @select_ne_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
+  %c = icmp ne i32 %i, 0
+  %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
+  ret <16 x i8> %res
+}
+
+; CHECK-LABEL: select_eq_v16i8:
+; CHECK-NEXT: .param i32, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, -1{{$}}
+; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
+; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <16 x i8> @select_eq_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
+  %c = icmp eq i32 %i, 0
+  %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
+  ret <16 x i8> %res
+}
+
+; ==
+; 8 x i16
+; ==
+; CHECK-LABEL: vselect_v8i16:
+; CHECK-NEXT: .param v128, v128, v128{{$}}
+; CHECK-NEXT: .result v128{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
+; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
+; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
+; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
+; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define <8 x i

[PATCH] D58742: [WebAssembly] Remove uses of ThreadModel

2019-02-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, sbc100, dschuff.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, jfb, rupprecht, 
dexonsmith, steven_wu, sunfish, hiraditya, jgravelle-google, mehdi_amini.
Herald added projects: clang, LLVM.

In the clang UI, replaces -mthread-model posix with -matomics as the
source of truth on threading. In the backend, replaces
-thread-model=posix with the atomics target feature, which is now
collected on the WebAssemblyTargetMachine along with all other used
features. These collected features will also be used to emit the
target features section in the future.

The default configuration for the backend is thread-model=posix and no
atomics, which was previously an invalid configuration. This change
makes the default valid because the thread model is ignored.

A side effect of this change is that objects are never emitted with
passive segments. It will instead be up to the linker to decide
whether sections should be active or passive based on whether atomics
are used in the final link.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58742

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Driver/ToolChains/WebAssembly.h
  clang/test/Driver/wasm-toolchain.c
  clang/test/Preprocessor/wasm-target-features.c
  lld/test/wasm/init-fini.ll
  lld/test/wasm/lto/atomics.ll
  lld/wasm/LTO.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h
  llvm/test/CodeGen/WebAssembly/atomic-mem-consistency.ll
  llvm/test/CodeGen/WebAssembly/atomic-rmw.ll
  llvm/test/CodeGen/WebAssembly/global.ll
  llvm/test/CodeGen/WebAssembly/tls.ll
  llvm/test/CodeGen/WebAssembly/vtable.ll
  llvm/test/MC/WebAssembly/bss.ll
  llvm/test/MC/WebAssembly/comdat.ll
  llvm/test/MC/WebAssembly/debug-info.ll
  llvm/test/MC/WebAssembly/explicit-sections.ll
  llvm/test/MC/WebAssembly/external-data.ll
  llvm/test/MC/WebAssembly/external-func-address.ll
  llvm/test/MC/WebAssembly/global-ctor-dtor.ll
  llvm/test/MC/WebAssembly/init-flags.ll
  llvm/test/MC/WebAssembly/reloc-data.ll
  llvm/test/MC/WebAssembly/unnamed-data.ll
  llvm/test/MC/WebAssembly/weak-alias.ll
  llvm/test/tools/llvm-nm/wasm/local-symbols.ll
  llvm/test/tools/llvm-objdump/WebAssembly/relocations.test

Index: llvm/test/tools/llvm-objdump/WebAssembly/relocations.test
===
--- llvm/test/tools/llvm-objdump/WebAssembly/relocations.test
+++ llvm/test/tools/llvm-objdump/WebAssembly/relocations.test
@@ -1,4 +1,4 @@
-; RUN: llc -thread-model=single -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
+; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
 
 @foo = external global i32, align 4
 @bar = global i32* @foo, align 4
Index: llvm/test/tools/llvm-nm/wasm/local-symbols.ll
===
--- llvm/test/tools/llvm-nm/wasm/local-symbols.ll
+++ llvm/test/tools/llvm-nm/wasm/local-symbols.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj -thread-model=single -mtriple=wasm32-unknown-unknown -o %t.o %s
+; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s
 ; RUN: llvm-nm %t.o | FileCheck %s
 
 @foo = internal global i32 1, align 4
Index: llvm/test/MC/WebAssembly/weak-alias.ll
===
--- llvm/test/MC/WebAssembly/weak-alias.ll
+++ llvm/test/MC/WebAssembly/weak-alias.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj -thread-model=single -wasm-keep-registers %s -o %t.o
+; RUN: llc -filetype=obj -wasm-keep-registers %s -o %t.o
 ; RUN: obj2yaml %t.o | FileCheck %s
 ; RUN: llvm-objdump -t %t.o | FileCheck --check-prefix=CHECK-SYMS %s
 
Index: llvm/test/MC/WebAssembly/unnamed-data.ll
===
--- llvm/test/MC/WebAssembly/unnamed-data.ll
+++ llvm/test/MC/WebAssembly/unnamed-data.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
+; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
 
 target triple = "wasm32-unknown-unknown"
 
Index: llvm/test/MC/WebAssembly/reloc-data.ll
===
--- llvm/test/MC/WebAssembly/reloc-data.ll
+++ llvm/test/MC/WebAssembly/reloc-data.ll
@@ -1,4 +1,4 @@
-; RUN: llc -O0 -filetype=obj -thread-model=single %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s
+; RUN: llc -O0 -filetype=obj %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s
 
 target triple = "wasm32-unknown-unknown"
 
Index: llvm/test/MC/WebAssembly/init-flags.ll
=

[PATCH] D58742: [WebAssembly] Remove uses of ThreadModel

2019-02-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively marked an inline comment as done.
tlively added inline comments.



Comment at: llvm/test/CodeGen/WebAssembly/atomic-mem-consistency.ll:1
-; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt
 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt 
-wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | 
FileCheck %s

sbc100 wrote:
> What did this start passing?   Is it because llc now has the correct default 
> and will lower atomics to non-atomics?  I guess there is no longer a way to 
> make this fail in the way that it did before.. which is good?
Precisely :D


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58742/new/

https://reviews.llvm.org/D58742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58742: [WebAssembly] Remove uses of ThreadModel

2019-02-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

I'll wait and see if @aheejin has any concerns before landing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58742/new/

https://reviews.llvm.org/D58742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58742: [WebAssembly] Remove uses of ThreadModel

2019-02-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively marked an inline comment as done.
tlively added a comment.

In D58742#1413077 , @sunfish wrote:

> This is still a little confusing to me. -matomic is supposed to be a 
> subtarget flag, stating that the wasm implementation we will run on supports 
> atomic instructions. -mthread-model posix is about the C++ interpretation -- 
> what style implementation of memory model do we want? In the future, -matomic 
> may become enabled by default, when enough wasm engines generally support it. 
> However, -mthread-model single/posix may still be useful to control 
> independently, because even with wasm engines supporting atomic, there are 
> reasons users might still want to compile their apps single-threaded: access 
> to linear memory with no declared max, lower overall code size, or other 
> things.


The only backend besides us that uses the ThreadModel at all is ARM, so we were 
questioning its generality. I originally shared your opinion that the available 
target features should be controlled separately from whether or not the user 
wants threads, but in reality we get to use the atomics feature if and only if 
the user opts in to threads. Because of this, ignoring the thread model 
entirely like most other backends lets us have a much simpler user interface 
that is not invalid by default.

I expect with this model we would never turn on atomics by default (since we 
don't want multithreaded by default), and most users would get them by using 
-pthread. This is very close in UI to native targets. The -matomics option is 
only there for users who are doing weird threaded things but don't want 
libpthread for some reason.




Comment at: clang/include/clang/Driver/ToolChain.h:456
   /// getThreadModel() - Which thread model does this target use?
-  virtual std::string getThreadModel(const llvm::opt::ArgList &) const {
-return "posix";
-  }
+  virtual std::string getThreadModel() const { return "posix"; }
 

aheejin wrote:
> I think now we can delete this overridden method, because the default value 
> for this is "posix". See Dan's [[ 
> https://github.com/llvm/llvm-project/commit/1384ee936e46816f348bc3756704aeaff92e86fe
>  | commit ]].
I did delete the overridden method below in 
clang/lib/Driver/ToolChains/WebAssembly.cpp. This is restoring the base class 
implementation to the way it was before your CL added the ArgList argument, 
since we no longer need it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58742/new/

https://reviews.llvm.org/D58742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58742: [WebAssembly] Remove uses of ThreadModel

2019-02-28 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD355112: [WebAssembly] Remove uses of ThreadModel (authored 
by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58742?vs=188634&id=188758#toc

Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58742/new/

https://reviews.llvm.org/D58742

Files:
  test/wasm/init-fini.ll
  test/wasm/lto/atomics.ll
  wasm/LTO.cpp


Index: test/wasm/init-fini.ll
===
--- test/wasm/init-fini.ll
+++ test/wasm/init-fini.ll
@@ -1,5 +1,5 @@
-; RUN: llc -filetype=obj -thread-model=single -o %t.o %s
-; RUN: llc -filetype=obj -thread-model=single %S/Inputs/global-ctor-dtor.ll -o 
%t.global-ctor-dtor.o
+; RUN: llc -filetype=obj -o %t.o %s
+; RUN: llc -filetype=obj %S/Inputs/global-ctor-dtor.ll -o %t.global-ctor-dtor.o
 
 target triple = "wasm32-unknown-unknown"
 
Index: test/wasm/lto/atomics.ll
===
--- test/wasm/lto/atomics.ll
+++ test/wasm/lto/atomics.ll
@@ -1,7 +1,8 @@
 ; RUN: llvm-as %s -o %t.o
 ; RUN: wasm-ld %t.o -o %t.wasm -lto-O0
-; Atomic operations with fail to compile if the ThreadModel is not
-; correctly set to Single (i.e. if atomics are not lowered to regular ops).
+
+; Atomic operations will not fail to compile if atomics are not
+; enabled because LLVM atomics will be lowered to regular ops.
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown-wasm"
Index: wasm/LTO.cpp
===
--- wasm/LTO.cpp
+++ wasm/LTO.cpp
@@ -47,9 +47,6 @@
   C.Options.FunctionSections = true;
   C.Options.DataSections = true;
 
-  // Wasm currently only supports ThreadModel::Single
-  C.Options.ThreadModel = ThreadModel::Single;
-
   C.DisableVerify = Config->DisableVerify;
   C.DiagHandler = diagnosticHandler;
   C.OptLevel = Config->LTOO;


Index: test/wasm/init-fini.ll
===
--- test/wasm/init-fini.ll
+++ test/wasm/init-fini.ll
@@ -1,5 +1,5 @@
-; RUN: llc -filetype=obj -thread-model=single -o %t.o %s
-; RUN: llc -filetype=obj -thread-model=single %S/Inputs/global-ctor-dtor.ll -o %t.global-ctor-dtor.o
+; RUN: llc -filetype=obj -o %t.o %s
+; RUN: llc -filetype=obj %S/Inputs/global-ctor-dtor.ll -o %t.global-ctor-dtor.o
 
 target triple = "wasm32-unknown-unknown"
 
Index: test/wasm/lto/atomics.ll
===
--- test/wasm/lto/atomics.ll
+++ test/wasm/lto/atomics.ll
@@ -1,7 +1,8 @@
 ; RUN: llvm-as %s -o %t.o
 ; RUN: wasm-ld %t.o -o %t.wasm -lto-O0
-; Atomic operations with fail to compile if the ThreadModel is not
-; correctly set to Single (i.e. if atomics are not lowered to regular ops).
+
+; Atomic operations will not fail to compile if atomics are not
+; enabled because LLVM atomics will be lowered to regular ops.
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown-wasm"
Index: wasm/LTO.cpp
===
--- wasm/LTO.cpp
+++ wasm/LTO.cpp
@@ -47,9 +47,6 @@
   C.Options.FunctionSections = true;
   C.Options.DataSections = true;
 
-  // Wasm currently only supports ThreadModel::Single
-  C.Options.ThreadModel = ThreadModel::Single;
-
   C.DisableVerify = Config->DisableVerify;
   C.DiagHandler = diagnosticHandler;
   C.OptLevel = Config->LTOO;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58854: [WebAssembly] Temporarily disable bulk-memory with -pthread

2019-03-01 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: sbc100.
Herald added subscribers: cfe-commits, jfb, sunfish, aheejin, jgravelle-google, 
dschuff.
Herald added a project: clang.
aheejin accepted this revision.
This revision is now accepted and ready to land.

To prevent the instability of bulk-memory in the wasm backend from
blocking separate pthread testing, temporarily remove the logic that
adds -mbulk-memory in the presence of -pthread. Since browsers will
ship bulk memory before or alongside threads, this change will be
reverted as soon as bulk memory has stabilized in the backend.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58854

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c
  clang/test/Preprocessor/wasm-target-features.c


Index: clang/test/Preprocessor/wasm-target-features.c
===
--- clang/test/Preprocessor/wasm-target-features.c
+++ clang/test/Preprocessor/wasm-target-features.c
@@ -59,8 +59,7 @@
 // RUN: -target wasm64-unknown-unknown -matomics \
 // RUN:   | FileCheck %s -check-prefix=ATOMICS
 //
-// ATOMICS-DAG:#define __wasm_atomics__ 1{{$}}
-// ATOMICS-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// ATOMICS:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -pthread \
@@ -69,8 +68,7 @@
 // RUN: -target wasm64-unknown-unknown -pthread \
 // RUN:   | FileCheck %s -check-prefix=PTHREAD
 //
-// PTHREAD-DAG:#define __wasm_atomics__ 1{{$}}
-// PTHREAD-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// PTHREAD:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -41,18 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '-target-feature 
+bulk-memory'
+// '-pthread' sets '-target-feature +atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
-
-// '-pthread' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_BULKMEM %s
-// PTHREAD_NO_BULKMEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
-
-// '-matomics' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -matomics -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=ATOMICS_NO_BULKMEM %s
-// ATOMICS_NO_BULKMEM: invalid argument '-matomics' not allowed with 
'-mno-bulk-memory'
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -124,8 +124,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics' and
-  // '-target-feature +bulk-memory'
+  // '-pthread' implies '-target-feature +atomics'
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -133,27 +132,8 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-pthread"
-  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
-  }
-
-  // '-matomics' implies '-mbulk-memory'
-  if (DriverArgs.hasFlag(options::OPT_matomics, options::OPT_mno_atomics,
- false)) {
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-mato

[PATCH] D58854: [WebAssembly] Temporarily disable bulk-memory with -pthread

2019-03-01 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC355248: [WebAssembly] Temporarily disable bulk-memory with 
-pthread (authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58854?vs=188997&id=189000#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58854/new/

https://reviews.llvm.org/D58854

Files:
  lib/Driver/ToolChains/WebAssembly.cpp
  test/Driver/wasm-toolchain.c
  test/Preprocessor/wasm-target-features.c


Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.c
@@ -59,8 +59,7 @@
 // RUN: -target wasm64-unknown-unknown -matomics \
 // RUN:   | FileCheck %s -check-prefix=ATOMICS
 //
-// ATOMICS-DAG:#define __wasm_atomics__ 1{{$}}
-// ATOMICS-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// ATOMICS:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -pthread \
@@ -69,8 +68,7 @@
 // RUN: -target wasm64-unknown-unknown -pthread \
 // RUN:   | FileCheck %s -check-prefix=PTHREAD
 //
-// PTHREAD-DAG:#define __wasm_atomics__ 1{{$}}
-// PTHREAD-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// PTHREAD:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
Index: test/Driver/wasm-toolchain.c
===
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -41,18 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '-target-feature 
+bulk-memory'
+// '-pthread' sets '-target-feature +atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
-
-// '-pthread' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_BULKMEM %s
-// PTHREAD_NO_BULKMEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
-
-// '-matomics' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -matomics -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=ATOMICS_NO_BULKMEM %s
-// ATOMICS_NO_BULKMEM: invalid argument '-matomics' not allowed with 
'-mno-bulk-memory'
Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -124,8 +124,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics' and
-  // '-target-feature +bulk-memory'
+  // '-pthread' implies '-target-feature +atomics'
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -133,27 +132,8 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-pthread"
-  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
-  }
-
-  // '-matomics' implies '-mbulk-memory'
-  if (DriverArgs.hasFlag(options::OPT_matomics, options::OPT_mno_atomics,
- false)) {
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-matomics"
-  << "-mno-bulk-memory";
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
   }
 }
 


Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.

[PATCH] D59721: [WebAssembly] Make driver -pthread imply linker --shared-memory

2019-03-22 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: sbc100, aheejin.
Herald added subscribers: cfe-commits, jfb, sunfish, jgravelle-google, dschuff.
Herald added a project: clang.

This eliminates a linker error the user might otherwise see about how
using the 'atomics' feature requires --shared-memory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59721

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -41,9 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics'
+// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -62,8 +62,10 @@
 if (ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
-if (Args.hasArg(options::OPT_pthread))
+if (Args.hasArg(options::OPT_pthread)) {
   CmdArgs.push_back("-lpthread");
+  CmdArgs.push_back("--shared-memory");
+}
 
 CmdArgs.push_back("-lc");
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -41,9 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics'
+// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -62,8 +62,10 @@
 if (ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
-if (Args.hasArg(options::OPT_pthread))
+if (Args.hasArg(options::OPT_pthread)) {
   CmdArgs.push_back("-lpthread");
+  CmdArgs.push_back("--shared-memory");
+}
 
 CmdArgs.push_back("-lc");
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59721: [WebAssembly] Make driver -pthread imply linker --shared-memory

2019-03-22 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356817: [WebAssembly] Make driver -pthread imply linker 
--shared-memory (authored by tlively, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59721?vs=191955&id=191961#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59721/new/

https://reviews.llvm.org/D59721

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/test/Driver/wasm-toolchain.c


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -41,9 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics'
+// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -62,8 +62,10 @@
 if (ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
-if (Args.hasArg(options::OPT_pthread))
+if (Args.hasArg(options::OPT_pthread)) {
   CmdArgs.push_back("-lpthread");
+  CmdArgs.push_back("--shared-memory");
+}
 
 CmdArgs.push_back("-lc");
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -41,9 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics'
+// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -62,8 +62,10 @@
 if (ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
-if (Args.hasArg(options::OPT_pthread))
+if (Args.hasArg(options::OPT_pthread)) {
   CmdArgs.push_back("-lpthread");
+  CmdArgs.push_back("--shared-memory");
+}
 
 CmdArgs.push_back("-lc");
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60013: [WebAssembly] Add mutable globals feature

2019-03-29 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, sunfish, 
hiraditya, jgravelle-google, sbc100.
Herald added projects: clang, LLVM.

This feature is not actually used for anything in the WebAssembly
backend, but adding it allows users to get it into the target features
sections of their objects, which makes these objects
future-compatible.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60013

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/Preprocessor/wasm-target-features.c
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/test/CodeGen/WebAssembly/mutable-globals.ll

Index: llvm/test/CodeGen/WebAssembly/mutable-globals.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/mutable-globals.ll
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mattr=+mutable-globals | FileCheck %s
+
+; Test that mutable globals is properly emitted into the target features section
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define void @foo() {
+  ret void
+}
+
+; CHECK-LABEL: .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 15
+; CHECK-NEXT: .ascii "mutable-globals"
Index: llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -44,6 +44,7 @@
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMutableGlobals = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -97,6 +98,7 @@
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMutableGlobals() const { return HasMutableGlobals; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
Index: llvm/lib/Target/WebAssembly/WebAssembly.td
===
--- llvm/lib/Target/WebAssembly/WebAssembly.td
+++ llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -51,6 +51,10 @@
   SubtargetFeature<"bulk-memory", "HasBulkMemory", "true",
"Enable bulk memory operations">;
 
+def FeatureMutableGlobals :
+  SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true",
+   "Enable mutable globals">;
+
 //===--===//
 // Architectures.
 //===--===//
Index: clang/test/Preprocessor/wasm-target-features.c
===
--- clang/test/Preprocessor/wasm-target-features.c
+++ clang/test/Preprocessor/wasm-target-features.c
@@ -70,6 +70,15 @@
 //
 // PTHREAD:#define __wasm_atomics__ 1{{$}}
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mmutable-globals \
+// RUN:   | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mmutable-globals \
+// RUN:   | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+//
+// MUTABLE-GLOBALS:#define __wasm_mutable_globals__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
 // RUN:   | FileCheck %s -check-prefix=MVP
@@ -84,6 +93,7 @@
 // MVP-NOT:#define __wasm_exception_handling__
 // MVP-NOT:#define __wasm_bulk_memory__
 // MVP-NOT:#define __wasm_atomics__
+// MVP-NOT:#define __wasm_mutable_globals__
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
@@ -96,6 +106,7 @@
 // BLEEDING-EDGE-DAG:#define __wasm_sign_ext__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_simd128__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_mutable_globals__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -35,6 +35,7 @@
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
   bool HasAtomics = false;
+  bool HasMutableGlobals = false;
 
 public:
   explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Index: clang/lib/Basic/Targets/WebAssembly.cpp
=

[PATCH] D60013: [WebAssembly] Add mutable globals feature

2019-03-29 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357321: [WebAssembly] Add mutable globals feature (authored 
by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60013?vs=192911&id=192925#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60013/new/

https://reviews.llvm.org/D60013

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Basic/Targets/WebAssembly.cpp
  cfe/trunk/lib/Basic/Targets/WebAssembly.h
  cfe/trunk/test/Preprocessor/wasm-target-features.c
  llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
  llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/trunk/test/CodeGen/WebAssembly/mutable-globals.ll

Index: llvm/trunk/test/CodeGen/WebAssembly/mutable-globals.ll
===
--- llvm/trunk/test/CodeGen/WebAssembly/mutable-globals.ll
+++ llvm/trunk/test/CodeGen/WebAssembly/mutable-globals.ll
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mattr=+mutable-globals | FileCheck %s
+
+; Test that mutable globals is properly emitted into the target features section
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define void @foo() {
+  ret void
+}
+
+; CHECK-LABEL: .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 15
+; CHECK-NEXT: .ascii "mutable-globals"
Index: llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
+++ llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
@@ -51,6 +51,10 @@
   SubtargetFeature<"bulk-memory", "HasBulkMemory", "true",
"Enable bulk memory operations">;
 
+def FeatureMutableGlobals :
+  SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true",
+   "Enable mutable globals">;
+
 //===--===//
 // Architectures.
 //===--===//
Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -44,6 +44,7 @@
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMutableGlobals = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -97,6 +98,7 @@
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMutableGlobals() const { return HasMutableGlobals; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2177,6 +2177,8 @@
 def mno_atomics : Flag<["-"], "mno-atomics">, Group;
 def mbulk_memory : Flag<["-"], "mbulk-memory">, Group;
 def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, Group;
+def mmutable_globals : Flag<["-"], "mmutable-globals">, Group;
+def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, Group;
 
 def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">,
   Flags<[HelpHidden]>,
Index: cfe/trunk/test/Preprocessor/wasm-target-features.c
===
--- cfe/trunk/test/Preprocessor/wasm-target-features.c
+++ cfe/trunk/test/Preprocessor/wasm-target-features.c
@@ -71,6 +71,15 @@
 // PTHREAD:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mmutable-globals \
+// RUN:   | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mmutable-globals \
+// RUN:   | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+//
+// MUTABLE-GLOBALS:#define __wasm_mutable_globals__ 1{{$}}
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
 // RUN:   | FileCheck %s -check-prefix=MVP
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -84,6 +93,7 @@
 // MVP-NOT:#define __wasm_exception_handling__
 // MVP-NOT:#define __wasm_bulk_memory__
 // MVP-NOT:#define __wasm_atomics__
+// MVP-NOT:#define __wasm_mutable_globals__
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
@@ -96,6 +106,7 @@
 // BLEEDING-EDGE-DAG:#define __wasm_sign_ext__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_simd128__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
+// BLEEDING-EDG

[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, 
sbc100.

Repository:
  rC Clang

https://reviews.llvm.org/D52852

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
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12427,6 +12427,28 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = EmitScalarExpr(E->getArg(1));
+Value *Extract = Builder.CreateExtractElement(Vec, Lane);
+return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+  }
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = EmitScalarExpr(E->getArg(1));
+Value *Extract = Builder.CreateExtractElement(Vec, Lane);
+return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+  }
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = EmitScalarExpr(E->getArg(1));
+return Builder.CreateExtractElement(Vec, Lane);
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basi

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
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


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) {

[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
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/D52856.


Repository:
  rC Clang

https://reviews.llvm.org/D52858

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
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12467,6 +12467,40 @@
 Value *Val = EmitScalarExpr(E->getArg(2));
 return Builder.CreateInsertElement(Vec, Val, Lane);
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_unsigned;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "ncV:128:")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "ncV:128:")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "ncV:128:")
+BUILTIN(__builtin_wasm_add_s

[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168222.
tlively marked an inline comment as done.
tlively added a comment.

- use isIntegerConstantExpr to force constant folding of lanes


Repository:
  rC Clang

https://reviews.llvm.org/D52852

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
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12427,6 +12427,36 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  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:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_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 *Extract = Builder.CreateExtractElement(Vec, Lane);
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+case WebAssem

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168223.
tlively added a comment.

- Force constant folding for lane


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
@@ -12457,6 +12457,34 @@
   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: 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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168224.
tlively added a comment.

- Rebase


Repository:
  rC Clang

https://reviews.llvm.org/D52858

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
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12485,6 +12485,40 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_unsigned;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "ncV:128:")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "ncV:128:")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "ncV:128:")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "ncV:128:")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "ncV:128:")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8

[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-03 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:46
+BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "ncV:128:")
+BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "ncV:128:")
+BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "ncV:128:")

craig.topper wrote:
> aheejin wrote:
> > - I guess the return types should be the same as its element type, because 
> > we are translating to not wasm but LLVM IR instructions and 
> > `extractelement`'s return type and element type are the same.
> > - What does `I` mean in the second argument? The instruction says it is 
> > required for constant folding. How is the generated IR different if we use 
> > it?
> The I makes Sema ensure it is a Integer Constant Expression.
I want these builtins to mimic the underlying wasm instructions as much as 
possible. I believe end users are more likely to be looking at the WebAssembly 
spec than the LLVM  language reference when using these functions.


Repository:
  rC Clang

https://reviews.llvm.org/D52852



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:59
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "ncV:128:")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "ncV:128:")

craig.topper wrote:
> Don't copy the "V:128:" part from X86. You just need the "nc".  The V:128: is 
> a special thing I'm working on for our AVX512 frequency issues.
ok, sounds good


Repository:
  rC Clang

https://reviews.llvm.org/D52858



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:55
+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:")

craig.topper wrote:
> aheejin wrote:
> > craig.topper wrote:
> > > I think maybe you want LL instead of W, but I'm not sure.
> > Not sure what the differences are either. I've used LL for other builtins 
> > in this file though.
> W changes based on what's returned from getInt64Type() for the target. I 
> think it will be either L or LL. It looks to be almost exclusively used by 
> MSVC compatibility intrinsics except for two builtins in NVPTX.
Ok, I'll switch to using LL.


Repository:
  rC Clang

https://reviews.llvm.org/D52856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168385.
tlively added a comment.

- Replace Wi with LLi in signature string
- Remove unnecessary V:128: attribute


Repository:
  rC Clang

https://reviews.llvm.org/D52852

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
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12427,6 +12427,36 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  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:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_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 *Extract = Builder.CreateExtractElement(Vec, Lane);
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_ext

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168387.
tlively added a comment.

- Replace Wi with LLi and remove V:128:


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
@@ -12457,6 +12457,34 @@
   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: 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", "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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168388.
tlively added a comment.

- Remove V:128: attributes


Repository:
  rC Clang

https://reviews.llvm.org/D52858

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
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12485,6 +12485,40 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_unsigned;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
+

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In https://reviews.llvm.org/D52856#1255905, @dschuff wrote:

> W is int64_t (which is long long for wasm32 and would probably be long for 
> wasm64 since that would probably LP64 (like Linux) rather than LLP64 (Like 
> Win64). So if we want it to be the same for both wasm32 and wasm64, I guess 
> we want LL.


Ideally I would be able to exactly specify int8_t, int32_t, etc, but c/s/i/LLi 
works too.


Repository:
  rC Clang

https://reviews.llvm.org/D52856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52910: [WebAssembly] any_true and all_true builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
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/D52858.


Repository:
  rC Clang

https://reviews.llvm.org/D52910

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
@@ -228,3 +228,51 @@
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
+
+int f33(i8x16 x) {
+  return __builtin_wasm_any_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f34(i16x8 x) {
+  return __builtin_wasm_any_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f35(i32x4 x) {
+  return __builtin_wasm_any_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f36(i64x2 x) {
+  return __builtin_wasm_any_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f37(i8x16 x) {
+  return __builtin_wasm_all_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f38(i16x8 x) {
+  return __builtin_wasm_all_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f39(i32x4 x) {
+  return __builtin_wasm_all_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f40(i64x2 x) {
+  return __builtin_wasm_all_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12519,6 +12519,35 @@
 Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  IntNo = Intrinsic::wasm_anytrue;
+  break;
+case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+case WebAssembly::BI__builtin_wasm_all_true_i64x2:
+  IntNo = Intrinsic::wasm_alltrue;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(IntNo, 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
@@ -66,4 +66,13 @@
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "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")
+BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
+BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
+
 #undef BUILTIN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
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


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_f64

[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343834: [WebAssembly] __builtin_wasm_extract_lane_* builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52852

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

Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -39,4 +39,14 @@
 BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
 
+// SIMD builtins
+BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12444,6 +12444,36 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  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:
+  case WebAssembly::

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343835: [WebAssembly] __builtin_wasm_replace_lane_* builtins 
(authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52856?vs=168387&id=168421#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52856

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

Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12474,6 +12474,34 @@
   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: 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", "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: 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
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343836: [WebAssembly] saturating arithmetic builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52858

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

Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
+BUILTIN(__builtin_wasm_sub_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12502,6 +12502,40 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  br

[PATCH] D52910: [WebAssembly] any_true and all_true builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343837: [WebAssembly] any_true and all_true builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52910

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

Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12536,6 +12536,35 @@
 Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  IntNo = Intrinsic::wasm_anytrue;
+  break;
+case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+case WebAssembly::BI__builtin_wasm_all_true_i64x2:
+  IntNo = Intrinsic::wasm_alltrue;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -66,4 +66,13 @@
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "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")
+BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
+BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -228,3 +228,51 @@
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
+
+int f33(i8x16 x) {
+  return __builtin_wasm_any_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f34(i16x8 x) {
+  return __builtin_wasm_any_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f35(i32x4 x) {
+  return __builtin_wasm_any_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f36(i64x2 x) {
+  return __builtin_wasm_any_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f37(i8x16 x) {
+  return __builtin_wasm_all_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f38(i16x8 x) {
+  return __builtin_wasm_all_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f39(i32x4 x) {
+  return __builtin_wasm_all_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f40(i64x2 x) {
+  return __builtin_wasm_all_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343838: [WebAssembly] abs and sqrt builtins (authored by 
tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52913

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


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,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: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/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


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,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: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -75

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

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343838: [WebAssembly] abs and sqrt builtins (authored by 
tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52913?vs=168402&id=168424#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52913

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


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
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
@@ -12565,6 +12565,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
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
@@ -12565,6 +12565,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 = Emit

[PATCH] D53007: [WebAssembly][NFC] Rename test functions for builtins

2018-10-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, kristina, jfb, sunfish, 
jgravelle-google, sbc100.

Repository:
  rC Clang

https://reviews.llvm.org/D53007

Files:
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -17,285 +17,285 @@
 typedef float f32x4 __attribute((vector_size(16)));
 typedef double f64x2 __attribute((vector_size(16)));
 
-__SIZE_TYPE__ f0(void) {
+__SIZE_TYPE__ memory_size(void) {
   return __builtin_wasm_memory_size(0);
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.memory.size.i32(i32 0)
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.memory.size.i64(i32 0)
 }
 
-__SIZE_TYPE__ f1(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ memory_grow(__SIZE_TYPE__ delta) {
   return __builtin_wasm_memory_grow(0, delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.memory.grow.i64(i32 0, i64 %{{.*}})
 }
 
-__SIZE_TYPE__ f2(void) {
+__SIZE_TYPE__ mem_size(void) {
   return __builtin_wasm_mem_size(0);
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.mem.size.i32(i32 0)
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.mem.size.i64(i32 0)
 }
 
-__SIZE_TYPE__ f3(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ mem_grow(__SIZE_TYPE__ delta) {
   return __builtin_wasm_mem_grow(0, delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.mem.grow.i32(i32 0, i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.mem.grow.i64(i32 0, i64 %{{.*}})
 }
 
-__SIZE_TYPE__ f4(void) {
+__SIZE_TYPE__ current_memory(void) {
   return __builtin_wasm_current_memory();
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.current.memory.i32()
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.current.memory.i64()
 }
 
-__SIZE_TYPE__ f5(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ grow_memory(__SIZE_TYPE__ delta) {
   return __builtin_wasm_grow_memory(delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.grow.memory.i32(i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.grow.memory.i64(i64 %{{.*}})
 }
 
-void f6(unsigned int tag, void *obj) {
+void throw(unsigned int tag, void *obj) {
   return __builtin_wasm_throw(tag, obj);
   // WEBASSEMBLY32: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
   // WEBASSEMBLY64: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
 }
 
-void f7(void) {
+void rethrow(void) {
   return __builtin_wasm_rethrow();
   // WEBASSEMBLY32: call void @llvm.wasm.rethrow()
   // WEBASSEMBLY64: call void @llvm.wasm.rethrow()
 }
 
-int f8(int *addr, int expected, long long timeout) {
+int atomic_wait_i32(int *addr, int expected, long long timeout) {
   return __builtin_wasm_atomic_wait_i32(addr, expected, timeout);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.wait.i32(i32* %{{.*}}, i32 %{{.*}}, i64 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.wait.i32(i32* %{{.*}}, i32 %{{.*}}, i64 %{{.*}})
 }
 
-int f9(long long *addr, long long expected, long long timeout) {
+int atomic_wait_i64(long long *addr, long long expected, long long timeout) {
   return __builtin_wasm_atomic_wait_i64(addr, expected, timeout);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.wait.i64(i64* %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.wait.i64(i64* %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
 }
 
-unsigned int f10(int *addr, int count) {
+unsigned int atomic_notify(int *addr, int count) {
   return __builtin_wasm_atomic_notify(addr, count);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
 
-int f11(i8x16 v) {
+int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f12(i8x16 v) {
+int extract_lane_u_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_u_i8x16(v, 13);
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: zext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f13(i16x8 v) {
+int extract_lane_s_i16x8(i16x8 v) {
   return __builtin_wasm_extract_lane_s_i16x8(v, 7);
   // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f14(i16x8 v) {
+int extract_lane_u_i16x8(i16x8 v) {
   return __builtin_wasm_extract_lane_u_i16x8(v, 7);
   // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
   // WEBASSEMBLY-NEXT: zext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f15(i32x4 v) {
+int extract_lane_i32x4(i32x4 v) {
   return __builtin_wasm_extract_lane_i32x4(v, 3);
   // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
   // WEBASSEMBLY-NEXT: ret
 }
 
-long long f16(i64x2 v) {
+long long extract_lane_i64x2(i64x2 v) {
   return __builtin_wasm_extract_lane_i64x2(v, 1);
   // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
   //

[PATCH] D53009: [WebAssembly] Saturating float-to-int builtins

2018-10-08 Thread Thomas Lively via Phabricator via cfe-commits
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/D52959 and https://reviews.llvm.org/D53004.


Repository:
  rC Clang

https://reviews.llvm.org/D53009

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
@@ -83,6 +83,54 @@
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
 
+int trunc_saturate_s_i32_f32(float f) {
+  return __builtin_wasm_trunc_saturate_s_i32_f32(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f32(float f) {
+  return __builtin_wasm_trunc_saturate_u_i32_f32(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_s_i32_f64(double f) {
+  return __builtin_wasm_trunc_saturate_s_i32_f64(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f64(double f) {
+  return __builtin_wasm_trunc_saturate_u_i32_f64(f);
+  // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f32(float f) {
+  return __builtin_wasm_trunc_saturate_s_i64_f32(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f32(float f) {
+  return __builtin_wasm_trunc_saturate_u_i64_f32(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f64(double f) {
+  return __builtin_wasm_trunc_saturate_s_i64_f64(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f64(double f) {
+  return __builtin_wasm_trunc_saturate_u_i64_f64(f);
+  // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double %f)
+  // 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
@@ -300,3 +348,27 @@
   // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
   // WEBASSEMBLY: ret
 }
+
+i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
+  return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+  // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+  // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
+  return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+  // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12456,6 +12456,30 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+Value *Src = EmitScalarExpr(E->getArg(0));
+llvm::Type *ResT = ConvertType(E->getType());
+Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
+ {ResT, Src->getType()});
+return Builder.CreateCall(Callee, {Src});
+  }
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
+  case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+Value *Src = 

[PATCH] D53007: [WebAssembly][NFC] Rename test functions for builtins

2018-10-08 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344009: [WebAssembly][NFC] Rename test functions for 
builtins (authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53007

Files:
  cfe/trunk/test/CodeGen/builtins-wasm.c

Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -17,285 +17,285 @@
 typedef float f32x4 __attribute((vector_size(16)));
 typedef double f64x2 __attribute((vector_size(16)));
 
-__SIZE_TYPE__ f0(void) {
+__SIZE_TYPE__ memory_size(void) {
   return __builtin_wasm_memory_size(0);
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.memory.size.i32(i32 0)
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.memory.size.i64(i32 0)
 }
 
-__SIZE_TYPE__ f1(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ memory_grow(__SIZE_TYPE__ delta) {
   return __builtin_wasm_memory_grow(0, delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.memory.grow.i64(i32 0, i64 %{{.*}})
 }
 
-__SIZE_TYPE__ f2(void) {
+__SIZE_TYPE__ mem_size(void) {
   return __builtin_wasm_mem_size(0);
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.mem.size.i32(i32 0)
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.mem.size.i64(i32 0)
 }
 
-__SIZE_TYPE__ f3(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ mem_grow(__SIZE_TYPE__ delta) {
   return __builtin_wasm_mem_grow(0, delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.mem.grow.i32(i32 0, i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.mem.grow.i64(i32 0, i64 %{{.*}})
 }
 
-__SIZE_TYPE__ f4(void) {
+__SIZE_TYPE__ current_memory(void) {
   return __builtin_wasm_current_memory();
   // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.current.memory.i32()
   // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.current.memory.i64()
 }
 
-__SIZE_TYPE__ f5(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ grow_memory(__SIZE_TYPE__ delta) {
   return __builtin_wasm_grow_memory(delta);
   // WEBASSEMBLY32: call i32 @llvm.wasm.grow.memory.i32(i32 %{{.*}})
   // WEBASSEMBLY64: call i64 @llvm.wasm.grow.memory.i64(i64 %{{.*}})
 }
 
-void f6(unsigned int tag, void *obj) {
+void throw(unsigned int tag, void *obj) {
   return __builtin_wasm_throw(tag, obj);
   // WEBASSEMBLY32: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
   // WEBASSEMBLY64: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
 }
 
-void f7(void) {
+void rethrow(void) {
   return __builtin_wasm_rethrow();
   // WEBASSEMBLY32: call void @llvm.wasm.rethrow()
   // WEBASSEMBLY64: call void @llvm.wasm.rethrow()
 }
 
-int f8(int *addr, int expected, long long timeout) {
+int atomic_wait_i32(int *addr, int expected, long long timeout) {
   return __builtin_wasm_atomic_wait_i32(addr, expected, timeout);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.wait.i32(i32* %{{.*}}, i32 %{{.*}}, i64 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.wait.i32(i32* %{{.*}}, i32 %{{.*}}, i64 %{{.*}})
 }
 
-int f9(long long *addr, long long expected, long long timeout) {
+int atomic_wait_i64(long long *addr, long long expected, long long timeout) {
   return __builtin_wasm_atomic_wait_i64(addr, expected, timeout);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.wait.i64(i64* %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.wait.i64(i64* %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
 }
 
-unsigned int f10(int *addr, int count) {
+unsigned int atomic_notify(int *addr, int count) {
   return __builtin_wasm_atomic_notify(addr, count);
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
 
-int f11(i8x16 v) {
+int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f12(i8x16 v) {
+int extract_lane_u_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_u_i8x16(v, 13);
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: zext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f13(i16x8 v) {
+int extract_lane_s_i16x8(i16x8 v) {
   return __builtin_wasm_extract_lane_s_i16x8(v, 7);
   // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f14(i16x8 v) {
+int extract_lane_u_i16x8(i16x8 v) {
   return __builtin_wasm_extract_lane_u_i16x8(v, 7);
   // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
   // WEBASSEMBLY-NEXT: zext
   // WEBASSEMBLY-NEXT: ret
 }
 
-int f15(i32x4 v) {
+int extract_lane_i32x4(i32x4 v) {
   return __builtin_wasm_extract_lane_i32x4(v, 3);
   // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
   // WEBASSEMBLY-NEXT: ret
 }
 
-long long f16(i64x2 v) {
+long long extract_lane_i64x2(i64x2 v) {

[PATCH] D57736: [WebAssembly] Bulk memory intrinsics and builtins

2019-02-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: cfe-commits, sunfish, hiraditya, jgravelle-google, 
sbc100, dschuff.
Herald added a project: clang.

implements llvm intrinsics and clang intrinsics for
memory.init and data.drop.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D57736

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
  llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
@@ -0,0 +1,28 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+bulk-memory | FileCheck %s
+
+; Test that bulk memory intrinsics lower correctly
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: memory_init:
+; CHECK-NEXT: .functype  memory_init (i32, i32, i32) -> ()
+; CHECK-NEXT: memory.init 0, 3, $0, $1, $2
+; CHECK-NEXT: return
+declare void @llvm.wasm.memory.init.i32.i32.i8(i32, i32, i8*, i32, i32)
+define void @memory_init(i8* %dest, i32 %offset, i32 %size) {
+  call void @llvm.wasm.memory.init.i32.i32.i8(
+i32 0, i32 3, i8* %dest, i32 %offset, i32 %size
+  )
+  ret void
+}
+
+; CHECK-LABEL: data_drop:
+; CHECK-NEXT: .functype  data_drop () -> ()
+; CHECK-NEXT: data.drop 3
+; CHECK-NEXT: return
+declare void @llvm.wasm.data.drop.i32(i32)
+define void @data_drop() {
+  call void @llvm.wasm.data.drop.i32(i32 3)
+  ret void
+}
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
@@ -27,6 +27,31 @@
 def wasm_memcpy : SDNode<"WebAssemblyISD::MEMORY_COPY", wasm_memcpy_t,
  [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
 
+//===--===//
+// memory.init
+//===--===//
+
+let mayStore = 1 in
+defm MEMORY_INIT :
+  BULK_I<(outs),
+ (ins i32imm_op:$seg, i32imm_op:$idx, I32:$dest,
+  I32:$offset, I32:$size),
+ (outs), (ins i32imm_op:$seg, i32imm_op:$idx),
+ [(int_wasm_memory_init (i32 imm:$seg), (i32 imm:$idx), I32:$dest,
+I32:$offset, I32:$size
+  )],
+ "memory.init\t$seg, $idx, $dest, $offset, $size",
+ "memory.init\t$seg, $idx", 0x08>;
+
+//===--===//
+// data.drop
+//===--===//
+
+defm DATA_DROP :
+  BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg),
+ [(int_wasm_data_drop (i32 imm:$seg))],
+ "data.drop\t$seg", "data.drop\t$seg", 0x09>;
+
 //===--===//
 // memory.copy
 //===--===//
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -110,4 +110,20 @@
 [llvm_anyvector_ty],
 [IntrNoMem, IntrSpeculatable]>;
 
+//===--===//
+// Bulk memory intrinsics
+//===--===//
+
+def int_wasm_memory_init :
+  Intrinsic<[],
+[llvm_anyint_ty, llvm_anyint_ty, LLVMPointerType,
+ llvm_i32_ty, llvm_i32_ty],
+[IntrWriteMem, IntrArgMemOnly, WriteOnly<1>],
+"", [SDNPMemOperand]>;
+def int_wasm_data_drop :
+  Intrinsic<[],
+[llvm_anyint_ty],
+[IntrNoDuplicate, IntrHasSideEffects],
+"", [SDNPMemOperand]>;
+
 } // TargetPrefix = "wasm"
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +unimplemented-simd128 -target-fea

[PATCH] D57798: [WebAssembly] Add atomics target option

2019-02-05 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Basic/Targets/WebAssembly.cpp:172
+}
+if (Feature == "0atomics") {
+  HasAtomics = false;

-atomics


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57798/new/

https://reviews.llvm.org/D57798



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57798: [WebAssembly] Add atomics target option

2019-02-05 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/Basic/Targets/WebAssembly.cpp:172
+}
+if (Feature == "0atomics") {
+  HasAtomics = false;

tlively wrote:
> -atomics
You won the race!



Comment at: test/Preprocessor/wasm-target-features.c:89
+// BLEEDING-EDGE-DAG:#define __wasm_simd128__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}}

Nice.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57798/new/

https://reviews.llvm.org/D57798



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:66
+if (Args.hasFlag(clang::driver::options::OPT_pthread,
+ clang::driver::options::OPT_no_pthread),
+false)

sbc100 wrote:
> aheejin wrote:
> > This code is not strictly related, but `hasFlag` is better than `hasArg` 
> > when there are both positive and negative versions of an option exist.
> Hmm.. there are currently no other references to OPT_no_pthread in the whole 
> codebase.   Maybe better to simply remove the option?
> 
> I wouldn't want to commit this as that first use of the option as it might 
> make it hard to remove :)
I think commands generally come in pairs to make it possible to override 
previous settings by appending args to command lines. Counting uses of 
OPT_no_pthread without including uses of OP_pthread doesn't make much sense.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D57874#1391116 , @tlively wrote:

> In D57874#1389953 , @aheejin wrote:
>
> > - `-matomics` means `-mthread-model posix`
>
>
> Why should this be the case? Atomic instructions are necessary for 
> multithreading, but I wouldn't think multithreading would be necessary for 
> atomic instructions. Certainly atomics are not very useful in a single 
> threaded context, but that doesn't seem like a strong enough reason to 
> implicitly opt in to the rest of multithreading when -matomics is provided by 
> itself.


Sorry, missed previous discussion.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D57874#1389953 , @aheejin wrote:

> - `-matomics` means `-mthread-model posix`


Why should this be the case? Atomic instructions are necessary for 
multithreading, but I wouldn't think multithreading would be necessary for 
atomic instructions. Certainly atomics are not very useful in a single threaded 
context, but that doesn't seem like a strong enough reason to implicitly opt in 
to the rest of multithreading when -matomics is provided by itself.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D57874#1389953 , @aheejin wrote:

> Anyway, moved all logic to the driver layer and did this:
>
> - `-matomics` means `-mthread-model posix`
> - `-mthread-model posix` means `-matomics`
> - `-pthread` means both `-matomics` and `-mthread-model posix`


If you replace "-matomics" with "-mbulk-memory," I plan to duplicate the logic 
for items 2 and 3 above, but not 1. For bulk memory even more than atomics, 
there is a legitimate usecase for enabling it even in single threaded contexts 
(namely getting to use memory.copy and memory.fill). I wonder if consistency 
with how bulk memory works is a strong enough argument for dropping item 1 for 
atomics as well.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D57874#1390014 , @sbc100 wrote:

> In D57874#1389981 , @sunfish wrote:
>
> > > - `-matomics` means `-mthread-model posix`
> >
> > The others sound reasonable, though this one seems a little surprising -- a 
> > user might have -matomics enabled because they're targeting a VM that has 
> > atomics, but still not want to use -mthread-model posix because their code 
> > doesn't actually using threads.
>
>
> If you look at what "-mthread-model posix" actually means in the codebase it 
> basically means "don't lower away atomics ops".
>
> Its only used by WebAssembly and ARMTargetMachine to select the 
> `createLowerAtomicPass`.   Given that these are the only uses it seems like 
> it should be removed or renamed.


FWIW, I plan to use the thread-model argument to determine what kind of 
initialization flags data segments should use as well. Will share a short doc 
detailing this soon.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:50
+  bool HasNoPthread =
+  !Pthread && DriverArgs.hasArg(clang::driver::options::OPT_no_pthread);
+

Should this logic use `getLastArg` or perhaps `getLastArgNoClaim` to check only 
that the final requested configuration is consistent rather than checking all 
intermediate configurations?



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:62
+Driver.Diag(diag::err_drv_argument_not_allowed_with) << "-matomics"
+ << "-no-pthread";
+  // '-mno-atomics' cannot be used with '-mthread-model posix'

I'm not sure about this one, either. What if I want atomics for multithreading 
but I don't want to link with libpthread?



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:79
+Driver.Diag(diag::err_drv_argument_not_allowed_with)
+<< "-no-pthread" << ThreadModelOpt;
+}

Same question here.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D57874#1391384 , @aheejin wrote:

> In D57874#1391133 , @tlively wrote:
>
> > In D57874#1389953 , @aheejin wrote:
> >
> > > Anyway, moved all logic to the driver layer and did this:
> > >
> > > - `-matomics` means `-mthread-model posix`
> > > - `-mthread-model posix` means `-matomics`
> > > - `-pthread` means both `-matomics` and `-mthread-model posix`
> >
> >
> > If you replace "-matomics" with "-mbulk-memory," I plan to duplicate the 
> > logic for items 2 and 3 above, but not 1. For bulk memory even more than 
> > atomics, there is a legitimate usecase for enabling it even in single 
> > threaded contexts (namely getting to use memory.copy and memory.fill). I 
> > wonder if consistency with how bulk memory works is a strong enough 
> > argument for dropping item 1 for atomics as well.
>
>
> Then now `-mthread-model posix` means both `-matomics` and `-mbulk-memory`, 
> `-matomics` means `-mthread-model posix`, `-mbulk-memory` means 
> `-mthread-model posix` but NOT `-matomics` means `mbulk-memory` and vice 
> versa, right? Oh god it's complicated BTW if you are planning to use 
> `-mthread-model` for turning on and off bulk memory too, why not 1?


We talked about this offline, but recapping here. We can't have `-mbulk-memory` 
imply `-thread-model posix` because a user might want bulk memory for access to 
instructions like memory.copy and memory.set (which are just more efficient 
primitives for memcpy and memset), but NOT want multithreading.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:29
+  Pthread =
+  DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread, false);
+  ThreadModel =

Shouldn't every use of `hasFlag` be `getLastArgValue` instead?



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:36
+  // Did user explicitly specify -mthread-model / -pthread?
+  bool HasThreadModel = DriverArgs.hasArg(options::OPT_mthread_model);
+  bool HasPthread = Pthread && DriverArgs.hasArg(options::OPT_pthread);

It doesn't matter whether the user included the -pthread flag if they later 
included the -no-pthread flag.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:42
+  // "posix")
+  if (HasPthread && HasThreadModel && ThreadModel != "posix")
+Driver.Diag(diag::err_drv_argument_not_allowed_with)

This should be `ThreadModel == "single"`, since the distinction we care about 
is single-threaded vs no single-threaded. If in the future there are dozens of 
thread models besides "posix" this logic should still work.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:157
+  parseThreadArgs(getDriver(), DriverArgs, Pthread, ThreadModel);
+  if (Pthread || ThreadModel == "posix") {
+CC1Args.push_back("-target-feature");

Same here. Should compare ThreadModel with "single".


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57874: [WebAssembly] Make thread-related options consistent

2019-02-08 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Driver/ToolChains/WebAssembly.cpp:29
+  Pthread =
+  DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread, false);
+  ThreadModel =

aheejin wrote:
> tlively wrote:
> > Shouldn't every use of `hasFlag` be `getLastArgValue` instead?
> `hasFlag` is a convenient way to check everything with one function call. 
> with `getLastArgValue` we have to call it twice (for example, for `-pthread` 
> and for `-no-pthread`), and most importantly when both of them are given, 
> calling `getLastArgValue` doesn't give you information on which one is the 
> last. `hasFlag` takes care of that by taking the last one when both of them 
> are given. So `-pthread -no-pthread` will return false, and `-no-pthread 
> -pthread` will return true.
> 
> The reason I used `hasArg` below is just to check if the user gave it 
> explicitly or not. And that's the reason I named variables `Pthread` and 
> `HasPthread`.
I see! I had misunderstood hasFlag. Thanks for explaining it.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57874/new/

https://reviews.llvm.org/D57874



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57736: [WebAssembly] Bulk memory intrinsics and builtins

2019-02-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:29
+// Bulk memory builtins
+TARGET_BUILTIN(__builtin_wasm_memory_init, "vIiv*ii", "", "bulk-memory")
+TARGET_BUILTIN(__builtin_wasm_data_drop, "vIi", "", "bulk-memory")

aheejin wrote:
> - When do we use `Ii` instead of `i`?
> - Shouldn't we add the memory index field as well, even if that means a user 
> always has to set it to 0? Are we gonna add a new builtin once multiple 
> memories are available?
> - Shouldn't the segment index, segment offset, and the size operands be `Ui` 
> because they cannot be negative?
We use `Ii` instead of `i` when the argument needs to be a compile time 
constant because it is encoded as a literal in the corresponding instruction.

I was imagining that we could add a new builtin once multiple memories are 
available, but perhaps it would be better to add an argument to the builtin now 
and error out if it is not zero. I will do that.

Yes, `Ui` seems reasonable.





Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:30
+TARGET_BUILTIN(__builtin_wasm_memory_init, "vIiv*ii", "", "bulk-memory")
+TARGET_BUILTIN(__builtin_wasm_data_drop, "vIi", "", "bulk-memory")
+

aheejin wrote:
> The same thing..
> - Shouldn't the segment index be `Ui`?
> - Shouldn't we add the memory index field as well?
> 
 - Done

 - This intrinsic doesn't have a memory index, since it doesn't write anything 
into memory.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13477
+if (!SegArg->isIntegerConstantExpr(SegConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+llvm::Type *SegType = ConvertType(SegArg->getType());

aheejin wrote:
> Not sure if we can use `llvm_unreachable` here, because we can certainly 
> reach here if a user uses this builtin with a non-const variable. In this 
> file people often just used `assert` for user errors, which is not ideal 
> either.
> 
> I haven't used it myself, but looking at the code, the recommended way to 
> signal an error looks like to use [[ 
> https://github.com/llvm/llvm-project/blob/db7fbcb038f095622a3e6847ecd6ff80bdc2483a/clang/lib/CodeGen/CodeGenFunction.h#L2092-L2094
>  | `CodeGenFunction::ErrorUnsupported` ]] function, as in [[ 
> https://github.com/llvm/llvm-project/blob/0e04ebdcda44ef90e25abd0a2e65cc755ae8bc37/clang/lib/CodeGen/CGBuiltin.cpp#L2458-L2460
>  | here ]]. We used `llvm_unreachable` for SIMD builtins too, but maybe we 
> can fix it later.
`llvm_unreachable` is appropriate here because non-constant expressions will 
have been caught earlier by the type checking.

A follow-up PR updating SIMD intrinsics to use `Ui` and appropriate error 
handling sounds good.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13488
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_memory_init,
+{SegType, IdxType, DstType});
+return Builder.CreateCall(Callee, Args);

aheejin wrote:
> Do we need to pass types here to make intrinsic names overloaded like 
> `llvm.wasm.memory.init.i32.i32.i8`, unless this intrinsic also support 
> operands of other types, which it doesn't? The same for `data.drop` builtin.
Fixed. I had been copying `llvm.memcpy`, but I agree it is better to not be 
polymorphic.



Comment at: llvm/include/llvm/IR/IntrinsicsWebAssembly.td:121
+ llvm_i32_ty, llvm_i32_ty],
+[IntrWriteMem, IntrArgMemOnly, WriteOnly<1>],
+"", [SDNPMemOperand]>;

aheejin wrote:
> - Isn't the pointer argument number not 1 but 2?
> - I guess this should have `IntrHasSideEffects` as well, as in `data.drop`?
> - I don't know much how they are handled differently in compilation, but 
> because we can access some other memory, which holds the segment part, during 
> execution, how about `IntrInaccessibleMemOrArgMemOnly` instead of 
> `IntrArgMemOnly`?
- Yes, good catch.

- Ok, I'm not sure it's necessary but it can't hurt.

- I'm not sure this is necessary either, but again it can't hurt. Better safe 
than sorry.



Comment at: llvm/include/llvm/IR/IntrinsicsWebAssembly.td:122
+[IntrWriteMem, IntrArgMemOnly, WriteOnly<1>],
+"", [SDNPMemOperand]>;
+def int_wasm_data_drop :

aheejin wrote:
> I told you we needed this, but on second thought, because we don't really use 
> `MachineMemOperand`, maybe we don't need it..? :$ The [[ 
> https://github.com/llvm/llvm-project/blob/dc2c93017f8bf2a2c10b8e024f8f4a6409db/llvm/include/llvm/IR/Intrinsics.td#L483-L496
>  | standard memcpy/memmove/memset intrinsics ]] don't have it either. So if 
> the code runs ok without these I think we can delete it. The same for 
> `data.drop` intrinsic. Sorry for the incorrect info and confusion.
No problem!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE

[PATCH] D57736: [WebAssembly] Bulk memory intrinsics and builtins

2019-02-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 186393.
tlively marked 12 inline comments as done.
tlively added a comment.

- Address comments
  - Use `Ui` in builtin signatures
  - Remove unnecessary intrinsic polymorphism
  - Tweak intrinsic properties


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57736/new/

https://reviews.llvm.org/D57736

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
  llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
  llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
  llvm/test/CodeGen/WebAssembly/bulk-memory.ll

Index: llvm/test/CodeGen/WebAssembly/bulk-memory.ll
===
--- llvm/test/CodeGen/WebAssembly/bulk-memory.ll
+++ llvm/test/CodeGen/WebAssembly/bulk-memory.ll
@@ -6,14 +6,17 @@
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i1)
+declare void @llvm.memcpy.p0i32.p0i32.i32(i32*, i32*, i32, i1)
+
+declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1)
+declare void @llvm.memmove.p0i32.p0i32.i32(i32*, i32*, i32, i1)
+
 ; CHECK-LABEL: memcpy_i8:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_i8 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memcpy.p0i8.p0i8.i32(
-  i8* %dest, i8* %src, i32 %len, i1 %volatile
-)
 define void @memcpy_i8(i8* %dest, i8* %src, i32 %len) {
   call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 0)
   ret void
@@ -22,11 +25,8 @@
 ; CHECK-LABEL: memmove_i8:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_i8 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memmove.p0i8.p0i8.i32(
-  i8* %dest, i8* %src, i32 %len, i1 %volatile
-)
 define void @memmove_i8(i8* %dest, i8* %src, i32 %len) {
   call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 0)
   ret void
@@ -35,11 +35,8 @@
 ; CHECK-LABEL: memcpy_i32:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_i32 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memcpy.p0i32.p0i32.i32(
-  i32* %dest, i32* %src, i32 %len, i1 %volatile
-)
 define void @memcpy_i32(i32* %dest, i32* %src, i32 %len) {
   call void @llvm.memcpy.p0i32.p0i32.i32(i32* %dest, i32* %src, i32 %len, i1 0)
   ret void
@@ -48,11 +45,8 @@
 ; CHECK-LABEL: memmove_i32:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_i32 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memmove.p0i32.p0i32.i32(
-  i32* %dest, i32* %src, i32 %len, i1 %volatile
-)
 define void @memmove_i32(i32* %dest, i32* %src, i32 %len) {
   call void @llvm.memmove.p0i32.p0i32.i32(i32* %dest, i32* %src, i32 %len, i1 0)
   ret void
@@ -82,7 +76,7 @@
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_1024 (i32, i32) -> ()
 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
-; BULK-MEM-NEXT: memory.copy $0, $1, $pop[[L0]]
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
 ; BULK-MEM-NEXT: return
 define void @memcpy_1024(i8* %dest, i8* %src) {
   call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0)
@@ -93,7 +87,7 @@
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_1024 (i32, i32) -> ()
 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
-; BULK-MEM-NEXT: memory.copy $0, $1, $pop[[L0]]
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
 ; BULK-MEM-NEXT: return
 define void @memmove_1024(i8* %dest, i8* %src) {
   call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0)
Index: llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
@@ -0,0 +1,28 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+bulk-memory | FileCheck %s
+
+; Test that bulk memory intrinsics lower correctly
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: memory_init:
+; CHECK-NEXT: .functype  memory_init (i32, i32, i32) -> ()
+; CHECK-NEXT: memory.init 3, 0, $0, $1, $2
+; CHECK-NEXT: return
+declare void @llvm.wasm.memory.init(i32, i32, i8*, i32, i32)
+define void @memory_init(i8* %de

[PATCH] D57736: [WebAssembly] Bulk memory intrinsics and builtins

2019-02-12 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 186504.
tlively added a comment.

- Update tests to check full polymorphism of llvm.memcpy and llvm.memmove


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57736/new/

https://reviews.llvm.org/D57736

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
  llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
  llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
  llvm/test/CodeGen/WebAssembly/bulk-memory.ll

Index: llvm/test/CodeGen/WebAssembly/bulk-memory.ll
===
--- llvm/test/CodeGen/WebAssembly/bulk-memory.ll
+++ llvm/test/CodeGen/WebAssembly/bulk-memory.ll
@@ -6,40 +6,39 @@
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
+declare void @llvm.memcpy.p0i8.p0i8.i8(i8*, i8*, i8, i1)
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i1)
+declare void @llvm.memcpy.p0i32.p0i32.i32(i32*, i32*, i32, i1)
+
+declare void @llvm.memmove.p0i8.p0i8.i8(i8*, i8*, i8, i1)
+declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1)
+declare void @llvm.memmove.p0i32.p0i32.i32(i32*, i32*, i32, i1)
+
 ; CHECK-LABEL: memcpy_i8:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_i8 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memcpy.p0i8.p0i8.i32(
-  i8* %dest, i8* %src, i32 %len, i1 %volatile
-)
-define void @memcpy_i8(i8* %dest, i8* %src, i32 %len) {
-  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 0)
+define void @memcpy_i8(i8* %dest, i8* %src, i8 zeroext %len) {
+  call void @llvm.memcpy.p0i8.p0i8.i8(i8* %dest, i8* %src, i8 %len, i1 0)
   ret void
 }
 
 ; CHECK-LABEL: memmove_i8:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_i8 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memmove.p0i8.p0i8.i32(
-  i8* %dest, i8* %src, i32 %len, i1 %volatile
-)
-define void @memmove_i8(i8* %dest, i8* %src, i32 %len) {
-  call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 0)
+define void @memmove_i8(i8* %dest, i8* %src, i8 zeroext %len) {
+  call void @llvm.memmove.p0i8.p0i8.i8(i8* %dest, i8* %src, i8 %len, i1 0)
   ret void
 }
 
 ; CHECK-LABEL: memcpy_i32:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_i32 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memcpy.p0i32.p0i32.i32(
-  i32* %dest, i32* %src, i32 %len, i1 %volatile
-)
 define void @memcpy_i32(i32* %dest, i32* %src, i32 %len) {
   call void @llvm.memcpy.p0i32.p0i32.i32(i32* %dest, i32* %src, i32 %len, i1 0)
   ret void
@@ -48,11 +47,8 @@
 ; CHECK-LABEL: memmove_i32:
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_i32 (i32, i32, i32) -> ()
-; BULK-MEM-NEXT: memory.copy $0, $1, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
 ; BULK-MEM-NEXT: return
-declare void @llvm.memmove.p0i32.p0i32.i32(
-  i32* %dest, i32* %src, i32 %len, i1 %volatile
-)
 define void @memmove_i32(i32* %dest, i32* %src, i32 %len) {
   call void @llvm.memmove.p0i32.p0i32.i32(i32* %dest, i32* %src, i32 %len, i1 0)
   ret void
@@ -82,7 +78,7 @@
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memcpy_1024 (i32, i32) -> ()
 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
-; BULK-MEM-NEXT: memory.copy $0, $1, $pop[[L0]]
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
 ; BULK-MEM-NEXT: return
 define void @memcpy_1024(i8* %dest, i8* %src) {
   call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0)
@@ -93,7 +89,7 @@
 ; NO-BULK-MEM-NOT: memory.copy
 ; BULK-MEM-NEXT: .functype memmove_1024 (i32, i32) -> ()
 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
-; BULK-MEM-NEXT: memory.copy $0, $1, $pop[[L0]]
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
 ; BULK-MEM-NEXT: return
 define void @memmove_1024(i8* %dest, i8* %src) {
   call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0)
Index: llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
@@ -0,0 +1,28 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+bulk-memory | FileCheck %s
+
+; Test that bulk memory intrinsics lower correctly
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-

[PATCH] D57736: [WebAssembly] Bulk memory intrinsics and builtins

2019-02-13 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL353983: [WebAssembly] Bulk memory intrinsics and builtins 
(authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57736?vs=186504&id=186740#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57736/new/

https://reviews.llvm.org/D57736

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c
  llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
  llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
  llvm/trunk/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
  llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll

Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
@@ -21,19 +21,48 @@
 }
 
 // Bespoke types and nodes for bulk memory ops
-def wasm_memcpy_t : SDTypeProfile<0, 3,
-  [SDTCisPtrTy<0>, SDTCisPtrTy<1>, SDTCisInt<2>]
+def wasm_memcpy_t : SDTypeProfile<0, 5,
+  [SDTCisInt<0>, SDTCisInt<1>, SDTCisPtrTy<2>, SDTCisPtrTy<3>, SDTCisInt<4>]
 >;
 def wasm_memcpy : SDNode<"WebAssemblyISD::MEMORY_COPY", wasm_memcpy_t,
  [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
 
 //===--===//
+// memory.init
+//===--===//
+
+let mayStore = 1 in
+defm MEMORY_INIT :
+  BULK_I<(outs),
+ (ins i32imm_op:$seg, i32imm_op:$idx, I32:$dest,
+  I32:$offset, I32:$size),
+ (outs), (ins i32imm_op:$seg, i32imm_op:$idx),
+ [(int_wasm_memory_init (i32 imm:$seg), (i32 imm:$idx), I32:$dest,
+I32:$offset, I32:$size
+  )],
+ "memory.init\t$seg, $idx, $dest, $offset, $size",
+ "memory.init\t$seg, $idx", 0x08>;
+
+//===--===//
+// data.drop
+//===--===//
+
+defm DATA_DROP :
+  BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg),
+ [(int_wasm_data_drop (i32 imm:$seg))],
+ "data.drop\t$seg", "data.drop\t$seg", 0x09>;
+
+//===--===//
 // memory.copy
 //===--===//
 
 let mayLoad = 1, mayStore = 1 in
-defm MEMORY_COPY : BULK_I<(outs), (ins I32:$dst, I32:$src, I32:$len),
-  (outs), (ins),
-  [(wasm_memcpy I32:$dst, I32:$src, I32:$len)],
-  "memory.copy\t$dst, $src, $len",
-  "memory.copy", 0x0a>;
+defm MEMORY_COPY :
+  BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx,
+  I32:$dst, I32:$src, I32:$len),
+ (outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx),
+ [(wasm_memcpy (i32 imm:$src_idx), (i32 imm:$dst_idx),
+   I32:$dst, I32:$src, I32:$len
+ )],
+ "memory.copy\t$src_idx, $dst_idx, $dst, $src, $len",
+ "memory.copy\t$src_idx, $dst_idx", 0x0a>;
Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
@@ -19,16 +19,18 @@
 WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor
 
 SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy(
-SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,
-SDValue Op3, unsigned Align, bool IsVolatile, bool AlwaysInline,
+SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,
+SDValue Size, unsigned Align, bool IsVolatile, bool AlwaysInline,
 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
   if (!DAG.getMachineFunction()
.getSubtarget()
.hasBulkMemory())
 return SDValue();
 
-  return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other, Chain, Op1,
- Op2, Op3);
+  SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);
+  return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other,
+ {Chain, MemIdx, MemIdx, Dst, Src,
+  DAG.getZExtOrTrunc(Size, DL, MVT::i32)});
 }
 
 SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove(
Index: llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- ll

[PATCH] D62830: [WebAssembly] Support Leak Sanitizer on Emscripten

2019-06-05 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362667: [WebAssembly] Support Leak Sanitizer on Emscripten 
(authored by tlively, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62830?vs=202817&id=203273#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62830/new/

https://reviews.llvm.org/D62830

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -211,7 +211,7 @@
 SanitizerMask WebAssembly::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   if (getTriple().isOSEmscripten()) {
-Res |= SanitizerKind::Vptr;
+Res |= SanitizerKind::Vptr | SanitizerKind::Leak;
   }
   return Res;
 }


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -211,7 +211,7 @@
 SanitizerMask WebAssembly::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   if (getTriple().isOSEmscripten()) {
-Res |= SanitizerKind::Vptr;
+Res |= SanitizerKind::Vptr | SanitizerKind::Leak;
   }
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63575: [WebAssembly] Add builtin functions for creating vector constants

2019-06-19 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: dschuff, aheejin.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.

These builtins do not offer any functionality over the normal
aggregate initialization for vector types, except that they enforce
that their arguments constant fold to integer expressions so they
always generate a vector constant. They are meant for use in the new
WebAssembly SIMD intrinsic header.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63575

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


Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -140,10 +140,29 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 const_i8x16() {
+  // MISSING-SIMD: error: '__builtin_wasm_const_i8x16' needs target feature 
simd128
+  // WEBASSEMBLY: ret <16 x i8> 
+  return __builtin_wasm_const_i8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15);
+}
+
+i16x8 const_i16x8() {
+  // WEBASSEMBLY: ret <8 x i16> 
+  return __builtin_wasm_const_i16x8(0, 1, 2, 3, 4, 5, 6, 7);
+}
+
+i32x4 const_i32x4() {
+  // WEBASSEMBLY: ret <4 x i32> 
+  return __builtin_wasm_const_i32x4(0, 1, 2, 3);
+}
+
+i64x2 const_i64x2() {
+  // WEBASSEMBLY: ret <2 x i64> 
+  return __builtin_wasm_const_i64x2(0, 1);
+}
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
-  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target 
feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13971,6 +13971,19 @@
  ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_const_i8x16:
+  case WebAssembly::BI__builtin_wasm_const_i16x8:
+  case WebAssembly::BI__builtin_wasm_const_i32x4:
+  case WebAssembly::BI__builtin_wasm_const_i64x2: {
+SmallVector Args;
+for (size_t i = 0; i < E->getNumArgs(); ++i) {
+  llvm::APSInt Const;
+  if (!E->getArg(i)->isIntegerConstantExpr(Const, getContext()))
+llvm_unreachable("Constant arg isn't actually constant?");
+  Args.push_back(llvm::ConstantInt::get(getLLVMContext(), Const));
+}
+return Builder.Insert(llvm::ConstantVector::get(Args));
+  }
   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:
Index: clang/include/clang/Basic/BuiltinsWebAssembly.def
===
--- clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -55,6 +55,11 @@
 TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", 
"nontrapping-fptoint")
 
 // SIMD builtins
+TARGET_BUILTIN(__builtin_wasm_const_i8x16, 
"V16cIcIcIcIcIcIcIcIcIcIcIcIcIcIcIcIc", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i16x8, "V8sIsIsIsIsIsIsIsIs", "nc", 
"simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i32x4, "V4iIiIiIiIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i64x2, "V2LLiILLiILLi", "nc", 
"unimplemented-simd128")
+
 TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc", 
"unimplemented-simd128")
 TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc", "simd128")


Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -140,10 +140,29 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 const_i8x16() {
+  // MISSING-SIMD: error: '__builtin_wasm_const_i8x16' needs target feature simd128
+  // WEBASSEMBLY: ret <16 x i8> 
+  return __builtin_wasm_const_i8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+}
+
+i16x8 const_i16x8() {
+  // WEBASSEMBLY: ret <8 x i16> 
+  return __builtin_wasm_const_i16x8(0, 1, 2, 3, 4, 5, 6, 7);
+}
+
+i32x4 const_i32x4() {
+  // WEBASSEMBLY: ret <4 x i32> 
+  return __builtin_wasm_const_i32x4(0, 1, 2, 3);
+}
+
+i64x2 const_i64x2() {
+  // WEBASSEMBLY: ret <2 x i64> 
+  return __builtin_wasm_const_i64x2(0, 1);
+}
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
-  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEM

[PATCH] D63575: [WebAssembly] Add builtin functions for creating vector constants

2019-06-19 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

This CL does not provide a mechanism for enforcing that the lanes of a floating 
point vector are constant, and it doesn't look like clang supports that kind of 
check. That makes this CL a half-baked solution, so I'm not sure we should 
actually go in this direction.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63575/new/

https://reviews.llvm.org/D63575



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64586: [WebAssembly] Make -pthread imply -bulk-memory

2019-07-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, jfb, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.

This paves the way for using passive segments in pthread builds, which
will make separate memory files unnecessary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64586

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,12 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=BULK_MEM_NO_ATOMICS %s
+// BULK_MEM_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 
2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies target features atomics and bulk-memory
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,15 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
+   options::OPT_mbulk_memory, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+bulk-memory");
   }
 }
 


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,12 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=BULK_MEM_NO_ATOMICS %s
+// BULK_MEM_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-bulk-memory'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:33
+// Thread-local storage
+TARGET_BUILTIN(__builtin_wasm_tls_size, "z", "nc", "bulk-memory")
+

quantum wrote:
> quantum wrote:
> > aheejin wrote:
> > > Why is it `c`(const)? According to [[ 
> > > https://github.com/llvm/llvm-project/blob/e6695821e592f95bffe1340b28be7bcfcce04284/clang/include/clang/Basic/Builtins.h#L104-L108
> > >  | this comment ]], this is true if this function has no side effects and 
> > > doesn't read memory, i.e., the result should be only dependent on its 
> > > arguments. Can't wasm globals be memory locations in machines?
> > I was thinking that since the global is immutable, so the value is always a 
> > constant.
> According to @tlively, there is no solid definition on whether a global 
> (especially a constant one), counts as memory access. For now, I am going to 
> change this to not constant. We can always change it back later.
I think this requires more conversation.



Comment at: lld/test/wasm/data-layout.ll:43
+; CHECK-NEXT:   - Index:   3
+; CHECK-NEXT: Type:I32
 ; CHECK-NEXT: Mutable: false

These globals don't have enough information to tell the reader what they even 
are, and they don't have anything to do with the data layout, so how about 
skipping these in the test with a comment saying what is being skipped?



Comment at: lld/test/wasm/tls.ll:57
+;   memory.init 0, 0
+;   end
+

quantum wrote:
> aheejin wrote:
> > Hmm, I think there might be a way to actually print disassembly results. 
> > There are '*.test' files in test directory, in which we have some examples. 
> > For example, [[ 
> > https://github.com/llvm/llvm-project/blob/master/lld/test/wasm/export-table.test
> >  | this test ]] has a sequence of commands you want to run, and you can put 
> > input files in a separate directory. That test uses `obj2yaml`, but can we 
> > possibly use `llvm-objdump` or something to disassemble?
> We already know that we can do something like
> 
> Run: obj2yaml %t.wasm | sed -n '/Body:/{s/^\s*Body:\s*//;s/../0x& /gp}'  
> | llvm-mc -disassemble -triple=wasm32
> 
> to compare the actual assembly. As for `llvm-objdump`, it seems to be unable 
> to disassemble the WASM properly:
> 
> 
> ```
> .../tools/lld/test/wasm/Output/tls.ll.tmp.wasm:   file format WASM
> 
> 
> Disassembly of section CODE:
> 
>  CODE:
> # 4 functions in section.
>1: 02 00   block   invalid_type
>3: 0b  end
>4: 10 00   call0
>6: 20 00   local.get   0
>8: 24 01   global.set  1
>a: 20 00   local.get   0
>c: 41 00   i32.const   0
>e: 41 08   i32.const   8
>   10: fc 08 00 00 memory.init 0, 0
>   14: 0b  end
>   15: 0f  return
>   16: 00  llvm-objdump: 
> lib/Target/WebAssembly/WebAssemblyGenAsmWriter.inc:2032: void 
> llvm::WebAssemblyInstPrinter::printInstruction(const llvm::MCInst *, 
> llvm::raw_ostream &): Assertion `Bits != 0 && "Cannot print this 
> instruction."' failed.
> 
> ```
It might be worth filing an LLVM bug for this (or possibly fixing in a separate 
CL).



Comment at: lld/wasm/Symbols.cpp:208
+if (Segment->OutputSeg->Name == ".tdata")
+  return Segment->OutputSegmentOffset + Offset;
 return Segment->OutputSeg->StartVA + Segment->OutputSegmentOffset + Offset;

It would be great to have an explanatory comment here.



Comment at: lld/wasm/Writer.cpp:777
+  break;
+}
+

quantum wrote:
> aheejin wrote:
> > Is it guaranteed that there's only one TLS segment?
> Yes, all the TLS input segments will be merged into `.tdata`.
--no-merge-data-segments!



Comment at: lld/wasm/Writer.cpp:250
+  TLSSize->Global->Global.InitExpr.Value.Int32 = Seg->Size;
+}
   }

What happens when there are multiple TLS sections and 
`--no-merge-data-segments` is used? I assume their sizes should be added 
together?



Comment at: lld/wasm/Writer.cpp:638
+  if (Name.startswith(".tbss."))
+return ".tdata";
   return Name;

Does this mean we can't control whether .tdata or .tbss comes first? Is that 
important for anything?



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp:1095
+WebAssemblyTargetLowering::LowerGlobalTLSAddress(SDValue Op,
+ SelectionDAG &DAG) const

[PATCH] D64586: [WebAssembly] Make pthread imply bulk-memory, mutable-globals

2019-07-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 209367.
tlively added a comment.

- Update comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64586/new/

https://reviews.llvm.org/D64586

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_BULK_MEM %s
+// PTHREAD_NO_BULK_MEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
+
+// '-pthread' not allowed with '-mno-mutable-globals'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-mutable-globals 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_MUT_GLOBALS %s
+// PTHREAD_NO_MUT_GLOBALS: invalid argument '-pthread' not allowed with 
'-mno-mutable-globals'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 
2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies atomics, bulk-memory, and mutable-globals
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,22 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
+   options::OPT_mbulk_memory, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-bulk-memory";
+if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
+   options::OPT_mmutable_globals, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-mutable-globals";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+bulk-memory");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+mutable-globals");
   }
 }
 


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %

[PATCH] D64586: [WebAssembly] Make pthread imply bulk-memory, mutable-globals

2019-07-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 209365.
tlively added a comment.

- Add mutable-globals


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64586/new/

https://reviews.llvm.org/D64586

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_BULK_MEM %s
+// PTHREAD_NO_BULK_MEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
+
+// '-pthread' not allowed with '-mno-mutable-globals'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-mutable-globals 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_MUT_GLOBALS %s
+// PTHREAD_NO_MUT_GLOBALS: invalid argument '-pthread' not allowed with 
'-mno-mutable-globals'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 
2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies target features atomics and bulk-memory
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,22 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
+   options::OPT_mbulk_memory, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-bulk-memory";
+if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
+   options::OPT_mmutable_globals, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-mutable-globals";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+bulk-memory");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+mutable-globals");
   }
 }
 


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN

[PATCH] D64586: [WebAssembly] Make pthread imply bulk-memory, mutable-globals

2019-07-11 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 209369.
tlively added a comment.

- and other comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64586/new/

https://reviews.llvm.org/D64586

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, +mutable-globals, and 
--shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_BULK_MEM %s
+// PTHREAD_NO_BULK_MEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
+
+// '-pthread' not allowed with '-mno-mutable-globals'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-mutable-globals 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_MUT_GLOBALS %s
+// PTHREAD_NO_MUT_GLOBALS: invalid argument '-pthread' not allowed with 
'-mno-mutable-globals'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 
2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies atomics, bulk-memory, and mutable-globals
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,22 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
+   options::OPT_mbulk_memory, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-bulk-memory";
+if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
+   options::OPT_mmutable_globals, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-mutable-globals";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+bulk-memory");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+mutable-globals");
   }
 }
 


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, +mutable-globals, and --shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-atomics'
 
+// '-pthread' not al

[PATCH] D64586: [WebAssembly] Make pthread imply bulk-memory, mutable-globals

2019-07-12 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365935: [WebAssembly] Make pthread imply bulk-memory, 
mutable-globals (authored by tlively, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64586?vs=209369&id=209544#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64586/new/

https://reviews.llvm.org/D64586

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/test/Driver/wasm-toolchain.c


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies atomics, bulk-memory, and mutable-globals
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,22 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
+   options::OPT_mbulk_memory, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-bulk-memory";
+if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
+   options::OPT_mmutable_globals, false))
+  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
+  << "-pthread"
+  << "-mno-mutable-globals";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+bulk-memory");
+CC1Args.push_back("-target-feature");
+CC1Args.push_back("+mutable-globals");
   }
 }
 
Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -48,11 +48,11 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '--shared-memory'
+// '-pthread' sets +atomics, +bulk-memory, +mutable-globals, and 
--shared-memory
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
 
 // '-pthread' not allowed with '-mno-atomics'
@@ -61,6 +61,18 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
 
+// '-pthread' not allowed with '-mno-bulk-memory'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_BULK_MEM %s
+// PTHREAD_NO_BULK_MEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
+
+// '-pthread' not allowed with '-mno-mutable-globals'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -pthread -mno-mutable-globals 2>&1 \
+// RUN:   | FileCheck -check-prefix=PTHREAD_NO_MUT_GLOBALS %s
+// PTHREAD_NO_MUT_GLOBALS: invalid argument '-pthread' not allowed with 
'-mno-mutable-globals'
+
 // RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 
2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
 // CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -141,7 +141,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics'
+  // '-pthread' implies atomics, bulk-memory, and mutable-globals
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -149,8 +149,22 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
+   

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-12 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lld/wasm/Driver.cpp:543
+  "__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
+  make(I32ArgSignature, "__wasm_init_tls"));
+

quantum wrote:
> aheejin wrote:
> > Does this TLS thing work when `Config->Shared == true`, i.e., do we create 
> > TLS globals even when this is a library?
> Since TLS is module specific (we can't allocate memory for other modules), we 
> must in fact generate this symbol for every module. Shared library support 
> will not be implemented in this diff, however.
Until we do implement TLS for shared modules, would it make sense to omit these 
globals and function from shared modules, since we can't use them in that 
context anyway?



Comment at: lld/wasm/Writer.cpp:638
+  if (Name.startswith(".tbss."))
+return ".tdata";
   return Name;

quantum wrote:
> tlively wrote:
> > Does this mean we can't control whether .tdata or .tbss comes first? Is 
> > that important for anything?
> Yes, it does mean that. The only reason why .tbss is supposed to be separate 
> is so that its memory can just be zeroed whereas .tdata has to have the bytes 
> stored in the program image. Currently, we just explicitly store the zero 
> bytes, so this won't be a problem.
It would be really great if we could find a way to elide the .bss 0 bytes as a 
code size optimization. Since we can't assume that the memory is already zeroed 
the way we can with passive segments, perhaps we can use a memory.fill 
instruction to zero the memory? Pursuing this in a follow-on CL should be fine.



Comment at: lld/wasm/Writer.cpp:805
+  writeUleb128(os, 0, "num locals");
+  writeU8(os, WASM_OPCODE_END, "end function");
+}

You could avoid duplicating these lines by making them unconditional.



Comment at: lld/wasm/Writer.cpp:905
+  if (config->sharedMemory)
+createInitTLSFunction();
+

Can you remind me how the InitTLSFunction interacts with relocatable code? I'm 
wondering if this should be called up in the condition with the other synthetic 
functions.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:193
+
+if (!Features[WebAssembly::FeatureBulkMemory])
   Stripped |= stripThreadLocals(M);

I just realized that if we have atomics but not bulk memory and TLS is 
stripped, then we will be in the awkward situation of both using atomics and 
disallowing atomics because the module is not thread safe. I think the best 
solution would be to go back and forcibly strip both atomics and TLS if either 
of them would be stripped.



Comment at: llvm/test/CodeGen/WebAssembly/tls.ll:2
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt 
-wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt 
-wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"

It would be good to check the negative case, too, i.e with bulk-memory disabled.



Comment at: llvm/test/CodeGen/WebAssembly/tls.ll:6
 
-; SINGLE-LABEL: address_of_tls:
+; CHECK-LABEL: address_of_tls:
 define i32 @address_of_tls() {

Is `CHECK` still used as a prefix if it not listed in the invocation of 
FileCheck?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

LGTM apart from one last comment




Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:193
+
+if (!Features[WebAssembly::FeatureBulkMemory])
   Stripped |= stripThreadLocals(M);

quantum wrote:
> tlively wrote:
> > I just realized that if we have atomics but not bulk memory and TLS is 
> > stripped, then we will be in the awkward situation of both using atomics 
> > and disallowing atomics because the module is not thread safe. I think the 
> > best solution would be to go back and forcibly strip both atomics and TLS 
> > if either of them would be stripped.
> Done.
We can be more fine grained than this. We should strip atomics or TLS only if 
the relevant feature is missing or the other one is stripped. It is possible to 
have thread-locals and bulk memory but not have any atomics to strip.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.

Nice work!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64949: [WebAssembly] Fix __builtin_wasm_tls_base intrinsic

2019-07-18 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.
This revision is now accepted and ready to land.

LGTM modulo a test!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64949/new/

https://reviews.llvm.org/D64949



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65028: [WebAssembly] Compute and export TLS block alignment

2019-07-19 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.
This revision is now accepted and ready to land.

Nice


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65028/new/

https://reviews.llvm.org/D65028



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.

These features will both be implemented soon, so I thought I would
save time by adding the boilerplate for both of them at the same time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62047

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/Preprocessor/wasm-target-features.c
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/test/CodeGen/WebAssembly/multivalue.ll
  llvm/test/CodeGen/WebAssembly/tailcall.ll

Index: llvm/test/CodeGen/WebAssembly/tailcall.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/tailcall.ll
@@ -0,0 +1,21 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+tail-call | FileCheck %s
+
+; Test that the tail-call attribute is accepted
+; TODO(tlively): implement tail call
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: recursive_tail:
+; CHECK:  i32.call $push[[L0:[0-9]+]]=, recursive_tail{{$}}
+; CHECK-NEXT: return $pop[[L0]]{{$}}
+define i32 @recursive_tail() {
+  %v = tail call i32 @recursive_tail()
+  ret i32 %v
+}
+
+; CHECK-LABEL: .section .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 9
+; CHECK-NEXT: .ascii "tail-call"
Index: llvm/test/CodeGen/WebAssembly/multivalue.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/multivalue.ll
@@ -0,0 +1,28 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+multivalue | FileCheck %s
+
+; Test that the multivalue attribute is accepted
+; TODO(tlively): implement multivalue
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%pair = type { i32, i32 }
+%packed_pair = type <{ i32, i32 }>
+
+; CHECK-LABEL: sret:
+; CHECK-NEXT: sret (i32, i32, i32) -> ()
+define %pair @sret(%pair %p) {
+  ret %pair %p
+}
+
+; CHECK-LABEL: packed_sret:
+; CHECK-NEXT: packed_sret (i32, i32, i32) -> ()
+define %packed_pair @packed_sret(%packed_pair %p) {
+  ret %packed_pair %p
+}
+
+; CHECK-LABEL: .section .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 10
+; CHECK-NEXT: .ascii "multivalue"
Index: llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -44,7 +44,9 @@
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMultivalue = false;
   bool HasMutableGlobals = false;
+  bool HasTailCall = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -98,7 +100,9 @@
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMultivalue() const { return HasMultivalue; }
   bool hasMutableGlobals() const { return HasMutableGlobals; }
+  bool hasTailCall() const { return HasTailCall; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -34,6 +34,10 @@
 Predicate<"Subtarget->hasAtomics()">,
 AssemblerPredicate<"FeatureAtomics", "atomics">;
 
+def HasMultivalue :
+Predicate<"Subtarget->hasMultivalue()">,
+AssemblerPredicate<"FeatureMultivalue", "multivalue">;
+
 def HasNontrappingFPToInt :
 Predicate<"Subtarget->hasNontrappingFPToInt()">,
 AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">;
@@ -46,18 +50,14 @@
 Predicate<"Subtarget->hasSignExt()">,
 AssemblerPredicate<"FeatureSignExt", "sign-ext">;
 
-def NotHasSignExt :
-Predicate<"!Subtarget->hasSignExt()">,
-AssemblerPredicate<"!FeatureSignExt", "sign-ext">;
+def HasTailCall :
+Predicate<"Subtarget->hasTailCall()">,
+AssemblerPredicate<"FeatureTailCall", "tail-call">;
 
 def HasExceptionHandling :
 Predicate<"Subtarget->hasExceptionHandling()">,
 AssemblerPredicate<"FeatureExcep

[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-21 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D62047#1505878 , @aheejin wrote:

> How about using `multi_value`/`multi-value`/`MultiValue`/`MULTI-VALUE` 
> (depending on positions)? The repo name is also multi-value. 
> https://github.com/WebAssembly/multi-value
>  Otherwise LGTM.


From 
https://english.stackexchange.com/questions/118021/existence-of-multi-in-us-english:

> the prefix multi is valid in American English, and usually used unhyphenated

F8907535: multivalue.jpg 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62047/new/

https://reviews.llvm.org/D62047



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-23 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361516: [WebAssembly] Add multivalue and tail-call target 
features (authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62047?vs=199941&id=201010#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62047/new/

https://reviews.llvm.org/D62047

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Basic/Targets/WebAssembly.cpp
  cfe/trunk/lib/Basic/Targets/WebAssembly.h
  cfe/trunk/test/Preprocessor/wasm-target-features.c
  llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/trunk/test/CodeGen/WebAssembly/multivalue.ll
  llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll

Index: llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
+++ llvm/trunk/lib/Target/WebAssembly/WebAssembly.td
@@ -33,6 +33,7 @@
 
 def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true",
   "Enable Atomics">;
+
 def FeatureNontrappingFPToInt :
   SubtargetFeature<"nontrapping-fptoint",
"HasNontrappingFPToInt", "true",
@@ -43,6 +44,11 @@
"HasSignExt", "true",
"Enable sign extension operators">;
 
+def FeatureTailCall :
+  SubtargetFeature<"tail-call",
+   "HasTailCall", "true",
+   "Enable tail call instructions">;
+
 def FeatureExceptionHandling :
   SubtargetFeature<"exception-handling", "HasExceptionHandling", "true",
"Enable Wasm exception handling">;
@@ -51,6 +57,11 @@
   SubtargetFeature<"bulk-memory", "HasBulkMemory", "true",
"Enable bulk memory operations">;
 
+def FeatureMultivalue :
+  SubtargetFeature<"multivalue",
+   "HasMultivalue", "true",
+   "Enable multivalue blocks, instructions, and functions">;
+
 def FeatureMutableGlobals :
   SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true",
"Enable mutable globals">;
Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -34,6 +34,10 @@
 Predicate<"Subtarget->hasAtomics()">,
 AssemblerPredicate<"FeatureAtomics", "atomics">;
 
+def HasMultivalue :
+Predicate<"Subtarget->hasMultivalue()">,
+AssemblerPredicate<"FeatureMultivalue", "multivalue">;
+
 def HasNontrappingFPToInt :
 Predicate<"Subtarget->hasNontrappingFPToInt()">,
 AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">;
@@ -46,18 +50,14 @@
 Predicate<"Subtarget->hasSignExt()">,
 AssemblerPredicate<"FeatureSignExt", "sign-ext">;
 
-def NotHasSignExt :
-Predicate<"!Subtarget->hasSignExt()">,
-AssemblerPredicate<"!FeatureSignExt", "sign-ext">;
+def HasTailCall :
+Predicate<"Subtarget->hasTailCall()">,
+AssemblerPredicate<"FeatureTailCall", "tail-call">;
 
 def HasExceptionHandling :
 Predicate<"Subtarget->hasExceptionHandling()">,
 AssemblerPredicate<"FeatureExceptionHandling", "exception-handling">;
 
-def NotHasExceptionHandling :
-Predicate<"!Subtarget->hasExceptionHandling()">,
-AssemblerPredicate<"!FeatureExceptionHandling", "exception-handling">;
-
 def HasBulkMemory :
 Predicate<"Subtarget->hasBulkMemory()">,
 AssemblerPredicate<"FeatureBulkMemory", "bulk-memory">;
Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -44,7 +44,9 @@
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMultivalue = false;
   bool HasMutableGlobals = false;
+  bool HasTailCall = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -98,7 +100,9 @@
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMultivalue() const { return HasMultivalue; }
   bool hasMutableGlobals() const { return HasMutableGlobals; }
+  bool hasTailCall() const { return HasTailCall; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
Index: llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll
===
--- llvm/trunk/test/CodeGen/WebAsse

[PATCH] D62333: Fix unresolved symbols when linking tools/clang/unittests/Tooling/ToolingTests

2019-05-23 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361536: Fix unresolved symbols when linking 
tools/clang/unittests/Tooling/ToolingTests (authored by tlively, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62333?vs=201022&id=201036#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62333/new/

https://reviews.llvm.org/D62333

Files:
  cfe/trunk/unittests/Tooling/CMakeLists.txt


Index: cfe/trunk/unittests/Tooling/CMakeLists.txt
===
--- cfe/trunk/unittests/Tooling/CMakeLists.txt
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt
@@ -71,6 +71,7 @@
   clangToolingCore
   clangToolingInclusions
   clangToolingRefactor
+  LLVMTestingSupport
   )
 
 


Index: cfe/trunk/unittests/Tooling/CMakeLists.txt
===
--- cfe/trunk/unittests/Tooling/CMakeLists.txt
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt
@@ -71,6 +71,7 @@
   clangToolingCore
   clangToolingInclusions
   clangToolingRefactor
+  LLVMTestingSupport
   )
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62559: [WebAssembly] Support VPtr sanitizer for Emscripten

2019-05-28 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

Please add a test!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62559/new/

https://reviews.llvm.org/D62559



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62559: [WebAssembly] Support VPtr sanitizer for Emscripten

2019-05-29 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362004: [WebAssembly] Support VPtr sanitizer for Emscripten 
(authored by tlively, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62559?vs=201803&id=202003#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62559/new/

https://reviews.llvm.org/D62559

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
  cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp


Index: cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
===
--- cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
+++ cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -emit-llvm %s -o - -triple 
wasm32-unknown-emscripten | FileCheck %s
+
+struct S {
+  virtual ~S() {}
+  int a;
+};
+
+struct T : S {
+  int b;
+};
+
+// CHECK-LABEL: @_Z15bad_static_castv
+void bad_static_cast() {
+  S s;
+  // CHECK: br i1 %[[NONNULL:.*]], label %[[CONT:.*]], label %[[MISS:.*]], 
!prof
+  // CHECK: [[MISS]]:
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss_abort
+  // CHECK: [[CONT]]:
+  T &r = static_cast(s);
+}
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
@@ -66,6 +66,7 @@
   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
+  SanitizerMask getSupportedSanitizers() const override;
 
   const char *getDefaultLinker() const override { return "wasm-ld"; }
 
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -208,6 +208,14 @@
   }
 }
 
+SanitizerMask WebAssembly::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (getTriple().isOSEmscripten()) {
+Res |= SanitizerKind::Vptr;
+  }
+  return Res;
+}
+
 Tool *WebAssembly::buildLinker() const {
   return new tools::wasm::Linker(*this);
 }


Index: cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
===
--- cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
+++ cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -emit-llvm %s -o - -triple wasm32-unknown-emscripten | FileCheck %s
+
+struct S {
+  virtual ~S() {}
+  int a;
+};
+
+struct T : S {
+  int b;
+};
+
+// CHECK-LABEL: @_Z15bad_static_castv
+void bad_static_cast() {
+  S s;
+  // CHECK: br i1 %[[NONNULL:.*]], label %[[CONT:.*]], label %[[MISS:.*]], !prof
+  // CHECK: [[MISS]]:
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss_abort
+  // CHECK: [[CONT]]:
+  T &r = static_cast(s);
+}
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
@@ -66,6 +66,7 @@
   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
+  SanitizerMask getSupportedSanitizers() const override;
 
   const char *getDefaultLinker() const override { return "wasm-ld"; }
 
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -208,6 +208,14 @@
   }
 }
 
+SanitizerMask WebAssembly::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (getTriple().isOSEmscripten()) {
+Res |= SanitizerKind::Vptr;
+  }
+  return Res;
+}
+
 Tool *WebAssembly::buildLinker() const {
   return new tools::wasm::Linker(*this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-09 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, 
sbc100.

Depends on D56501 . Also adds a macro define
__wasm_unimplemented_simd128__ for feature detection of unimplemented
SIMD builtins.


Repository:
  rC Clang

https://reviews.llvm.org/D56504

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,9 +1,5 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
 
 // SIMD convenience types
 typedef char i8x16 __attribute((vector_size(16)));
Index: lib/Basic/Targets/WebAssembly.h
===
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -28,7 +28,8 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
-  } SIMDLevel;
+UnimplementedSIMD128,
+  } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt;
   bool HasSignExt;
@@ -59,18 +60,12 @@
 MacroBuilder &Builder) const override;
 
 private:
+  static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level);
+
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
- const std::vector &FeaturesVec) const override {
-if (CPU == "bleeding-edge") {
-  Features["simd128"] = true;
-  Features["nontrapping-fptoint"] = true;
-  Features["sign-ext"] = true;
-}
-return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
-  }
-
+ const std::vector &FeaturesVec) const override;
   bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
Index: lib/Basic/Targets/WebAssembly.cpp
===
--- lib/Basic/Targets/WebAssembly.cpp
+++ lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   \
   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)\
   {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
 #include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("unimplemented-simd128", SIMDLevel >= UnimplementedSIMD128)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -55,8 +58,47 @@
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= UnimplementedSIMD128)
+Builder.defineMacro("__wasm_unimplemented_simd128__");
 }
 
+void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level) {
+  switch (Level) {
+  case UnimplementedSIMD128:
+Features["unimplemented-simd128"] = true;
+LLVM_FALLTHROUGH;
+  case SIMD128:
+Features["simd128"] = true;
+Features["sign-ext"] = true;
+LLVM_FALLTHROUGH;
+  case NoSIMD:
+break;
+  }
+}
+
+bool WebAssemblyTargetInfo::initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
+ StringRef CPU,
+ const std::vector &FeaturesVec) const {
+if (CPU == "bleeding-edge") {
+  Features["nontrapping-fptoint"] = true;
+  Features["sign-ext"] = true;
+  setSIMDLevel(Features, SIMD128);
+}
+// Other targets do not consider use

[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-09 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 180921.
tlively added a comment.

- Decouple sign-ext from simd128


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,9 +1,5 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
 
 // SIMD convenience types
 typedef char i8x16 __attribute((vector_size(16)));
Index: lib/Basic/Targets/WebAssembly.h
===
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -28,7 +28,8 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
-  } SIMDLevel;
+UnimplementedSIMD128,
+  } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt;
   bool HasSignExt;
@@ -59,18 +60,12 @@
 MacroBuilder &Builder) const override;
 
 private:
+  static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level);
+
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
- const std::vector &FeaturesVec) const override {
-if (CPU == "bleeding-edge") {
-  Features["simd128"] = true;
-  Features["nontrapping-fptoint"] = true;
-  Features["sign-ext"] = true;
-}
-return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
-  }
-
+ const std::vector &FeaturesVec) const override;
   bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
Index: lib/Basic/Targets/WebAssembly.cpp
===
--- lib/Basic/Targets/WebAssembly.cpp
+++ lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   \
   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)\
   {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
 #include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("unimplemented-simd128", SIMDLevel >= UnimplementedSIMD128)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -55,8 +58,46 @@
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= UnimplementedSIMD128)
+Builder.defineMacro("__wasm_unimplemented_simd128__");
 }
 
+void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level) {
+  switch (Level) {
+  case UnimplementedSIMD128:
+Features["unimplemented-simd128"] = true;
+LLVM_FALLTHROUGH;
+  case SIMD128:
+Features["simd128"] = true;
+LLVM_FALLTHROUGH;
+  case NoSIMD:
+break;
+  }
+}
+
+bool WebAssemblyTargetInfo::initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
+ StringRef CPU,
+ const std::vector &FeaturesVec) const {
+if (CPU == "bleeding-edge") {
+  Features["nontrapping-fptoint"] = true;
+  Features["sign-ext"] = true;
+  setSIMDLevel(Features, SIMD128);
+}
+// Other targets do not consider user-configured features here, but while we
+// are actively developing new features it is useful to let user-configured
+// features control availability of builtins
+setSIMDLe

[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-09 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 180984.
tlively added a comment.

- Match the new naming scheme from rL350791 


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,9 +1,5 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +simd128-unimplemented -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +simd128-unimplemented -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
 
 // SIMD convenience types
 typedef char i8x16 __attribute((vector_size(16)));
Index: lib/Basic/Targets/WebAssembly.h
===
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -28,7 +28,8 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
-  } SIMDLevel;
+SIMD128Unimplemented,
+  } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt;
   bool HasSignExt;
@@ -59,18 +60,12 @@
 MacroBuilder &Builder) const override;
 
 private:
+  static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level);
+
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
- const std::vector &FeaturesVec) const override {
-if (CPU == "bleeding-edge") {
-  Features["simd128"] = true;
-  Features["nontrapping-fptoint"] = true;
-  Features["sign-ext"] = true;
-}
-return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
-  }
-
+ const std::vector &FeaturesVec) const override;
   bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
Index: lib/Basic/Targets/WebAssembly.cpp
===
--- lib/Basic/Targets/WebAssembly.cpp
+++ lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   \
   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)\
   {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
 #include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("simd128-unimplemented", SIMDLevel >= SIMD128Unimplemented)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -55,8 +58,46 @@
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= SIMD128Unimplemented)
+Builder.defineMacro("__wasm_unimplemented_simd128__");
 }
 
+void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level) {
+  switch (Level) {
+  case SIMD128Unimplemented:
+Features["simd128-unimplemented"] = true;
+LLVM_FALLTHROUGH;
+  case SIMD128:
+Features["simd128"] = true;
+LLVM_FALLTHROUGH;
+  case NoSIMD:
+break;
+  }
+}
+
+bool WebAssemblyTargetInfo::initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
+ StringRef CPU,
+ const std::vector &FeaturesVec) const {
+if (CPU == "bleeding-edge") {
+  Features["nontrapping-fptoint"] = true;
+  Features["sign-ext"] = true;
+  setSIMDLevel(Features, SIMD128);
+}
+// Other targets do not consider user-configured features here, but while we
+// are actively developing new features it is useful to let user-configured
+// features 

[PATCH] D56504: [WebAssembly] Add simd128-unimplemented feature, gate builtins

2019-01-09 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: lib/Basic/Targets/WebAssembly.cpp:89
+// features control availability of builtins
+setSIMDLevel(Features, SIMDLevel);
+if (HasNontrappingFPToInt)

aheejin wrote:
> Minor thing, but should we extract this as a function? It is gonna be a 
> couple line anyway, like
> 
> ```
> if (CPU == "bleeding-edge") {
>   ...
>   Features["unimplemented-simd128"] = Features["simd128"] = true;
> }
> 
> if (SIMDLevel >= SIMD128)
>   Features["simd128"] = true;
> if (SIMDLevel >= UnimplementedSIMD128)
>   Features["unimplemented-simd128"] = true;
> ...
> 
> And to me it is more readable to see all `Features` setting in one place. But 
> I'm not too opinionated either.
The structure of basically all this code is pulled from X86.cpp, which is 
obviously has a lot more features to wrangle. This particular function is 
similar to `setSSELevel` in X86.cpp. I agree that it probably doesn't need to 
be separate now, but as we explore possible extensions to the SIMD proposal in 
the future I think it will be useful to have this function.



Comment at: lib/Basic/Targets/WebAssembly.cpp:98
+return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
+  }
+

aheejin wrote:
> The indentation of these functions looks weird and there are lines that 
> exceeds 80 cols. clang-format?
Done, and copied my pre-commit git hooks from the main LLVM repo so it won't be 
an issue again.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56504: [WebAssembly] Add simd128-unimplemented feature, gate builtins

2019-01-09 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 180989.
tlively marked 3 inline comments as done.
tlively added a comment.

- Fix formatting, fix and test macro name


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/CodeGen/builtins-wasm.c
  test/Preprocessor/wasm-target-features.c

Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.c
@@ -8,6 +8,15 @@
 // SIMD128:#define __wasm_simd128__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -msimd128-unimplemented \
+// RUN:   | FileCheck %s -check-prefix=SIMD128-UNIMPLEMENTED
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -msimd128-unimplemented \
+// RUN:   | FileCheck %s -check-prefix=SIMD128-UNIMPLEMENTED
+//
+// SIMD128-UNIMPLEMENTED:#define __wasm_simd128_unimplemented__ 1{{$}}
+//
+// RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
 // RUN:   | FileCheck %s -check-prefix=MVP
 // RUN: %clang -E -dM %s -o - 2>&1 \
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,9 +1,6 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +simd128-unimplemented -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +simd128-unimplemented -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
 
 // SIMD convenience types
 typedef char i8x16 __attribute((vector_size(16)));
@@ -158,6 +155,7 @@
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
Index: lib/Basic/Targets/WebAssembly.h
===
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -28,7 +28,8 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
-  } SIMDLevel;
+SIMD128Unimplemented,
+  } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt;
   bool HasSignExt;
@@ -59,18 +60,12 @@
 MacroBuilder &Builder) const override;
 
 private:
+  static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level);
+
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
- const std::vector &FeaturesVec) const override {
-if (CPU == "bleeding-edge") {
-  Features["simd128"] = true;
-  Features["nontrapping-fptoint"] = true;
-  Features["sign-ext"] = true;
-}
-return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
-  }
-
+ const std::vector &FeaturesVec) const override;
   bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
Index: lib/Basic/Targets/WebAssembly.cpp
===
--- lib/Basic/Targets/WebAssembly.cpp
+++ lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   \
   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)\
   {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
 #include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@
 bool WebAssemblyTarget

[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-10 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 181171.
tlively marked an inline comment as done.
tlively added a comment.

- Change names again to reflect latest committed LLVM change


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/CodeGen/builtins-wasm.c
  test/Preprocessor/wasm-target-features.c

Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.c
@@ -8,6 +8,15 @@
 // SIMD128:#define __wasm_simd128__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -munimplemented-simd128 \
+// RUN:   | FileCheck %s -check-prefix=SIMD128-UNIMPLEMENTED
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -munimplemented-simd128 \
+// RUN:   | FileCheck %s -check-prefix=SIMD128-UNIMPLEMENTED
+//
+// SIMD128-UNIMPLEMENTED:#define __wasm_unimplemented_simd128__ 1{{$}}
+//
+// RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
 // RUN:   | FileCheck %s -check-prefix=MVP
 // RUN: %clang -E -dM %s -o - 2>&1 \
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,9 +1,6 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
-// RUN:   -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +unimplemented-simd128 -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature +nontrapping-fptoint -target-feature +exception-handling -fno-lax-vector-conversions -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
 
 // SIMD convenience types
 typedef char i8x16 __attribute((vector_size(16)));
@@ -158,6 +155,7 @@
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
Index: lib/Basic/Targets/WebAssembly.h
===
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -28,7 +28,8 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
-  } SIMDLevel;
+UnimplementedSIMD128,
+  } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt;
   bool HasSignExt;
@@ -59,18 +60,12 @@
 MacroBuilder &Builder) const override;
 
 private:
+  static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level);
+
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
- const std::vector &FeaturesVec) const override {
-if (CPU == "bleeding-edge") {
-  Features["simd128"] = true;
-  Features["nontrapping-fptoint"] = true;
-  Features["sign-ext"] = true;
-}
-return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
-  }
-
+ const std::vector &FeaturesVec) const override;
   bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
Index: lib/Basic/Targets/WebAssembly.cpp
===
--- lib/Basic/Targets/WebAssembly.cpp
+++ lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   \
   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)\
   {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
 #include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@
 boo

[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-10 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:53
 // Saturating fp-to-int conversions
-BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f64, "id", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f64, "id", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f32, "LLif", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f32, "LLif", "nc")
-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")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc", 
"nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc", 
"nontrapping-fptoint")

aheejin wrote:
> aheejin wrote:
> > clang-format this file
> This file still does not look like clang-formatted; I guess your script 
> misses this file because its extension is `def`.
As discussed, clang-format might be bad for readability in this file.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56504: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

2019-01-10 Thread Thomas Lively via Phabricator via cfe-commits
tlively closed this revision.
tlively added a comment.

Closed by commit rC350909 .


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56504/new/

https://reviews.llvm.org/D56504



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67425: [WebAssembly] Narrowing and widening SIMD ops

2019-09-10 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.

Implements target-specific LLVM intrinsics and clang builtins for
these new SIMD operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67425

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -463,4 +463,40 @@
 # CHECK: f64x2.convert_i64x2_u # encoding: [0xfd,0xb2,0x01]
 f64x2.convert_i64x2_u
 
+# CHECK: i8x16.narrow_i16x8_s # encoding: [0xfd,0xc6,0x01]
+i8x16.narrow_i16x8_s
+
+# CHECK: i8x16.narrow_i16x8_u # encoding: [0xfd,0xc7,0x01]
+i8x16.narrow_i16x8_u
+
+# CHECK: i16x8.narrow_i32x4_s # encoding: [0xfd,0xc8,0x01]
+i16x8.narrow_i32x4_s
+
+# CHECK: i16x8.narrow_i32x4_u # encoding: [0xfd,0xc9,0x01]
+i16x8.narrow_i32x4_u
+
+# CHECK: i16x8.widen_low_i8x16_s # encoding: [0xfd,0xca,0x01]
+i16x8.widen_low_i8x16_s
+
+# CHECK: i16x8.widen_high_i8x16_s # encoding: [0xfd,0xcb,0x01]
+i16x8.widen_high_i8x16_s
+
+# CHECK: i16x8.widen_low_i8x16_u # encoding: [0xfd,0xcc,0x01]
+i16x8.widen_low_i8x16_u
+
+# CHECK: i16x8.widen_high_i8x16_u # encoding: [0xfd,0xcd,0x01]
+i16x8.widen_high_i8x16_u
+
+# CHECK: i32x4.widen_low_i16x8_s # encoding: [0xfd,0xce,0x01]
+i32x4.widen_low_i16x8_s
+
+# CHECK: i32x4.widen_high_i16x8_s # encoding: [0xfd,0xcf,0x01]
+i32x4.widen_high_i16x8_s
+
+# CHECK: i32x4.widen_low_i16x8_u # encoding: [0xfd,0xd0,0x01]
+i32x4.widen_low_i16x8_u
+
+# CHECK: i32x4.widen_high_i16x8_u # encoding: [0xfd,0xd1,0x01]
+i32x4.widen_high_i16x8_u
+
 end_function
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -712,6 +712,33 @@
 defm "" : SIMDConvert;
 defm "" : SIMDConvert;
 
+// Narrowing operations
+multiclass SIMDNarrow baseInst> {
+  defm "" : SIMDConvert;
+  defm "" : SIMDConvert;
+}
+defm "" : SIMDNarrow;
+defm "" : SIMDNarrow;
+
+// Widening operations
+multiclass SIMDWiden baseInst> {
+  defm "" : SIMDConvert;
+  defm "" : SIMDConvert;
+  defm "" : SIMDConvert;
+  defm "" : SIMDConvert;
+}
+
+defm "" : SIMDWiden;
+defm "" : SIMDWiden;
+
 // Lower llvm.wasm.trunc.saturate.* to saturating instructions
 def : Pat<(v4i32 (int_wasm_trunc_saturate_signed (v4f32 V128:$src))),
   (fp_to_sint_v4i32_v4f32 (v4f32 V128:$src))>;
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -117,6 +117,31 @@
   Intrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
 [IntrNoMem, IntrSpeculatable]>;
+def int_wasm_narrow_signed :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_narrow_unsigned :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_widen_low_signed :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_widen_high_signed :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_widen_low_unsigned :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_widen_high_unsigned :
+  Intrinsic<[llvm_anyvector_ty],
+[llvm_anyvector_ty],
+[IntrNoMem, IntrSpeculatable]>;
+
 
 //===--===//
 // Bulk memory intrinsics
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -463,3 +463,75 @@
   // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 narrow_s_i8x16_i16x8(i16x8 v) {
+  return __builtin_wasm_narrow_s_i8x16_i16x8(v);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.narrow.signed.v16i8.v8i16(<8 x i16> %v)
+  // WEBASSEMBLY: ret
+}
+
+i8x16 narrow_u_i8x16_i16x8(i16x8 v) {
+ 

  1   2   3   4   5   >