From ae6ad8977bc14b2afbeb7fdb248b968e37bcafc4 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 13 Jun 2025 11:08:47 +0100 Subject: [PATCH] nir/uub: improve iand with constant sources fossil-db (navi21): Totals from 9 (0.01% of 79653) affected shaders: Instrs: 11878 -> 11868 (-0.08%) CodeSize: 61572 -> 61508 (-0.10%) Latency: 44585 -> 44581 (-0.01%); split: -0.02%, +0.01% InvThroughput: 9697 -> 9660 (-0.38%) VALU: 8889 -> 8876 (-0.15%) SALU: 1339 -> 1342 (+0.22%) Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir_range_analysis.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_range_analysis.c b/src/compiler/nir/nir_range_analysis.c index 94859979276..089b8949609 100644 --- a/src/compiler/nir/nir_range_analysis.c +++ b/src/compiler/nir/nir_range_analysis.c @@ -1850,9 +1850,17 @@ get_alu_uub(struct analysis_state *state, struct uub_query q, uint32_t *result, case nir_op_umax: *result = src[0] > src[1] ? src[0] : src[1]; break; - case nir_op_iand: - *result = bitmask(util_last_bit64(src[0])) & bitmask(util_last_bit64(src[1])); + case nir_op_iand: { + nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0); + nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1); + if (nir_scalar_is_const(src0_scalar)) + *result = bitmask(util_last_bit64(src[1])) & nir_scalar_as_uint(src0_scalar); + else if (nir_scalar_is_const(src1_scalar)) + *result = bitmask(util_last_bit64(src[0])) & nir_scalar_as_uint(src1_scalar); + else + *result = bitmask(util_last_bit64(src[0])) & bitmask(util_last_bit64(src[1])); break; + } case nir_op_ior: case nir_op_ixor: *result = bitmask(util_last_bit64(src[0])) | bitmask(util_last_bit64(src[1]));