[PATCH] D65753: Builtins: Add some v2f16 variants

2022-12-07 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm abandoned this revision.
arsenm added a comment.
Herald added a project: All.

Looks like __builtin_elementwise_* now exist to handle some of these operations 
for arbitrary vector elements


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

https://reviews.llvm.org/D65753

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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-06 Thread Steve Canon via Phabricator via cfe-commits
scanon added a comment.

(Ideally we would just call them e.g. __builtin_floor, but that would be 
source-breaking. __builtin_tgmath_floor seems like a good compromise.)


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

https://reviews.llvm.org/D65753



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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-06 Thread Steve Canon via Phabricator via cfe-commits
scanon added a comment.

Strongly agree with what @rjmccall said. If we can make these generic builtins 
instead of ending up with O(100) variants of each math operation, that would 
make life immensely nicer.


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

https://reviews.llvm.org/D65753



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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm, sorry, that's a C++ spec, and it looks like the (abandoned) C attempt at 
data parallelism (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2081.htm) 
doesn't introduce vector types.

Talking about it internally, I think there are two reasonable approaches:

- Add an OpenCL prefix to the builtin, e.g. `__builtin_cl_floorv216`.  This 
isn't great because it feels like it's heading towards a world with a million 
builtins for different element types and vector sizes.
- Make the builtin type-generic, e.g. `__builtin_generic_floor` (or 
`__builtin_tgmath_floor`), where the builtin allows an arbitrary floating-point 
argument (or vector thereof).


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

https://reviews.llvm.org/D65753



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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

You might want to look into ISO/IEC TS 19570 - 2018 to see what they're 
thinking.  If it looks like there's a potential conflict, then maybe these 
should have an OpenCL-specific prefix on them.


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

https://reviews.llvm.org/D65753



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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  I think there are two reasonable concerns here, both arising from the 
fact that these names occupy (the builtin namespace parallel to) a namespace 
that the committee might want to occupy in the future:

- Is a `v2fN` suffix sufficiently likely to avoid interfering with this 
namespace?  If there's an *exact* collision, that might be okay if the builtin 
actually matches the standard behavior; my concern is that they might conflict. 
 (Different orderings of element count and element type?  Unrelated functions 
ending in `v`?)
- Is it a good idea to introduce builtins in this namespace that traffic in our 
current vector types instead of a potential future standard-blessed vector type?


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

https://reviews.llvm.org/D65753



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


[PATCH] D65753: Builtins: Add some v2f16 variants

2019-08-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: rjmccall, Anastasia, yaxunl, rsmith.
Herald added a subscriber: wdng.
arsenm added a parent revision: D65597: WIP: Builtins: Start adding half 
versions of math builtins.

This will avoid hacks in the OpenCL builtin library.


https://reviews.llvm.org/D65753

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/builtins-f16.cl

Index: test/CodeGenOpenCL/builtins-f16.cl
===
--- test/CodeGenOpenCL/builtins-f16.cl
+++ test/CodeGenOpenCL/builtins-f16.cl
@@ -1,7 +1,10 @@
-// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-darwin-apple %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn-amd-amdhsa %s | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+
 // CHECK-LABEL: define void @test_half_builtins
 void test_half_builtins(half h0, half h1, half h2) {
   volatile half res;
@@ -69,3 +72,35 @@
   // CHECK: call half @llvm.canonicalize.f16(half %h0)
   res = __builtin_canonicalizef16(h0);
 }
