[PATCH] D65597: WIP: Builtins: Start adding half versions of math builtins

2019-08-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r367973


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

https://reviews.llvm.org/D65597



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


[PATCH] D65597: WIP: Builtins: Start adding half versions of math builtins

2019-08-05 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D65597



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


[PATCH] D65597: WIP: Builtins: Start adding half versions of math builtins

2019-08-04 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 213276.
arsenm added a comment.

Change naming scheme, add more and tests


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

https://reviews.llvm.org/D65597

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

Index: test/CodeGenOpenCL/builtins-f16.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/builtins-f16.cl
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-darwin-apple %s | FileCheck %s
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// CHECK-LABEL: define void @test_half_builtins
+void test_half_builtins(half h0, half h1, half h2) {
+  volatile half res;
+
+  // CHECK: call half @llvm.copysign.f16(half %h0, half %h1)
+  res = __builtin_copysignf16(h0, h1);
+
+  // CHECK: call half @llvm.fabs.f16(half %h0)
+  res = __builtin_fabsf16(h0);
+
+  // CHECK: call half @llvm.ceil.f16(half %h0)
+  res = __builtin_ceilf16(h0);
+
+  // CHECK: call half @llvm.cos.f16(half %h0)
+  res = __builtin_cosf16(h0);
+
+  // CHECK: call half @llvm.exp.f16(half %h0)
+  res = __builtin_expf16(h0);
+
+  // CHECK: call half @llvm.exp2.f16(half %h0)
+  res = __builtin_exp2f16(h0);
+
+  // CHECK: call half @llvm.floor.f16(half %h0)
+  res = __builtin_floorf16(h0);
+
+  // CHECK: call half @llvm.fma.f16(half %h0, half %h1, half %h2)
+  res = __builtin_fmaf16(h0, h1 ,h2);
+
+  // CHECK: call half @llvm.maxnum.f16(half %h0, half %h1)
+  res = __builtin_fmaxf16(h0, h1);
+
+  // CHECK: call half @llvm.minnum.f16(half %h0, half %h1)
+  res = __builtin_fminf16(h0, h1);
+
+  // CHECK: frem half %h0, %h1
+  res = __builtin_fmodf16(h0, h1);
+
+  // CHECK: call half @llvm.pow.f16(half %h0, half %h1)
+  res = __builtin_powf16(h0, h1);
+
+  // CHECK: call half @llvm.log10.f16(half %h0)
+  res = __builtin_log10f16(h0);
+
+  // CHECK: call half @llvm.log2.f16(half %h0)
+  res = __builtin_log2f16(h0);
+
+  // CHECK: call half @llvm.log.f16(half %h0)
+  res = __builtin_logf16(h0);
+
+  // CHECK: call half @llvm.rint.f16(half %h0)
+  res = __builtin_rintf16(h0);
+
+  // CHECK: call half @llvm.round.f16(half %h0)
+  res = __builtin_roundf16(h0);
+
+  // CHECK: call half @llvm.sin.f16(half %h0)
+  res = __builtin_sinf16(h0);
+
+  // CHECK: call half @llvm.sqrt.f16(half %h0)
+  res = __builtin_sqrtf16(h0);
+
+  // CHECK: call half @llvm.trunc.f16(half %h0)
+  res = __builtin_truncf16(h0);
+
+  // CHECK: call half @llvm.canonicalize.f16(half %h0)
+  res = __builtin_canonicalizef16(h0);
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1557,6 +1557,7 @@
 case Builtin::BIceill:
 case Builtin::BI__builtin_ceil:
 case Builtin::BI__builtin_ceilf:
+case Builtin::BI__builtin_ceilf16:
 case Builtin::BI__builtin_ceill:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::ceil));
 
@@ -1565,6 +1566,7 @@
 case Builtin::BIcopysignl:
 case Builtin::BI__builtin_copysign:
 case Builtin::BI__builtin_copysignf:
+case Builtin::BI__builtin_copysignf16:
 case Builtin::BI__builtin_copysignl:
 case Builtin::BI__builtin_copysignf128:
   return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::copysign));
@@ -1574,6 +1576,7 @@
 case Builtin::BIcosl:
 case Builtin::BI__builtin_cos:
 case Builtin::BI__builtin_cosf:
+case Builtin::BI__builtin_cosf16:
 case Builtin::BI__builtin_cosl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::cos));
 
@@ -1582,6 +1585,7 @@
 case Builtin::BIexpl:
 case Builtin::BI__builtin_exp:
 case Builtin::BI__builtin_expf:
+case Builtin::BI__builtin_expf16:
 case Builtin::BI__builtin_expl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp));
 
