From 79a8e8b5b26d98f4969a906172e3ce95d3726398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 24 Aug 2022 12:25:23 +0200 Subject: [PATCH] aco/optimizer: do can_eliminate_and_exec() optimization later MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will allow to optimize s_not(v_cmp()) safely. Totals from 1024 (0.76% of 134913) affected shaders: (GFX10.3) CodeSize: 5695424 -> 5701860 (+0.11%); split: -0.00%, +0.11% Scratch: 242688 -> 241664 (-0.42%) Instrs: 1040656 -> 1041635 (+0.09%); split: -0.00%, +0.09% Latency: 16842282 -> 16922790 (+0.48%); split: -0.06%, +0.54% InvThroughput: 4772728 -> 4810868 (+0.80%); split: -0.10%, +0.90% VClause: 20013 -> 20000 (-0.06%); split: -0.12%, +0.05% Copies: 115057 -> 114384 (-0.58%); split: -1.22%, +0.63% Branches: 34531 -> 34532 (+0.00%); split: -0.00%, +0.01% PreSGPRs: 46263 -> 46267 (+0.01%) Reviewed-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_optimizer.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 26357f44080..be19e592a21 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -1939,9 +1939,6 @@ label_instruction(opt_ctx& ctx, aco_ptr& instr) * s_and is unnecessary. */ ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp()); break; - } else if (can_eliminate_and_exec(ctx, instr->operands[0].getTemp(), instr->pass_flags)) { - ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp()); - break; } } FALLTHROUGH; @@ -4489,6 +4486,20 @@ select_instruction(opt_ctx& ctx, aco_ptr& instr) return; } + /* This optimization is done late in order to be able to apply otherwise + * unsafe optimizations such as the inverse comparison optimization. + */ + if (instr->opcode == aco_opcode::s_and_b32 || instr->opcode == aco_opcode::s_and_b64) { + if (instr->operands[0].isTemp() && fixed_to_exec(instr->operands[1]) && + ctx.uses[instr->operands[0].tempId()] == 1 && ctx.uses[instr->definitions[1].tempId()] == 0 && + can_eliminate_and_exec(ctx, instr->operands[0].getTemp(), instr->pass_flags)) { + ctx.uses[instr->operands[0].tempId()]--; + ctx.info[instr->operands[0].tempId()].instr->definitions[0].setTemp(instr->definitions[0].getTemp()); + instr.reset(); + return; + } + } + /* Combine DPP copies into VALU. This should be done after creating MAD/FMA. */ if (instr->isVALU()) { for (unsigned i = 0; i < instr->operands.size(); i++) {