+
+// CHECK-LABEL: @test_v2f16_builtins(
+void test_v2f16_builtins(half2 h0, half2 h1, half2 h2) {
+  volatile half2 res;
+
+  // CHECK: call <2 x half> @llvm.fma.v2f16(<2 x half> %h0, <2 x half> %h1, <2 x half> %h2)
+  res = __builtin_fmav2f16(h0, h1 ,h2);
+
+  // CHECK: call <2 x half> @llvm.maxnum.v2f16(<2 x half> %h0, <2 x half> %h1)
+  res = __builtin_fmaxv2f16(h0, h1);
+
+  // CHECK: call <2 x half> @llvm.minnum.v2f16(<2 x half> %h0, <2 x half> %h1)
+  res = __builtin_fminv2f16(h0, h1);
+
+  // CHECK: call <2 x half> @llvm.copysign.v2f16(<2 x half> %h0, <2 x half> %h1)
+  res = __builtin_copysignv2f16(h0, h1);
+
+  // CHECK: call <2 x half> @llvm.floor.v2f16(<2 x half> %h0)
+  res = __builtin_floorv2f16(h0);
+
+  // CHECK: call <2 x half> @llvm.ceil.v2f16(<2 x half> %h0)
+  res = __builtin_ceilv2f16(h0);
+
+  // CHECK: call <2 x half> @llvm.trunc.v2f16(<2 x half> %h0)
+  res = __builtin_truncv2f16(h0);
+
+  // CHECK: call <2 x half> @llvm.rint.v2f16(<2 x half> %h0)
+  res = __builtin_rintv2f16(h0);
+
+  // CHECK: call <2 x half> @llvm.canonicalize.v2f16(<2 x half> %h0)
+  res = __builtin_canonicalizev2f16(h0);
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1558,6 +1558,7 @@
 case Builtin::BI__builtin_ceil:
 case Builtin::BI__builtin_ceilf:
 case Builtin::BI__builtin_ceilf16:
+case Builtin::BI__builtin_ceilv2f16:
 case Builtin::BI__builtin_ceill:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::ceil));
 
@@ -1567,6 +1568,7 @@
 case Builtin::BI__builtin_copysign:
 case Builtin::BI__builtin_copysignf:
 case Builtin::BI__builtin_copysignf16:
+case Builtin::BI__builtin_copysignv2f16:
 case Builtin::BI__builtin_copysignl:
 case Builtin::BI__builtin_copysignf128:
   return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::copysign));
@@ -1614,6 +1616,7 @@
 case Builtin::BI__builtin_floor:
 case Builtin::BI__builtin_floorf:
 case Builtin::BI__builtin_floorf16:
+case Builtin::BI__builtin_floorv2f16:
 case Builtin::BI__builtin_floorl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::floor));
 
@@ -1623,6 +1626,7 @@
 case Builtin::BI__builtin_fma:
 case Builtin::BI__builtin_fmaf:
 case Builtin::BI__builtin_fmaf16:
+case Builtin::BI__builtin_fmav2f16:
 case Builtin::BI__builtin_fmal:
   return RValue::get(emitTernaryBuiltin(*this, E, Intrinsic::fma));
 
@@ -1632,6 +1636,7 @@
 case Builtin::BI__builtin_fmax:
 case Builtin::BI__builtin_fmaxf:
 case Builtin::BI__builtin_fmaxf16:
+case Builtin::BI__builtin_fmaxv2f16:
 case Builtin::BI__builtin_fmaxl:
   return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::maxnum));
 
@@ -1641,6 +1646,7 @@
 case Builtin::BI__builtin_fmin:
 case Builtin::BI__builtin_fminf:
 case Builtin::BI__builtin_fminf16:
+case Builtin::BI__builtin_fminv2f16:
 case Builtin::BI__builtin_fminl:
   return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::minnum));
 
@@ -1708,6 +1714,7 @@
 case Builtin::BI__builtin_rint:
 case Builtin::BI__builtin_rintf:
 case Builtin::BI__builtin_rintf16:
+case Builtin::BI__builtin_rintv2f16:
 case Builtin::BI__builtin_rintl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::rint));
 
@@ -1744,6 +1751,7 @@
 case Builtin::BI__builtin_trunc:
 case Builtin::BI__builtin_truncf:
 case Builtin::BI__builtin_truncf16:
+case Builtin::BI__builtin_truncv2f16:
 case Builtin::BI__builtin_truncl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::trunc));
 
@@ -4000,6 +4008,7 @@
   case Builtin::BI__builtin_canonicalize:
   case Builtin::BI__builtin_canonicalizef:
   case Builtin::BI__builtin_canonical