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