From 4bcb62d203a986b12fc595f6d2d5e93766b7d56a Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 27 Aug 2023 17:38:02 -0400 Subject: [PATCH] nir/opt_sink: Also consider load_preamble as const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acts like constants, schedule them like constants. This lets us move lowered frag coord code down. Results on dolphin ubers: total instructions in shared programs: 195144 -> 196633 (0.76%) instructions in affected programs: 175737 -> 177226 (0.85%) helped: 28 HURT: 27 Instructions are HURT. total bytes in shared programs: 1379980 -> 1388308 (0.60%) bytes in affected programs: 1244250 -> 1252578 (0.67%) helped: 28 HURT: 27 Bytes are HURT. total halfregs in shared programs: 13591 -> 13557 (-0.25%) halfregs in affected programs: 2176 -> 2142 (-1.56%) helped: 12 HURT: 2 Inconclusive result (%-change mean confidence interval includes 0). total threads in shared programs: 233728 -> 234112 (0.16%) threads in affected programs: 3264 -> 3648 (11.76%) helped: 6 HURT: 0 Threads are helped. Results on Android shader-db: total instructions in shared programs: 1775324 -> 1775912 (0.03%) instructions in affected programs: 155305 -> 155893 (0.38%) helped: 353 HURT: 548 Instructions are HURT. total bytes in shared programs: 11676650 -> 11678454 (0.02%) bytes in affected programs: 1058924 -> 1060728 (0.17%) helped: 370 HURT: 547 Inconclusive result (value mean confidence interval includes 0). total halfregs in shared programs: 484143 -> 471212 (-2.67%) halfregs in affected programs: 98833 -> 85902 (-13.08%) helped: 2478 HURT: 674 Halfregs are helped. Instr count changes due to losing the RA lottery. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_sink.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_opt_sink.c b/src/compiler/nir/nir_opt_sink.c index 4bfb59c2f19..185ea123202 100644 --- a/src/compiler/nir/nir_opt_sink.c +++ b/src/compiler/nir/nir_opt_sink.c @@ -35,6 +35,26 @@ * anscestor of consuming instructions. */ +/* + * Detect whether a source is like a constant for the purposes of register + * pressure calculations (e.g. can be remat anywhere effectively for free). + */ +static bool +is_constant_like(nir_src *src) +{ + /* Constants are constants */ + if (nir_src_is_const(*src)) + return true; + + /* Otherwise, look for constant-like intrinsics */ + nir_instr *parent = src->ssa->parent_instr; + if (parent->type != nir_instr_type_intrinsic) + return false; + + return (nir_instr_as_intrinsic(parent)->intrinsic == + nir_intrinsic_load_preamble); +} + bool nir_can_move_instr(nir_instr *instr, nir_move_options options) { @@ -70,7 +90,7 @@ nir_can_move_instr(nir_instr *instr, nir_move_options options) unsigned constant_inputs = 0; for (unsigned i = 0; i < inputs; ++i) { - if (nir_src_is_const(alu->src[i].src)) + if (is_constant_like(&alu->src[i].src)) constant_inputs++; }