aco: optimize branching sequence with p_create_vector exec producer

This happens with inverse_ballot and wave64.

Foz-DB Navi21:
Totals from 3 (0.00% of 79395) affected shaders:
Instrs: 2689 -> 2683 (-0.22%)
CodeSize: 14988 -> 14972 (-0.11%)
Latency: 20207 -> 20204 (-0.01%)
Copies: 144 -> 141 (-2.08%)
Branches: 76 -> 73 (-3.95%)
SALU: 241 -> 238 (-1.24%)

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29502>
This commit is contained in:
Georg Lehmann
2024-05-31 15:52:12 +02:00
committed by Marge Bot
parent 690f880d18
commit 818ff03865
+6 -3
View File
@@ -398,7 +398,8 @@ try_optimize_branching_sequence(ssa_elimination_ctx& ctx, Block& block, const in
*/
const bool can_reassign =
vopc || (exec_copy->opcode == aco_opcode::p_parallelcopy &&
(exec_val->isSALU() || exec_val->opcode == aco_opcode::p_parallelcopy));
(exec_val->isSALU() || exec_val->opcode == aco_opcode::p_parallelcopy ||
exec_val->opcode == aco_opcode::p_create_vector));
/* The reassignment is not worth it when both the original exec needs to be copied
* and the new exec copy can't be removed. In this case we'd end up with more instructions.
@@ -507,8 +508,10 @@ try_optimize_branching_sequence(ssa_elimination_ctx& ctx, Block& block, const in
exec_copy->operands[0] = Operand(exec, ctx.program->lane_mask);
}
if (exec_val->opcode == aco_opcode::p_parallelcopy && exec_val->operands[0].isConstant() &&
exec_val->operands[0].constantValue()) {
bool has_nonzero_op =
std::any_of(exec_val->operands.begin(), exec_val->operands.end(),
[](const Operand& op) -> bool { return op.isConstant() && op.constantValue(); });
if (exec_val->isPseudo() && has_nonzero_op) {
/* Remove the branch instruction when exec is constant non-zero. */
aco_ptr<Instruction>& branch = block.instructions.back();
if (branch->opcode == aco_opcode::p_cbranch_z && branch->operands[0].physReg() == exec)