https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/164957
Previous implementation was cmp, select and @llvm.smax sequence in LLVM IR. >From 39fa5d234da4c1bdab76770a76636193ab25fbf6 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Fri, 24 Oct 2025 13:05:01 +0200 Subject: [PATCH] [libclc] Simplify integer __clc_abs implementation Previous implementation was cmp, select and @llvm.smax sequence in LLVM IR. --- libclc/clc/lib/generic/integer/clc_abs.inc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libclc/clc/lib/generic/integer/clc_abs.inc b/libclc/clc/lib/generic/integer/clc_abs.inc index 26ec0b24ffb96..222b14fbe7b28 100644 --- a/libclc/clc/lib/generic/integer/clc_abs.inc +++ b/libclc/clc/lib/generic/integer/clc_abs.inc @@ -6,7 +6,16 @@ // //===----------------------------------------------------------------------===// +#ifdef __CLC_GEN_S + +_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) { + return __builtin_astype(__builtin_elementwise_abs(x), __CLC_U_GENTYPE); +} + +#else + _CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) { - return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x), - __CLC_U_GENTYPE); + return x; } + +#endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
