https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/150181
Also delete unary_def_via_fp32.inc. There are small changes in amdgcn--amdhsa.bc due to vector conversion is scalarized, e.g. %2 = fpext <4 x half> %0 to <4 x float> %3 = extractelement <4 x float> %2, i64 0 %4 = tail call float @llvm.fabs.f32(float %3) -> %2 = extractelement <4 x half> %0, i64 0 %3 = tail call half @llvm.fabs.f16(half %2) %4 = fpext half %3 to float >From 4a64e39cb21fcde0858d4b8795e44d0ce146dbd3 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Wed, 23 Jul 2025 09:21:43 +0200 Subject: [PATCH] [libclc] Simplify unary_def_scalarize.inc's use in __clc_erf/erfc/tgamma Also delete unary_def_via_fp32.inc. There are small changes in amdgcn--amdhsa.bc due to vector conversion is scalarized, e.g. %2 = fpext <4 x half> %0 to <4 x float> %3 = extractelement <4 x float> %2, i64 0 %4 = tail call float @llvm.fabs.f32(float %3) -> %2 = extractelement <4 x half> %0, i64 0 %3 = tail call half @llvm.fabs.f16(half %2) %4 = fpext half %3 to float --- .../include/clc/math/unary_def_via_fp32.inc | 11 -------- libclc/clc/lib/generic/math/clc_erf.cl | 26 +++++-------------- libclc/clc/lib/generic/math/clc_erfc.cl | 24 +++++------------ libclc/clc/lib/generic/math/clc_tgamma.cl | 26 +++++-------------- 4 files changed, 21 insertions(+), 66 deletions(-) delete mode 100644 libclc/clc/include/clc/math/unary_def_via_fp32.inc diff --git a/libclc/clc/include/clc/math/unary_def_via_fp32.inc b/libclc/clc/include/clc/math/unary_def_via_fp32.inc deleted file mode 100644 index f109e8ec4a111..0000000000000 --- a/libclc/clc/include/clc/math/unary_def_via_fp32.inc +++ /dev/null @@ -1,11 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x) { - return __CLC_CONVERT_GENTYPE(FUNCTION(__CLC_CONVERT_FLOATN(x))); -} diff --git a/libclc/clc/lib/generic/math/clc_erf.cl b/libclc/clc/lib/generic/math/clc_erf.cl index 17fee3e8d11f8..bea392445c93c 100644 --- a/libclc/clc/lib/generic/math/clc_erf.cl +++ b/libclc/clc/lib/generic/math/clc_erf.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> #include <clc/math/clc_fabs.h> @@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erf(float x) { return ret; } -#define __FLOAT_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -500,24 +493,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erf(double y) { return y < 0.0 ? -ret : ret; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 -#include <clc/clc_convert.h> - #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_erf(half x) { + return (half)__clc_erf((float)x); +} #endif + +#define FUNCTION __clc_erf +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> diff --git a/libclc/clc/lib/generic/math/clc_erfc.cl b/libclc/clc/lib/generic/math/clc_erfc.cl index 77f8959831d27..fab6960046028 100644 --- a/libclc/clc/lib/generic/math/clc_erfc.cl +++ b/libclc/clc/lib/generic/math/clc_erfc.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> #include <clc/math/clc_fabs.h> @@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erfc(float x) { return ret; } -#define __FLOAT_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -509,12 +502,6 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) { return ret; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 @@ -524,9 +511,12 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) { #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_erfc(half x) { + return (half)__clc_erfc((float)x); +} #endif + +#define FUNCTION __clc_erfc +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> diff --git a/libclc/clc/lib/generic/math/clc_tgamma.cl b/libclc/clc/lib/generic/math/clc_tgamma.cl index e0fed98026ca5..83b09cc33ecc2 100644 --- a/libclc/clc/lib/generic/math/clc_tgamma.cl +++ b/libclc/clc/lib/generic/math/clc_tgamma.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/float/definitions.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> @@ -32,12 +31,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_tgamma(float x) { return g; } -#define __FLOAT_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -59,24 +52,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_tgamma(double x) { return g; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 -#include <clc/clc_convert.h> - #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_tgamma(half x) { + return (half)__clc_tgamma((float)x); +} #endif + +#define FUNCTION __clc_tgamma +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits