From a06f38e5aeff6833729a3b37b84e50cabb2b7bd7 Mon Sep 17 00:00:00 2001 From: Natalie Vock Date: Mon, 17 Feb 2025 18:42:49 +0100 Subject: [PATCH] aco/vn: Don't combine expressions across calls This increases live state across calls, which in turn increases spilling and makes for slower shaders overall. On top of RT function calls: Totals from 7 (0.01% of 81072) affected shaders: Instrs: 8980 -> 8955 (-0.28%); split: -0.88%, +0.60% CodeSize: 51976 -> 51684 (-0.56%); split: -1.02%, +0.46% SpillSGPRs: 248 -> 244 (-1.61%); split: -3.63%, +2.02% SpillVGPRs: 367 -> 365 (-0.54%); split: -1.09%, +0.54% Scratch: 32768 -> 31744 (-3.12%) Latency: 135669 -> 128720 (-5.12%); split: -5.13%, +0.01% InvThroughput: 35301 -> 34783 (-1.47%); split: -1.51%, +0.05% VClause: 241 -> 242 (+0.41%) SClause: 117 -> 120 (+2.56%) Copies: 1311 -> 1338 (+2.06%); split: -0.69%, +2.75% PreSGPRs: 899 -> 895 (-0.44%); split: -1.56%, +1.11% PreVGPRs: 1103 -> 1099 (-0.36%) VALU: 6143 -> 6098 (-0.73%); split: -1.22%, +0.49% SALU: 913 -> 933 (+2.19%); split: -0.11%, +2.30% VMEM: 989 -> 967 (-2.22%) SMEM: 201 -> 214 (+6.47%) Part-of: --- src/amd/compiler/aco_opt_value_numbering.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_opt_value_numbering.cpp b/src/amd/compiler/aco_opt_value_numbering.cpp index 9aed42974ca..df57a7c4619 100644 --- a/src/amd/compiler/aco_opt_value_numbering.cpp +++ b/src/amd/compiler/aco_opt_value_numbering.cpp @@ -226,7 +226,8 @@ struct InstrPred { case Format::EXP: case Format::SOPP: case Format::PSEUDO_BRANCH: - case Format::PSEUDO_BARRIER: UNREACHABLE("unsupported instruction format"); + case Format::PSEUDO_BARRIER: + case Format::PSEUDO_CALL: UNREACHABLE("unsupported instruction format"); default: return true; } } @@ -360,6 +361,14 @@ process_block(vn_ctx& ctx, Block& block) if (instr->opcode == aco_opcode::p_discard_if || instr->opcode == aco_opcode::p_demote_to_helper || instr->opcode == aco_opcode::p_end_wqm) ctx.exec_id++; + /* Clear all recorded values when encountering a call instruction to prevent replacing + * values across call instructions. The live state that can be kept in registers during + * function calls is typically very limited, so it's better to compute the same thing twice + * instead of increasing live ranges. This also disables value numbering of call instructions + * themselves, which is obviously invalid because callees can have side effects. + */ + if (instr->isCall()) + ctx.expr_values.clear(); /* simple copy-propagation through renaming */ bool copy_instr =