[libclc] libclc: Fix -cl-denorms-are-zero for rtp and rtn conversions (PR #188148)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 24 00:17:57 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/188148
>From c9818d0186e833251e518631424241b14534e412 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 23 Mar 2026 23:12:07 +0100
Subject: [PATCH] libclc: Fix -cl-denorms-are-zero for rtp and rtn conversions
---
.../clc/lib/generic/conversion/clc_convert_float.inc | 12 ++++++++++++
.../generic/conversion/clc_convert_float2float.cl | 1 +
2 files changed, 13 insertions(+)
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