From 61862b209e4e4e8f5006f4449a424023e891594a Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 18 Nov 2024 14:26:15 -0400 Subject: [PATCH] nir/opt_algebraic: optimize convert_uint_sat(ulong) I wrote this in my query copy shader, it didn't get the codegen I expected, so I investigated. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 1cd4be8b478..5d7bc2db014 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1976,6 +1976,12 @@ optimizations.extend([ (('u2f32', ('u2u64', 'a@32')), ('u2f32', a)), + # UINT32_MAX < a just checks the high half of a 64-bit value. This occurs + # when lowering convert_uint_sat(ulong). Although the replacement is more + # instructions, it replaces a 64-bit instruction with a 32-bit instruction + # and a move that will likely be coalesced. + (('ult', 0xffffffff, 'a@64'), ('ine', ('unpack_64_2x32_split_y', a), 0)), + # Redundant trip through 8-bit (('i2i16', ('u2u8', ('iand', 'a@16', 1))), ('iand', 'a@16', 1)), (('u2u16', ('u2u8', ('iand', 'a@16', 1))), ('iand', 'a@16', 1)),