aco/vn: copy-propagate trivial phis

Totals from 154 (0.19% of 79395) affected shaders: (GFX11)

Instrs: 102420 -> 101702 (-0.70%); split: -0.71%, +0.01%
CodeSize: 534060 -> 530620 (-0.64%); split: -0.65%, +0.01%
Latency: 560180 -> 559723 (-0.08%); split: -0.10%, +0.01%
InvThroughput: 62769 -> 61708 (-1.69%); split: -1.72%, +0.03%
Copies: 6929 -> 6260 (-9.66%); split: -9.68%, +0.03%
Branches: 1636 -> 1609 (-1.65%)
PreVGPRs: 5913 -> 5906 (-0.12%)
VALU: 52681 -> 52012 (-1.27%); split: -1.27%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28661>
This commit is contained in:
Daniel Schürmann 2024-04-08 13:47:25 +02:00 committed by Marge Bot
parent 6e3446422f
commit 55130069b8

View file

@ -313,6 +313,21 @@ can_eliminate(aco_ptr<Instruction>& instr)
return true;
}
bool
is_trivial_phi(Block& block, Instruction* instr)
{
if (!is_phi(instr))
return false;
/* Logical LCSSA phis must be kept in order to prevent the optimizer
* from doing invalid transformations. */
if (instr->opcode == aco_opcode::p_phi && (block.kind & block_kind_loop_exit))
return false;
return std::all_of(instr->operands.begin(), instr->operands.end(),
[&](Operand& op) { return op == instr->operands[0]; });
}
void
process_block(vn_ctx& ctx, Block& block)
{
@ -333,14 +348,9 @@ process_block(vn_ctx& ctx, Block& block)
instr->opcode == aco_opcode::p_demote_to_helper || instr->opcode == aco_opcode::p_end_wqm)
ctx.exec_id++;
if (!can_eliminate(instr)) {
new_instructions.emplace_back(std::move(instr));
continue;
}
/* simple copy-propagation through renaming */
bool copy_instr =
instr->opcode == aco_opcode::p_parallelcopy ||
is_trivial_phi(block, instr.get()) || instr->opcode == aco_opcode::p_parallelcopy ||
(instr->opcode == aco_opcode::p_create_vector && instr->operands.size() == 1);
if (copy_instr && !instr->definitions[0].isFixed() && instr->operands[0].isTemp() &&
instr->operands[0].regClass() == instr->definitions[0].regClass()) {
@ -348,6 +358,11 @@ process_block(vn_ctx& ctx, Block& block)
continue;
}
if (!can_eliminate(instr)) {
new_instructions.emplace_back(std::move(instr));
continue;
}
instr->pass_flags = ctx.exec_id;
std::pair<expr_set::iterator, bool> res = ctx.expr_values.emplace(instr.get(), block.index);
@ -388,7 +403,7 @@ void
rename_phi_operands(Block& block, aco::unordered_map<uint32_t, Temp>& renames)
{
for (aco_ptr<Instruction>& phi : block.instructions) {
if (phi->opcode != aco_opcode::p_phi && phi->opcode != aco_opcode::p_linear_phi)
if (!is_phi(phi))
break;
for (Operand& op : phi->operands) {