Module: Mesa Branch: staging/23.1 Commit: 12849ec35bbc675aa4227b4d1504a7d3bfab7935 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=12849ec35bbc675aa4227b4d1504a7d3bfab7935
Author: Rhys Perry <[email protected]> Date: Tue Sep 26 19:29:37 2023 +0100 nir/lower_int64: fix find_lsb(0) If the high 32 bits were zero, this would be umin(find_lsb(lo), 31). This evaluates to 31 if lo is also zero, instead of -1. Signed-off-by: Rhys Perry <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Fixes: 9293d8e64bc7 ("nir: Add find_lsb lowering to nir_lower_int64.") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25409> (cherry picked from commit bcdac65ca3718b237abddc9f4714d4580c081e35) --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_int64.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 715e36f0023..905bb3fc294 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -823,7 +823,7 @@ "description": "nir/lower_int64: fix find_lsb(0)", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "9293d8e64bc72ac15c075b67f711fa2d986bcafb" }, diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c index c3e541e2228..87b9ef6eced 100644 --- a/src/compiler/nir/nir_lower_int64.c +++ b/src/compiler/nir/nir_lower_int64.c @@ -711,8 +711,11 @@ lower_find_lsb64(nir_builder *b, nir_ssa_def *x) /* Use umin so that -1 (no bits found) becomes larger (0xFFFFFFFF) * than any actual bit position, so we return a found bit instead. + * This is similar to the ufind_msb lowering. If you need this lowering + * without uadd_sat, add code like in lower_ufind_msb64. */ - return nir_umin(b, lo_lsb, nir_iadd(b, hi_lsb, nir_imm_int(b, 32))); + assert(!b->shader->options->lower_uadd_sat); + return nir_umin(b, lo_lsb, nir_uadd_sat(b, hi_lsb, nir_imm_int(b, 32))); } static nir_ssa_def *
