From 221311e1e964d10b0289af187165be8096875f54 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 3 Feb 2023 16:15:40 -0500 Subject: [PATCH] agx: Handle constant-offset in address matching Match iadd(x, #y). The format shift will get constant-folded away and, if y is sufficiently small, the constant will be inlined by the AGX backend optimizer. This gets rid of piles of 64-bit arithmetic from lowering UBOs. It probably doesn't matter for perf since that's happening in preamble shaders but it *is* noisy. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_nir_lower_address.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/asahi/compiler/agx_nir_lower_address.c b/src/asahi/compiler/agx_nir_lower_address.c index 368046f4eea..197326b5137 100644 --- a/src/asahi/compiler/agx_nir_lower_address.c +++ b/src/asahi/compiler/agx_nir_lower_address.c @@ -37,6 +37,17 @@ match_address(nir_ssa_scalar base, int8_t format_shift) }; for (unsigned i = 0; i < ARRAY_SIZE(summands); ++i) { + /* We can add a small constant to the 64-bit base for free */ + if (nir_ssa_scalar_is_const(summands[i])) { + return (struct match){ + .base = summands[1 - i], + .offset = summands[i], + .shift = -format_shift, + .sign_extend = true, + }; + } + + /* Otherwise, we can only add an offset extended from 32-bits */ if (!nir_ssa_scalar_is_alu(summands[i])) continue;