Index: include/clang/Basic/Builtins.def =================================================================== --- include/clang/Basic/Builtins.def +++ include/clang/Basic/Builtins.def @@ -113,14 +113,17 @@ BUILTIN(__builtin_abs , "ii" , "ncF") BUILTIN(__builtin_copysign, "ddd", "ncF") BUILTIN(__builtin_copysignf, "fff", "ncF") +BUILTIN(__builtin_copysignf16, "hhh", "ncF") BUILTIN(__builtin_copysignl, "LdLdLd", "ncF") BUILTIN(__builtin_copysignf128, "LLdLLdLLd", "ncF") BUILTIN(__builtin_fabs , "dd" , "ncF") BUILTIN(__builtin_fabsf, "ff" , "ncF") BUILTIN(__builtin_fabsl, "LdLd", "ncF") +BUILTIN(__builtin_fabsf16, "hh" , "ncF") BUILTIN(__builtin_fabsf128, "LLdLLd", "ncF") BUILTIN(__builtin_fmod , "ddd" , "Fne") BUILTIN(__builtin_fmodf, "fff" , "Fne") +BUILTIN(__builtin_fmodf16, "hhh" , "Fne") BUILTIN(__builtin_fmodl, "LdLdLd", "Fne") BUILTIN(__builtin_frexp , "ddi*" , "Fn") BUILTIN(__builtin_frexpf, "ffi*" , "Fn") @@ -154,6 +157,7 @@ BUILTIN(__builtin_powil, "LdLdi", "Fnc") BUILTIN(__builtin_pow , "ddd" , "Fne") BUILTIN(__builtin_powf, "fff" , "Fne") +BUILTIN(__builtin_powf16, "hhh" , "Fne") BUILTIN(__builtin_powl, "LdLdLd", "Fne") // Standard unary libc/libm functions with double/float/long double variants: @@ -180,9 +184,11 @@ BUILTIN(__builtin_cbrtl, "LdLd", "Fnc") BUILTIN(__builtin_ceil , "dd" , "Fnc") BUILTIN(__builtin_ceilf, "ff" , "Fnc") +BUILTIN(__builtin_ceilf16, "hh" , "Fnc") BUILTIN(__builtin_ceill, "LdLd", "Fnc") BUILTIN(__builtin_cos , "dd" , "Fne") BUILTIN(__builtin_cosf, "ff" , "Fne") +BUILTIN(__builtin_cosf16, "hh" , "Fne") BUILTIN(__builtin_cosh , "dd" , "Fne") BUILTIN(__builtin_coshf, "ff" , "Fne") BUILTIN(__builtin_coshl, "LdLd", "Fne") @@ -195,9 +201,11 @@ BUILTIN(__builtin_erfcl, "LdLd", "Fne") BUILTIN(__builtin_exp , "dd" , "Fne") BUILTIN(__builtin_expf, "ff" , "Fne") +BUILTIN(__builtin_expf16, "hh" , "Fne") BUILTIN(__builtin_expl, "LdLd", "Fne") BUILTIN(__builtin_exp2 , "dd" , "Fne") BUILTIN(__builtin_exp2f, "ff" , "Fne") +BUILTIN(__builtin_exp2f16, "hh" , "Fne") BUILTIN(__builtin_exp2l, "LdLd", "Fne") BUILTIN(__builtin_expm1 , "dd", "Fne") BUILTIN(__builtin_expm1f, "ff", "Fne") @@ -207,15 +215,19 @@ BUILTIN(__builtin_fdiml, "LdLdLd", "Fne") BUILTIN(__builtin_floor , "dd" , "Fnc") BUILTIN(__builtin_floorf, "ff" , "Fnc") +BUILTIN(__builtin_floorf16, "hh" , "Fnc") BUILTIN(__builtin_floorl, "LdLd", "Fnc") BUILTIN(__builtin_fma, "dddd", "Fne") BUILTIN(__builtin_fmaf, "ffff", "Fne") +BUILTIN(__builtin_fmaf16, "hhhh", "Fne") BUILTIN(__builtin_fmal, "LdLdLdLd", "Fne") BUILTIN(__builtin_fmax, "ddd", "Fnc") BUILTIN(__builtin_fmaxf, "fff", "Fnc") +BUILTIN(__builtin_fmaxf16, "hhh", "Fnc") BUILTIN(__builtin_fmaxl, "LdLdLd", "Fnc") BUILTIN(__builtin_fmin, "ddd", "Fnc") BUILTIN(__builtin_fminf, "fff", "Fnc") +BUILTIN(__builtin_fminf16, "hhh", "Fnc") BUILTIN(__builtin_fminl, "LdLdLd", "Fnc") BUILTIN(__builtin_hypot , "ddd" , "Fne") BUILTIN(__builtin_hypotf, "fff" , "Fne") @@ -235,17 +247,20 @@ BUILTIN(__builtin_log , "dd" , "Fne") BUILTIN(__builtin_log10 , "dd" , "Fne") BUILTIN(__builtin_log10f, "ff" , "Fne") +BUILTIN(__builtin_log10f16, "hh" , "Fne") BUILTIN(__builtin_log10l, "LdLd", "Fne") BUILTIN(__builtin_log1p , "dd" , "Fne") BUILTIN(__builtin_log1pf, "ff" , "Fne") BUILTIN(__builtin_log1pl, "LdLd", "Fne") BUILTIN(__builtin_log2, "dd" , "Fne") BUILTIN(__builtin_log2f, "ff" , "Fne") +BUILTIN(__builtin_log2f16, "hh" , "Fne") BUILTIN(__builtin_log2l, "LdLd" , "Fne") BUILTIN(__builtin_logb , "dd", "Fne") BUILTIN(__builtin_logbf, "ff", "Fne") BUILTIN(__builtin_logbl, "LdLd", "Fne") BUILTIN(__builtin_logf, "ff" , "Fne") +BUILTIN(__builtin_logf16, "hh" , "Fne") BUILTIN(__builtin_logl, "LdLd", "Fne") BUILTIN(__builtin_lrint , "Lid", "Fne") BUILTIN(__builtin_lrintf, "Lif", "Fne") @@ -270,9 +285,11 @@ BUILTIN(__builtin_remquol, "LdLdLdi*", "Fn") BUILTIN(__builtin_rint , "dd", "Fnc") BUILTIN(__builtin_rintf, "ff", "Fnc") +BUILTIN(__builtin_rintf16, "hh", "Fnc") BUILTIN(__builtin_rintl, "LdLd", "Fnc") BUILTIN(__builtin_round, "dd" , "Fnc") BUILTIN(__builtin_roundf, "ff" , "Fnc") +BUILTIN(__builtin_roundf16, "hh" , "Fnc") BUILTIN(__builtin_roundl, "LdLd" , "Fnc") BUILTIN(__builtin_scalbln , "ddLi", "Fne") BUILTIN(__builtin_scalblnf, "ffLi", "Fne") @@ -282,12 +299,14 @@ BUILTIN(__builtin_scalbnl, "LdLdi", "Fne") BUILTIN(__builtin_sin , "dd" , "Fne") BUILTIN(__builtin_sinf, "ff" , "Fne") +BUILTIN(__builtin_sinf16, "hh" , "Fne") BUILTIN(__builtin_sinh , "dd" , "Fne") BUILTIN(__builtin_sinhf, "ff" , "Fne") BUILTIN(__builtin_sinhl, "LdLd", "Fne") BUILTIN(__builtin_sinl, "LdLd", "Fne") BUILTIN(__builtin_sqrt , "dd" , "Fne") BUILTIN(__builtin_sqrtf, "ff" , "Fne") +BUILTIN(__builtin_sqrtf16, "hh" , "Fne") BUILTIN(__builtin_sqrtl, "LdLd", "Fne") BUILTIN(__builtin_tan , "dd" , "Fne") BUILTIN(__builtin_tanf, "ff" , "Fne") @@ -301,6 +320,7 @@ BUILTIN(__builtin_trunc , "dd", "Fnc") BUILTIN(__builtin_truncf, "ff", "Fnc") BUILTIN(__builtin_truncl, "LdLd", "Fnc") +BUILTIN(__builtin_truncf16, "hh", "Fnc") // C99 complex builtins BUILTIN(__builtin_cabs, "dXd", "Fne") @@ -394,6 +414,7 @@ // Special FP builtins. BUILTIN(__builtin_canonicalize, "dd", "nc") BUILTIN(__builtin_canonicalizef, "ff", "nc") +BUILTIN(__builtin_canonicalizef16, "hh", "nc") BUILTIN(__builtin_canonicalizel, "LdLd", "nc") // Builtins for arithmetic. 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 RValue::get(emitTernaryBuiltin(*this, E, Intrinsic::fma)); @@ -1623,6 +1631,7 @@ case Builtin::BIfmaxl: case Builtin::BI__builtin_fmax: case Builtin::BI__builtin_fmaxf: + case Builtin::BI__builtin_fmaxf16: case Builtin::BI__builtin_fmaxl: return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::maxnum)); @@ -1631,6 +1640,7 @@ case Builtin::BIfminl: case Builtin::BI__builtin_fmin: case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminf16: case Builtin::BI__builtin_fminl: return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::minnum)); @@ -1641,6 +1651,7 @@ case Builtin::BIfmodl: case Builtin::BI__builtin_fmod: case Builtin::BI__builtin_fmodf: + case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: { Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); @@ -1652,6 +1663,7 @@ case Builtin::BIlogl: case Builtin::BI__builtin_log: case Builtin::BI__builtin_logf: + case Builtin::BI__builtin_logf16: case Builtin::BI__builtin_logl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log)); @@ -1660,6 +1672,7 @@ case Builtin::BIlog10l: case Builtin::BI__builtin_log10: case Builtin::BI__builtin_log10f: + case Builtin::BI__builtin_log10f16: case Builtin::BI__builtin_log10l: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log10)); @@ -1668,6 +1681,7 @@ case Builtin::BIlog2l: case Builtin::BI__builtin_log2: case Builtin::BI__builtin_log2f: + case Builtin::BI__builtin_log2f16: case Builtin::BI__builtin_log2l: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log2)); @@ -1684,6 +1698,7 @@ case Builtin::BIpowl: case Builtin::BI__builtin_pow: case Builtin::BI__builtin_powf: + case Builtin::BI__builtin_powf16: case Builtin::BI__builtin_powl: return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::pow)); @@ -1692,6 +1707,7 @@ case Builtin::BIrintl: case Builtin::BI__builtin_rint: case Builtin::BI__builtin_rintf: + case Builtin::BI__builtin_rintf16: case Builtin::BI__builtin_rintl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::rint)); @@ -1700,6 +1716,7 @@ case Builtin::BIroundl: case Builtin::BI__builtin_round: case Builtin::BI__builtin_roundf: + case Builtin::BI__builtin_roundf16: case Builtin::BI__builtin_roundl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::round)); @@ -1708,6 +1725,7 @@ case Builtin::BIsinl: case Builtin::BI__builtin_sin: case Builtin::BI__builtin_sinf: + case Builtin::BI__builtin_sinf16: case Builtin::BI__builtin_sinl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sin)); @@ -1716,6 +1734,7 @@ case Builtin::BIsqrtl: case Builtin::BI__builtin_sqrt: case Builtin::BI__builtin_sqrtf: + case Builtin::BI__builtin_sqrtf16: case Builtin::BI__builtin_sqrtl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sqrt)); @@ -1724,6 +1743,7 @@ case Builtin::BItruncl: case Builtin::BI__builtin_trunc: case Builtin::BI__builtin_truncf: + case Builtin::BI__builtin_truncf16: case Builtin::BI__builtin_truncl: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::trunc)); @@ -3979,6 +3999,7 @@ break; case Builtin::BI__builtin_canonicalize: case Builtin::BI__builtin_canonicalizef: + case Builtin::BI__builtin_canonicalizef16: case Builtin::BI__builtin_canonicalizel: return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::canonicalize)); 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); +}