[libclc] 32c6a53 - libclc: Fix -cl-denorms-are-zero for rtp and rtn conversions (#188148)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 24 00:27:17 PDT 2026


Author: Matt Arsenault
Date: 2026-03-24T07:27:11Z
New Revision: 32c6a53b767850183208aff8b783e6bc08f21515

URL: https://github.com/llvm/llvm-project/commit/32c6a53b767850183208aff8b783e6bc08f21515
DIFF: https://github.com/llvm/llvm-project/commit/32c6a53b767850183208aff8b783e6bc08f21515.diff

LOG: libclc: Fix -cl-denorms-are-zero for rtp and rtn conversions (#188148)

Added: 
    

Modified: 
    libclc/clc/lib/generic/conversion/clc_convert_float.inc
    libclc/clc/lib/generic/conversion/clc_convert_float2float.cl

Removed: 
    


################################################################################
diff  --git a/libclc/clc/lib/generic/conversion/clc_convert_float.inc b/libclc/clc/lib/generic/conversion/clc_convert_float.inc
index 52244b2b68626..2e2d60d685576 100644
--- a/libclc/clc/lib/generic/conversion/clc_convert_float.inc
+++ b/libclc/clc/lib/generic/conversion/clc_convert_float.inc
@@ -120,6 +120,12 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_XCONCAT(__CLC_FUNCTION,
 #endif
   __CLC_GENTYPE sel =
       __clc_select(r, __clc_nextup(r), __CLC_CONVERT_S_GENTYPE(y < x));
+
+#ifndef __CLC_I2F
+  if (__CLC_GENTYPE_DENORMS_ARE_ZERO)
+    sel = __clc_select(sel, r, __CLC_CONVERT_S_GENTYPE(r == __CLC_FP_LIT(0.0)));
+#endif
+
 #if defined(__CLC_I2F) && (__CLC_FPSIZE == 16) && (__CLC_GENSIZE_SRC >= 16)
   half dst_min = -0x1.ffcp+15h;
   sel = __clc_max(sel, (__CLC_GENTYPE)dst_min);
@@ -141,6 +147,12 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_XCONCAT(__CLC_FUNCTION,
   c = c || __CLC_CONVERT_S_GENTYPE((__CLC_GENTYPE_SRC)__CLC_SRC_MAX == x);
 #endif
   __CLC_GENTYPE sel = __clc_select(r, __clc_nextdown(r), c);
+
+#ifndef __CLC_I2F
+  if (__CLC_GENTYPE_DENORMS_ARE_ZERO)
+    sel = __clc_select(sel, r, __CLC_CONVERT_S_GENTYPE(r == __CLC_FP_LIT(0.0)));
+#endif
+
 #if defined(__CLC_I2F) && (__CLC_FPSIZE == 16) && (__CLC_GENSIZE_SRC >= 16)
 #if defined(__CLC_GEN_S) && (__CLC_GENSIZE_SRC == 16)
   // short is 16 bits signed, so the maximum value rounded to negative infinity

diff  --git a/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl b/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl
index 5280e528ffd58..2993a190d8236 100644
--- a/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl
+++ b/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl
@@ -13,6 +13,7 @@
 #include "clc/math/clc_nextafter.h"
 #include "clc/math/clc_nextdown.h"
 #include "clc/math/clc_nextup.h"
+#include "clc/math/clc_subnormal_config.h"
 #include "clc/relational/clc_select.h"
 #include "clc/shared/clc_clamp.h"
 


        


More information about the cfe-commits mailing list