aco/vn: remove dead instructions early

Dead p_create_vector/p_split_vector left behind by instruction selection slow down
the other passes and negatively affect extract labels in aco_optimizer.

Foz-DB GFX1201:
Totals from 964 (1.20% of 80251) affected shaders:
MaxWaves: 29206 -> 29030 (-0.60%); split: +0.08%, -0.68%
Instrs: 669369 -> 668842 (-0.08%); split: -0.16%, +0.09%
CodeSize: 3385192 -> 3383216 (-0.06%); split: -0.13%, +0.07%
VGPRs: 46788 -> 46848 (+0.13%); split: -0.85%, +0.97%
Latency: 3985660 -> 3892742 (-2.33%); split: -2.54%, +0.21%
InvThroughput: 538296 -> 536761 (-0.29%); split: -0.38%, +0.10%
VClause: 8336 -> 8418 (+0.98%); split: -0.17%, +1.15%
SClause: 17111 -> 17120 (+0.05%); split: -0.20%, +0.25%
Copies: 44393 -> 44239 (-0.35%); split: -1.25%, +0.91%
PreSGPRs: 45417 -> 45419 (+0.00%)
PreVGPRs: 30401 -> 31644 (+4.09%); split: -0.00%, +4.09%
VALU: 348282 -> 348167 (-0.03%); split: -0.15%, +0.12%
SALU: 121454 -> 121410 (-0.04%); split: -0.04%, +0.01%

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35825>
This commit is contained in:
Georg Lehmann 2025-07-07 13:19:33 +02:00 committed by Marge Bot
parent 82af226690
commit 9e8ba10447

View file

@ -239,6 +239,7 @@ struct vn_ctx {
monotonic_buffer_resource m;
expr_set expr_values;
aco::unordered_map<uint32_t, Temp> renames;
std::vector<uint16_t> uses;
/* The exec id should be the same on the same level of control flow depth.
* Together with the check for dominator relations, it is safe to assume
@ -254,6 +255,7 @@ struct vn_ctx {
for (Block& block : program->blocks)
size += block.instructions.size();
expr_values.reserve(size);
uses = dead_code_analysis(program);
}
};
@ -342,6 +344,10 @@ process_block(vn_ctx& ctx, Block& block)
new_instructions.reserve(block.instructions.size());
for (aco_ptr<Instruction>& instr : block.instructions) {
/* Clean up dead create_vector/split_vector left behind by instruction selection. */
if (is_dead(ctx.uses, instr.get()))
continue;
/* first, rename operands */
for (Operand& op : instr->operands) {
if (!op.isTemp())