@@ -1590,6 +1594,7 @@
 case Builtin::BIexp2l:
 case Builtin::BI__builtin_exp2:
 case Builtin::BI__builtin_exp2f:
+case Builtin::BI__builtin_exp2f16:
 case Builtin::BI__builtin_exp2l:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp2));
 
@@ -1598,6 +1603,7 @@
 case Builtin::BIfabsl:
 case Builtin::BI__builtin_fabs:
 case Builtin::BI__builtin_fabsf:
+case Builtin::BI__builtin_fabsf16:
 case Builtin::BI__builtin_fabsl:
 case Builtin::BI__builtin_fabsf128:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::fabs));
@@ -1607,6 +1613,7 @@
 case Builtin::BIfloorl:
 case Builtin::BI__builtin_floor:
 case Builtin::BI__builtin_floorf:
+case Builtin::BI__builtin_floorf16:
 case Builtin::BI__builtin_floorl:
   return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::floor));
 
@@ -1615,6 +1622,7 @@
 case Builtin::BIfmal:
 case Builtin::BI__builtin_fma:
 case Builtin::BI__builtin_fmaf:
+case Builtin::BI__builtin_fmaf16:
 case Builtin::BI__builtin_fmal:
   return 

[PATCH] D65597: WIP: Builtins: Start adding half versions of math builtins

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

In N2405 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2405.pdf), these are 
called `truncf16`, `cosf16`, etc., which I think is appropriate.


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

https://reviews.llvm.org/D65597



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


[PATCH] D65597: WIP: Builtins: Start adding half versions of math builtins

2019-08-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: rsmith, rjmccall, Anastasia, yaxunl.
Herald added a subscriber: wdng.

The implementation of the OpenCL builtin currently library uses 2 different 
hacks to get to the corresponding IR intrinsics from the source. This will 
allow removal of those.

I'm not sure this is the right naming scheme, but tries to follow the
single character suffix like f/l. This is a problem for sin/cos, since
__builtin_sinh already means double sinh etc. Another alternative might be _f16


https://reviews.llvm.org/D65597

Files:
  include/clang/Basic/Builtins.def


Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -181,6 +181,7 @@
 BUILTIN(__builtin_ceil , "dd"  , "Fnc")
 BUILTIN(__builtin_ceilf, "ff"  , "Fnc")
 BUILTIN(__builtin_ceill, "LdLd", "Fnc")
+BUILTIN(__builtin_ceilh, "hh"  , "Fnc")
 BUILTIN(__builtin_cos , "dd"  , "Fne")
 BUILTIN(__builtin_cosf, "ff"  , "Fne")
 BUILTIN(__builtin_cosh , "dd"  , "Fne")
@@ -208,15 +209,19 @@
 BUILTIN(__builtin_floor , "dd"  , "Fnc")
 BUILTIN(__builtin_floorf, "ff"  , "Fnc")
 BUILTIN(__builtin_floorl, "LdLd", "Fnc")
+BUILTIN(__builtin_floorh, "hh"  , "Fnc")
 BUILTIN(__builtin_fma, "", "Fne")
 BUILTIN(__builtin_fmaf, "", "Fne")
 BUILTIN(__builtin_fmal, "LdLdLdLd", "Fne")
+BUILTIN(__builtin_fmah, "", "Fne")
 BUILTIN(__builtin_fmax, "ddd", "Fnc")
 BUILTIN(__builtin_fmaxf, "fff", "Fnc")
 BUILTIN(__builtin_fmaxl, "LdLdLd", "Fnc")
+BUILTIN(__builtin_fmaxf, "hhh", "Fnc")
 BUILTIN(__builtin_fmin, "ddd", "Fnc")
 BUILTIN(__builtin_fminf, "fff", "Fnc")
 BUILTIN(__builtin_fminl, "LdLdLd", "Fnc")
+BUILTIN(__builtin_fminh, "hhh", "Fnc")
 BUILTIN(__builtin_hypot , "ddd"  , "Fne")
 BUILTIN(__builtin_hypotf, "fff"  , "Fne")
 BUILTIN(__builtin_hypotl, "LdLdLd", "Fne")
@@ -271,6 +276,7 @@
 BUILTIN(__builtin_rint , "dd", "Fnc")
 BUILTIN(__builtin_rintf, "ff", "Fnc")
 BUILTIN(__builtin_rintl, "LdLd", "Fnc")
+BUILTIN(__builtin_rinth, "hh", "Fnc")
 BUILTIN(__builtin_round, "dd"  , "Fnc")
 BUILTIN(__builtin_roundf, "ff"  , "Fnc")
 BUILTIN(__builtin_roundl, "LdLd"  , "Fnc")
