Mesa (main): nir/lower_int64: do not try to clamp floats to int-range

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 21 14:42:55 UTC 2022


Module: Mesa
Branch: main
Commit: 30aab0af07c5bcfab7f0341bba815162ee5f2049
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=30aab0af07c5bcfab7f0341bba815162ee5f2049

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Tue Apr 19 08:21:08 2022 +0200

nir/lower_int64: do not try to clamp floats to int-range

The clamping isn't correct, because the exact values ended up getting
rounded off a bit when converting back to floats.

But, converting floats to integers have undefined results when the
float value doesn't fit in the integer. So let's not try to clamp the
value here.

This was caught by digging at a Clang warning, see this thread for
details:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15547#note_1329769

Acked-by: Boris Brezillon <boris.brezillon at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16022>

---

 src/compiler/nir/nir_lower_int64.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c
index d5b161206bf..da393c807c6 100644
--- a/src/compiler/nir/nir_lower_int64.c
+++ b/src/compiler/nir/nir_lower_int64.c
@@ -759,16 +759,11 @@ lower_f2(nir_builder *b, nir_ssa_def *x, bool dst_is_signed)
 
    if (dst_is_signed)
       x_sign = nir_fsign(b, x);
-   else
-      x = nir_fmin(b, x, nir_imm_floatN_t(b, UINT64_MAX, x->bit_size));
 
    x = nir_ftrunc(b, x);
 
-   if (dst_is_signed) {
-      x = nir_fmin(b, x, nir_imm_floatN_t(b, INT64_MAX, x->bit_size));
-      x = nir_fmax(b, x, nir_imm_floatN_t(b, INT64_MIN, x->bit_size));
+   if (dst_is_signed)
       x = nir_fabs(b, x);
-   }
 
    nir_ssa_def *div = nir_imm_floatN_t(b, 1ULL << 32, x->bit_size);
    nir_ssa_def *res_hi = nir_f2u32(b, nir_fdiv(b, x, div));



More information about the mesa-commit mailing list