aco/ra: iterate backwards when coalescing phis

Aligning the phi definition with the operand from
the else- block can reduce the number of branches
if the else- block is otherwise empty.

Totals from 16 (0.01% of 136546) affected shaders (Navi10:
CodeSize: 707848 -> 707312 (-0.08%); split: -0.09%, +0.01%
Instrs: 126534 -> 126400 (-0.11%); split: -0.13%, +0.02%
Latency: 6399306 -> 6395082 (-0.07%)
InvThroughput: 6134374 -> 6132119 (-0.04%); split: -0.04%, +0.00%
SClause: 1879 -> 1871 (-0.43%)
Copies: 36316 -> 36219 (-0.27%); split: -0.37%, +0.10%
Branches: 4154 -> 4127 (-0.65%); split: -0.67%, +0.02%

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9763>
This commit is contained in:
Daniel Schürmann 2021-03-22 14:57:26 +00:00 committed by Marge Bot
parent 7c64623e94
commit 4bfbd4de84

View file

@ -2134,7 +2134,9 @@ void register_allocation(Program *program, std::vector<IDSet>& live_out_per_bloc
if (!definition.isFixed()) {
std::vector<std::pair<Operand, Definition>> parallelcopy;
/* try to find a register that is used by at least one operand */
for (const Operand& op : phi->operands) {
for (int i = phi->operands.size() - 1; i >= 0; i--) {
/* by going backwards, we aim to avoid copies in else-blocks */
const Operand& op = phi->operands[i];
if (!(op.isTemp() && op.isFixed()))
continue;
PhysReg reg = op.physReg();