@@ -289,6 +295,7 @@
 BUILTIN(__builtin_sqrt , "dd"  , "Fne")
 BUILTIN(__builtin_sqrtf, "ff"  , "Fne")
 BUILTIN(__builtin_sqrtl, "LdLd", "Fne")
+BUILTIN(__builtin_sqrth, "ff"  , "Fne")
 BUILTIN(__builtin_tan , "dd"  , "Fne")
 BUILTIN(__builtin_tanf, "ff"  , "Fne")
 BUILTIN(__builtin_tanh , "dd"  , "Fne")
@@ -301,6 +308,7 @@
 BUILTIN(__builtin_trunc , "dd", "Fnc")
 BUILTIN(__builtin_truncf, "ff", "Fnc")
 BUILTIN(__builtin_truncl, "LdLd", "Fnc")
+BUILTIN(__builtin_trunch, "hh", "Fnc")
 
 // C99 complex builtins
 BUILTIN(__builtin_cabs, "dXd", "Fne")
@@ -395,6 +403,7 @@
 BUILTIN(__builtin_canonicalize, "dd", "nc")
 BUILTIN(__builtin_canonicalizef, "ff", "nc")
 BUILTIN(__builtin_canonicalizel, "LdLd", "nc")
+BUILTIN(__builtin_canonicalizeh, "hh", "nc")
 
 // Builtins for arithmetic.
 BUILTIN(__builtin_clzs , "iUs"  , "nc")


Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -181,6 +181,7 @@
 BUILTIN(__builtin_ceil , "dd"  , "Fnc")
 BUILTIN(__builtin_ceilf, "ff"  , "Fnc")
 BUILTIN(__builtin_ceill, "LdLd", "Fnc")
+BUILTIN(__builtin_ceilh, "hh"  , "Fnc")
 BUILTIN(__builtin_cos , "dd"  , "Fne")
 BUILTIN(__builtin_cosf, "ff"  , "Fne")
 BUILTIN(__builtin_cosh , "dd"  , "Fne")
@@ -208,15 +209,19 @@
 BUILTIN(__builtin_floor , "dd"  , "Fnc")
 BUILTIN(__builtin_floorf, "ff"  , "Fnc")
 BUILTIN(__builtin_floorl, "LdLd", "Fnc")
+BUILTIN(__builtin_floorh, "hh"  , "Fnc")
 BUILTIN(__builtin_fma, "", "Fne")
 BUILTIN(__builtin_fmaf, "", "Fne")
 BUILTIN(__builtin_fmal, "LdLdLdLd", "Fne")
+BUILTIN(__builtin_fmah, "", "Fne")
 BUILTIN(__builtin_fmax, "ddd", "Fnc")
 BUILTIN(__builtin_fmaxf, "fff", "Fnc")
 BUILTIN(__builtin_fmaxl, "LdLdLd", "Fnc")
+BUILTIN(__builtin_fmaxf, "hhh", "Fnc")
 BUILTIN(__builtin_fmin, "ddd", "Fnc")
 BUILTIN(__builtin_fminf, "fff", "Fnc")
 BUILTIN(__builtin_fminl, "LdLdLd", "Fnc")
+BUILTIN(__builtin_fminh, "hhh", "Fnc")
 BUILTIN(__builtin_hypot , "ddd"  , "Fne")
 BUILTIN(__builtin_hypotf, "fff"  , "Fne")
 BUILTIN(__builtin_hypotl, "LdLdLd", "Fne")
@@ -271,6 +276,7 @@
 BUILTIN(__builtin_rint , "dd", "Fnc")
 BUILTIN(__builtin_rintf, "ff", "Fnc")
 BUILTIN(__builtin_rintl, "LdLd", "Fnc")
+BUILTIN(__builtin_rinth, "hh", "Fnc")
 BUILTIN(__builtin_round, "dd"  , "Fnc")
 BUILTIN(__builtin_roundf, "ff"  , "Fnc")
 BUILTIN(__builtin_roundl, "LdLd"  , "Fnc")
@@ -289,6 +295,7 @@
 BUILTIN(__builtin_sqrt , "dd"  , "Fne")
 BUILTIN(__builtin_sqrtf, "ff"  , "Fne")
 BUILTIN(__builtin_sqrtl, "LdLd", "Fne")
+BUILTIN(__builtin_sqrth, "ff"  , "Fne")
 BUILTIN(__builtin_tan , "dd"  , "Fne")
 BUILTIN(__builtin_tanf, "ff"  , "Fne")
 BUILTIN(__builtin_tanh , "dd"  , "Fne")
@@ -301,6 +308,7 @@
 BUILTIN(__builtin_trunc , "dd", "Fnc")