[libclc] [libclc] Refine __clc_fp*_subnormals_supported and __clc_flush_denormal_if_not_supported (PR #157633)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 10 05:17:17 PDT 2025
================
@@ -66,13 +65,11 @@ bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void);
#define LOG_MAGIC_NUM_SP32 (1 + NUMEXPBITS_SP32 - EXPBIAS_SP32)
_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) {
- int ix = __clc_as_int(x);
- if (!__clc_fp32_subnormals_supported() && ((ix & EXPBITS_SP32) == 0) &&
- ((ix & MANTBITS_SP32) != 0)) {
- ix &= SIGNBIT_SP32;
- x = __clc_as_float(ix);
- }
- return x;
+ // Avoid calling __clc_fp32_subnormals_supported here: it uses
+ // llvm.canonicalize, which quiets sNaN.
+ return __builtin_fabsf(x) < 0x1p-149f
+ ? __builtin_elementwise_copysign(0.0f, x)
+ : x;
----------------
arsenm wrote:
There's no support check here. `__builtin_fabsf(x) < 0x1p-149f` will be true for 0 or a denormal value, regardless of whether the fcmp flushes the input
Also you can use __builtin_elementwise_abs to be consistently using elementwise builtins
https://github.com/llvm/llvm-project/pull/157633
More information about the cfe-commits
mailing list