2019-09-17 13:22:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2019 Valve Corporation
|
|
|
|
|
*
|
2024-04-08 09:02:30 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2019-09-17 13:22:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "aco_builder.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
#include "aco_ir.h"
|
2021-06-09 10:14:54 +02:00
|
|
|
|
2021-06-09 15:40:03 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
namespace aco {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
enum WQMState : uint8_t {
|
|
|
|
|
Unspecified = 0,
|
2024-10-04 10:09:08 +02:00
|
|
|
Exact,
|
|
|
|
|
WQM, /* with control flow applied */
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum mask_type : uint8_t {
|
|
|
|
|
mask_type_global = 1 << 0,
|
|
|
|
|
mask_type_exact = 1 << 1,
|
|
|
|
|
mask_type_wqm = 1 << 2,
|
|
|
|
|
mask_type_loop = 1 << 3, /* active lanes of a loop */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct loop_info {
|
|
|
|
|
Block* loop_header;
|
|
|
|
|
uint16_t num_exec_masks;
|
|
|
|
|
bool has_divergent_break;
|
|
|
|
|
bool has_divergent_continue;
|
2019-09-26 10:33:43 +01:00
|
|
|
bool has_discard; /* has a discard or demote */
|
2022-02-07 18:56:11 +01:00
|
|
|
loop_info(Block* b, uint16_t num, bool breaks, bool cont, bool discard)
|
|
|
|
|
: loop_header(b), num_exec_masks(num), has_divergent_break(breaks),
|
2019-09-17 13:22:17 +02:00
|
|
|
has_divergent_continue(cont), has_discard(discard)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-04 10:27:35 +02:00
|
|
|
struct exec_info {
|
2024-10-08 19:46:22 +02:00
|
|
|
Operand op; /* Either a temporary, exec or const -1. */
|
2024-10-04 10:27:35 +02:00
|
|
|
uint8_t type; /* enum mask_type */
|
|
|
|
|
exec_info() = default;
|
|
|
|
|
exec_info(const Operand& op_, const uint8_t& type_) : op(op_), type(type_) {}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
struct block_info {
|
2024-10-04 10:27:35 +02:00
|
|
|
std::vector<exec_info> exec;
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct exec_ctx {
|
|
|
|
|
Program* program;
|
|
|
|
|
std::vector<block_info> info;
|
|
|
|
|
std::vector<loop_info> loop;
|
|
|
|
|
bool handle_wqm = false;
|
aco/insert_exec: only restore wqm mask after control flow if necessary
The next commit will make this not free, so we should avoid it if possible.
Foz-DB Navi31:
Totals from 3933 (4.93% of 79789) affected shaders:
Instrs: 5726914 -> 5727295 (+0.01%); split: -0.00%, +0.01%
CodeSize: 31307100 -> 31308884 (+0.01%); split: -0.00%, +0.01%
SpillSGPRs: 1797 -> 1793 (-0.22%); split: -0.33%, +0.11%
Latency: 58973929 -> 58974343 (+0.00%); split: -0.00%, +0.00%
InvThroughput: 8591893 -> 8591911 (+0.00%); split: -0.00%, +0.00%
SClause: 209074 -> 209115 (+0.02%); split: -0.00%, +0.02%
Copies: 423965 -> 432420 (+1.99%)
Branches: 149976 -> 149979 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 200175 -> 200663 (+0.24%)
VALU: 3440165 -> 3440156 (-0.00%); split: -0.00%, +0.00%
SALU: 555727 -> 556143 (+0.07%); split: -0.00%, +0.08%
Fixes: b872ff6ef28 ("aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF")
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34659>
2025-04-22 19:42:02 +02:00
|
|
|
bool had_demote_in_cf = false;
|
2025-07-06 20:38:00 +02:00
|
|
|
Temp local_exact_mask;
|
2020-11-03 14:40:05 +01:00
|
|
|
exec_ctx(Program* program_) : program(program_), info(program->blocks.size()) {}
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
transition_to_WQM(exec_ctx& ctx, Builder bld, unsigned idx)
|
|
|
|
|
{
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[idx].exec.back().type & mask_type_wqm)
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[idx].exec.back().type & mask_type_global) {
|
|
|
|
|
Operand exec_mask = ctx.info[idx].exec.back().op;
|
2024-10-08 19:46:22 +02:00
|
|
|
if (exec_mask == Operand(exec, bld.lm))
|
|
|
|
|
ctx.info[idx].exec.back().op = bld.copy(bld.def(bld.lm), exec_mask);
|
2021-02-15 11:24:22 +00:00
|
|
|
|
2024-10-08 19:46:22 +02:00
|
|
|
bld.sop1(Builder::s_wqm, Definition(exec, bld.lm), bld.def(s1, scc), exec_mask);
|
|
|
|
|
ctx.info[idx].exec.emplace_back(Operand(exec, bld.lm), mask_type_global | mask_type_wqm);
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* otherwise, the WQM mask should be one below the current mask */
|
|
|
|
|
ctx.info[idx].exec.pop_back();
|
2024-10-04 10:27:35 +02:00
|
|
|
assert(ctx.info[idx].exec.back().type & mask_type_wqm);
|
|
|
|
|
assert(ctx.info[idx].exec.back().op.size() == bld.lm.size());
|
|
|
|
|
assert(ctx.info[idx].exec.back().op.isTemp());
|
2024-10-08 19:46:22 +02:00
|
|
|
bld.copy(Definition(exec, bld.lm), ctx.info[idx].exec.back().op);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
transition_to_Exact(exec_ctx& ctx, Builder bld, unsigned idx)
|
|
|
|
|
{
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[idx].exec.back().type & mask_type_exact)
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
2019-09-26 15:38:09 +01:00
|
|
|
/* We can't remove the loop exec mask, because that can cause exec.size() to
|
|
|
|
|
* be less than num_exec_masks. The loop exec mask also needs to be kept
|
|
|
|
|
* around for various uses. */
|
2024-10-04 10:27:35 +02:00
|
|
|
if ((ctx.info[idx].exec.back().type & mask_type_global) &&
|
|
|
|
|
!(ctx.info[idx].exec.back().type & mask_type_loop)) {
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[idx].exec.pop_back();
|
2024-10-04 10:27:35 +02:00
|
|
|
assert(ctx.info[idx].exec.back().type & mask_type_exact);
|
|
|
|
|
assert(ctx.info[idx].exec.back().op.size() == bld.lm.size());
|
|
|
|
|
assert(ctx.info[idx].exec.back().op.isTemp());
|
2024-10-08 19:46:22 +02:00
|
|
|
bld.copy(Definition(exec, bld.lm), ctx.info[idx].exec.back().op);
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* otherwise, we create an exact mask and push to the stack */
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand wqm = ctx.info[idx].exec.back().op;
|
2024-10-08 19:46:22 +02:00
|
|
|
if (wqm == Operand(exec, bld.lm)) {
|
2021-02-15 11:24:22 +00:00
|
|
|
wqm = bld.sop1(Builder::s_and_saveexec, bld.def(bld.lm), bld.def(s1, scc),
|
2024-10-04 10:27:35 +02:00
|
|
|
Definition(exec, bld.lm), ctx.info[idx].exec[0].op, Operand(exec, bld.lm));
|
2021-02-15 11:24:22 +00:00
|
|
|
} else {
|
2024-10-04 10:27:35 +02:00
|
|
|
bld.sop2(Builder::s_and, Definition(exec, bld.lm), bld.def(s1, scc), ctx.info[idx].exec[0].op,
|
|
|
|
|
wqm);
|
2021-02-15 11:24:22 +00:00
|
|
|
}
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec.back().op = Operand(wqm);
|
2024-10-08 19:46:22 +02:00
|
|
|
ctx.info[idx].exec.emplace_back(Operand(exec, bld.lm), mask_type_exact);
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
unsigned
|
|
|
|
|
add_coupling_code(exec_ctx& ctx, Block* block, std::vector<aco_ptr<Instruction>>& instructions)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx = block->index;
|
|
|
|
|
Builder bld(ctx.program, &instructions);
|
2023-12-18 11:21:08 +01:00
|
|
|
Block::edge_vec& preds = block->linear_preds;
|
2024-01-08 15:12:17 +01:00
|
|
|
bool restore_exec = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2025-07-06 20:38:00 +02:00
|
|
|
ctx.local_exact_mask = Temp();
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* start block */
|
2023-01-19 17:36:06 +01:00
|
|
|
if (preds.empty()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
aco_ptr<Instruction>& startpgm = block->instructions[0];
|
|
|
|
|
assert(startpgm->opcode == aco_opcode::p_startpgm);
|
|
|
|
|
bld.insert(std::move(startpgm));
|
|
|
|
|
|
2022-05-19 14:12:08 +01:00
|
|
|
unsigned count = 1;
|
2024-07-19 13:23:29 +01:00
|
|
|
while (block->instructions[count]->opcode == aco_opcode::p_init_scratch ||
|
|
|
|
|
block->instructions[count]->opcode == aco_opcode::s_setprio) {
|
|
|
|
|
bld.insert(std::move(block->instructions[count]));
|
2022-05-19 14:12:08 +01:00
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 19:46:22 +02:00
|
|
|
Operand start_exec(exec, bld.lm);
|
2021-05-07 15:02:58 +02:00
|
|
|
|
2019-10-14 17:46:02 +01:00
|
|
|
/* exec seems to need to be manually initialized with combined shaders */
|
2023-05-13 17:55:54 +02:00
|
|
|
if (ctx.program->stage.num_sw_stages() > 1 ||
|
2023-08-21 15:50:23 +02:00
|
|
|
ctx.program->stage.hw == AC_HW_NEXT_GEN_GEOMETRY_SHADER ||
|
2023-08-24 09:41:55 +02:00
|
|
|
(ctx.program->stage.sw == SWStage::VS &&
|
|
|
|
|
(ctx.program->stage.hw == AC_HW_HULL_SHADER ||
|
|
|
|
|
ctx.program->stage.hw == AC_HW_LEGACY_GEOMETRY_SHADER)) ||
|
|
|
|
|
(ctx.program->stage.sw == SWStage::TES &&
|
|
|
|
|
ctx.program->stage.hw == AC_HW_LEGACY_GEOMETRY_SHADER)) {
|
2021-07-13 11:22:46 +02:00
|
|
|
start_exec = Operand::c32_or_c64(-1u, bld.lm == s2);
|
2021-05-07 15:02:58 +02:00
|
|
|
bld.copy(Definition(exec, bld.lm), start_exec);
|
2019-10-14 17:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
aco: Enable constant exec mask based optimization on compute shaders.
We know for sure exec is initially -1 when the shader always has full subgroups.
Fossil DB stats on GFX11:
Totals from 3884 (2.88% of 134913) affected shaders:
SpillSGPRs: 1673 -> 1697 (+1.43%); split: -1.67%, +3.11%
SpillVGPRs: 2316 -> 2310 (-0.26%); split: -0.65%, +0.39%
CodeSize: 19584436 -> 19567156 (-0.09%); split: -0.13%, +0.04%
Scratch: 217088 -> 216832 (-0.12%)
Instrs: 3784596 -> 3780303 (-0.11%); split: -0.15%, +0.03%
Latency: 39971204 -> 39794967 (-0.44%); split: -0.47%, +0.03%
InvThroughput: 7885552 -> 7801247 (-1.07%); split: -1.14%, +0.07%
VClause: 74654 -> 74611 (-0.06%); split: -0.07%, +0.01%
SClause: 103139 -> 103043 (-0.09%); split: -0.13%, +0.04%
Copies: 279864 -> 281995 (+0.76%); split: -0.72%, +1.48%
Branches: 92082 -> 92084 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 155637 -> 149491 (-3.95%)
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20670>
2023-01-10 19:15:25 +01:00
|
|
|
/* EXEC is automatically initialized by the HW for compute shaders.
|
|
|
|
|
* We know for sure exec is initially -1 when the shader always has full subgroups.
|
|
|
|
|
*/
|
|
|
|
|
if (ctx.program->stage == compute_cs && ctx.program->info.cs.uses_full_subgroups)
|
|
|
|
|
start_exec = Operand::c32_or_c64(-1u, bld.lm == s2);
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
if (ctx.handle_wqm) {
|
2023-01-19 17:36:06 +01:00
|
|
|
ctx.info[idx].exec.emplace_back(start_exec, mask_type_global | mask_type_exact);
|
2023-09-03 11:05:08 +02:00
|
|
|
/* Initialize WQM already */
|
|
|
|
|
transition_to_WQM(ctx, bld, idx);
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
uint8_t mask = mask_type_global;
|
|
|
|
|
if (ctx.program->needs_wqm) {
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
bld.sop1(Builder::s_wqm, Definition(exec, bld.lm), bld.def(s1, scc),
|
|
|
|
|
Operand(exec, bld.lm));
|
2019-09-17 13:22:17 +02:00
|
|
|
mask |= mask_type_wqm;
|
|
|
|
|
} else {
|
|
|
|
|
mask |= mask_type_exact;
|
|
|
|
|
}
|
2023-01-19 17:36:06 +01:00
|
|
|
ctx.info[idx].exec.emplace_back(start_exec, mask);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 14:12:08 +01:00
|
|
|
return count;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* loop entry block */
|
|
|
|
|
if (block->kind & block_kind_loop_header) {
|
|
|
|
|
assert(preds[0] == idx - 1);
|
|
|
|
|
ctx.info[idx].exec = ctx.info[idx - 1].exec;
|
|
|
|
|
loop_info& info = ctx.loop.back();
|
2024-01-06 12:59:51 +01:00
|
|
|
assert(ctx.info[idx].exec.size() == info.num_exec_masks);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2025-02-18 12:24:22 +01:00
|
|
|
/* Create phi for global exact mask in case of demote. */
|
|
|
|
|
if (info.has_discard && preds.size() > 1 && info.num_exec_masks > 1) {
|
|
|
|
|
aco_ptr<Instruction> phi(
|
|
|
|
|
create_instruction(aco_opcode::p_linear_phi, Format::PSEUDO, preds.size(), 1));
|
|
|
|
|
phi->definitions[0] = bld.def(bld.lm);
|
|
|
|
|
phi->operands[0] = ctx.info[preds[0]].exec[0].op;
|
|
|
|
|
ctx.info[idx].exec[0].op = bld.insert(std::move(phi));
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec.back().type |= mask_type_loop;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
if (info.has_divergent_continue) {
|
2024-01-06 16:46:54 +01:00
|
|
|
/* create ssa name for loop active mask */
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> phi{
|
|
|
|
|
create_instruction(aco_opcode::p_linear_phi, Format::PSEUDO, preds.size(), 1)};
|
2024-01-06 16:46:54 +01:00
|
|
|
phi->definitions[0] = bld.def(bld.lm);
|
2024-10-08 19:46:22 +02:00
|
|
|
phi->operands[0] = ctx.info[preds[0]].exec.back().op;
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec.back().op = bld.insert(std::move(phi));
|
2024-01-06 16:46:54 +01:00
|
|
|
|
2024-01-08 15:12:17 +01:00
|
|
|
restore_exec = true;
|
2024-10-04 10:27:35 +02:00
|
|
|
uint8_t mask_type = ctx.info[idx].exec.back().type & (mask_type_wqm | mask_type_exact);
|
|
|
|
|
ctx.info[idx].exec.emplace_back(ctx.info[idx].exec.back().op, mask_type);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-08 15:12:17 +01:00
|
|
|
} else if (block->kind & block_kind_loop_exit) {
|
2019-09-17 13:22:17 +02:00
|
|
|
Block* header = ctx.loop.back().loop_header;
|
|
|
|
|
loop_info& info = ctx.loop.back();
|
|
|
|
|
|
|
|
|
|
for (ASSERTED unsigned pred : preds)
|
|
|
|
|
assert(ctx.info[pred].exec.size() >= info.num_exec_masks);
|
|
|
|
|
|
|
|
|
|
/* fill the loop header phis */
|
2023-12-18 11:21:08 +01:00
|
|
|
Block::edge_vec& header_preds = header->linear_preds;
|
2020-11-03 14:40:05 +01:00
|
|
|
int instr_idx = 0;
|
2025-02-18 12:24:22 +01:00
|
|
|
if (info.has_discard && header_preds.size() > 1 && info.num_exec_masks > 1) {
|
|
|
|
|
aco_ptr<Instruction>& phi = header->instructions[instr_idx++];
|
|
|
|
|
assert(phi->opcode == aco_opcode::p_linear_phi);
|
|
|
|
|
for (unsigned i = 1; i < phi->operands.size(); i++)
|
|
|
|
|
phi->operands[i] = ctx.info[header_preds[i]].exec[0].op;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2020-11-03 14:40:05 +01:00
|
|
|
|
2024-01-06 16:46:54 +01:00
|
|
|
if (info.has_divergent_continue) {
|
2020-11-03 14:40:05 +01:00
|
|
|
aco_ptr<Instruction>& phi = header->instructions[instr_idx++];
|
|
|
|
|
assert(phi->opcode == aco_opcode::p_linear_phi);
|
|
|
|
|
for (unsigned i = 1; i < phi->operands.size(); i++)
|
2024-10-08 19:46:22 +02:00
|
|
|
phi->operands[i] = ctx.info[header_preds[i]].exec[info.num_exec_masks - 1].op;
|
2024-06-18 14:15:04 +01:00
|
|
|
restore_exec = true;
|
2020-11-03 14:40:05 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
if (info.has_divergent_break) {
|
2024-01-08 15:12:17 +01:00
|
|
|
restore_exec = true;
|
2024-01-06 12:59:51 +01:00
|
|
|
/* Drop the loop active mask. */
|
|
|
|
|
info.num_exec_masks--;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
assert(!(block->kind & block_kind_top_level) || info.num_exec_masks <= 2);
|
|
|
|
|
|
|
|
|
|
/* create the loop exit phis if not trivial */
|
2020-11-03 14:40:05 +01:00
|
|
|
for (unsigned exec_idx = 0; exec_idx < info.num_exec_masks; exec_idx++) {
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand same = ctx.info[preds[0]].exec[exec_idx].op;
|
|
|
|
|
uint8_t type = ctx.info[header_preds[0]].exec[exec_idx].type;
|
2019-09-17 13:22:17 +02:00
|
|
|
bool trivial = true;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 1; i < preds.size() && trivial; i++) {
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[preds[i]].exec[exec_idx].op != same)
|
2019-09-17 13:22:17 +02:00
|
|
|
trivial = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trivial) {
|
|
|
|
|
ctx.info[idx].exec.emplace_back(same, type);
|
|
|
|
|
} else {
|
|
|
|
|
/* create phi for loop footer */
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> phi{
|
|
|
|
|
create_instruction(aco_opcode::p_linear_phi, Format::PSEUDO, preds.size(), 1)};
|
2019-11-27 11:04:47 +01:00
|
|
|
phi->definitions[0] = bld.def(bld.lm);
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++)
|
2024-10-08 19:46:22 +02:00
|
|
|
phi->operands[i] = ctx.info[preds[i]].exec[exec_idx].op;
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[idx].exec.emplace_back(bld.insert(std::move(phi)), type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 18:56:11 +01:00
|
|
|
assert(ctx.info[idx].exec.size() == info.num_exec_masks);
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.loop.pop_back();
|
|
|
|
|
|
2022-02-07 18:56:11 +01:00
|
|
|
} else if (preds.size() == 1) {
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[idx].exec = ctx.info[preds[0]].exec;
|
2025-02-13 09:16:05 +01:00
|
|
|
|
|
|
|
|
/* After continue and break blocks, we implicitly set exec to zero.
|
|
|
|
|
* This is so that parallelcopies can be inserted before the branch
|
|
|
|
|
* without being affected by the changed exec mask.
|
|
|
|
|
*/
|
|
|
|
|
if (ctx.info[idx].exec.back().op.constantEquals(0)) {
|
|
|
|
|
assert(block->logical_succs.empty());
|
|
|
|
|
/* Check whether the successor block already restores exec. */
|
|
|
|
|
uint16_t block_kind = ctx.program->blocks[block->linear_succs[0]].kind;
|
|
|
|
|
if (!(block_kind & (block_kind_loop_header | block_kind_loop_exit | block_kind_invert |
|
|
|
|
|
block_kind_merge))) {
|
|
|
|
|
/* The successor does not restore exec. */
|
|
|
|
|
restore_exec = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
assert(preds.size() == 2);
|
2024-10-08 21:34:17 +02:00
|
|
|
assert(ctx.info[preds[0]].exec.size() == ctx.info[preds[1]].exec.size());
|
2020-12-11 17:44:19 +01:00
|
|
|
|
2024-10-08 21:34:17 +02:00
|
|
|
unsigned last = ctx.info[preds[0]].exec.size() - 1;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-10-08 21:34:17 +02:00
|
|
|
/* create phis for diverged temporary exec masks */
|
|
|
|
|
for (unsigned i = 0; i < last; i++) {
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
/* skip trivial phis */
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[preds[0]].exec[i].op == ctx.info[preds[1]].exec[i].op) {
|
2024-10-08 19:46:22 +02:00
|
|
|
Operand op = ctx.info[preds[0]].exec[i].op;
|
2021-02-15 11:31:13 +01:00
|
|
|
/* discard/demote can change the state of the current exec mask */
|
2024-10-08 19:46:22 +02:00
|
|
|
assert(!op.isTemp() ||
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[preds[0]].exec[i].type == ctx.info[preds[1]].exec[i].type);
|
|
|
|
|
uint8_t mask = ctx.info[preds[0]].exec[i].type & ctx.info[preds[1]].exec[i].type;
|
2024-10-08 19:46:22 +02:00
|
|
|
ctx.info[idx].exec.emplace_back(op, mask);
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand phi = bld.pseudo(aco_opcode::p_linear_phi, bld.def(bld.lm),
|
2024-10-08 19:46:22 +02:00
|
|
|
ctx.info[preds[0]].exec[i].op, ctx.info[preds[1]].exec[i].op);
|
2024-10-04 10:27:35 +02:00
|
|
|
uint8_t mask_type = ctx.info[preds[0]].exec[i].type & ctx.info[preds[1]].exec[i].type;
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[idx].exec.emplace_back(phi, mask_type);
|
|
|
|
|
}
|
2024-10-08 21:34:17 +02:00
|
|
|
|
|
|
|
|
if (block->kind & block_kind_merge) {
|
|
|
|
|
restore_exec = true;
|
|
|
|
|
} else {
|
|
|
|
|
/* The last mask is already in exec. */
|
|
|
|
|
Operand current_exec = Operand(exec, bld.lm);
|
|
|
|
|
if (ctx.info[preds[0]].exec[last].op == ctx.info[preds[1]].exec[last].op) {
|
|
|
|
|
current_exec = ctx.info[preds[0]].exec[last].op;
|
|
|
|
|
}
|
|
|
|
|
uint8_t mask_type =
|
|
|
|
|
ctx.info[preds[0]].exec[last].type & ctx.info[preds[1]].exec[last].type;
|
|
|
|
|
ctx.info[idx].exec.emplace_back(current_exec, mask_type);
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
while (block->instructions[i]->opcode == aco_opcode::p_phi ||
|
|
|
|
|
block->instructions[i]->opcode == aco_opcode::p_linear_phi) {
|
|
|
|
|
bld.insert(std::move(block->instructions[i]));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ctx.handle_wqm) {
|
2025-04-23 10:43:31 +02:00
|
|
|
if (ctx.info[idx].exec.size() == 2) {
|
aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF
Totals from 4740 (5.97% of 79377) affected shaders: (Navi31)
Instrs: 6273963 -> 6273410 (-0.01%); split: -0.01%, +0.00%
CodeSize: 34306560 -> 34304284 (-0.01%); split: -0.01%, +0.00%
SpillSGPRs: 1793 -> 1797 (+0.22%); split: -0.11%, +0.33%
Latency: 62599300 -> 62598714 (-0.00%); split: -0.00%, +0.00%
InvThroughput: 9117199 -> 9117189 (-0.00%); split: -0.00%, +0.00%
SClause: 223548 -> 223529 (-0.01%); split: -0.02%, +0.01%
Copies: 464248 -> 454711 (-2.05%); split: -2.06%, +0.00%
Branches: 161446 -> 161443 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 226278 -> 225608 (-0.30%)
VALU: 3793235 -> 3793244 (+0.00%); split: -0.00%, +0.00%
SALU: 606184 -> 605759 (-0.07%); split: -0.08%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33619>
2025-02-18 10:31:04 +01:00
|
|
|
/* End WQM handling if not needed anymore */
|
2023-09-03 11:05:08 +02:00
|
|
|
if (block->instructions[i]->opcode == aco_opcode::p_end_wqm) {
|
2025-04-23 10:43:31 +02:00
|
|
|
assert(block->kind & block_kind_top_level);
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec.back().type |= mask_type_global;
|
2019-09-17 13:22:17 +02:00
|
|
|
transition_to_Exact(ctx, bld, idx);
|
|
|
|
|
ctx.handle_wqm = false;
|
2024-01-08 15:12:17 +01:00
|
|
|
restore_exec = false;
|
2023-09-03 11:05:08 +02:00
|
|
|
i++;
|
aco/insert_exec: only restore wqm mask after control flow if necessary
The next commit will make this not free, so we should avoid it if possible.
Foz-DB Navi31:
Totals from 3933 (4.93% of 79789) affected shaders:
Instrs: 5726914 -> 5727295 (+0.01%); split: -0.00%, +0.01%
CodeSize: 31307100 -> 31308884 (+0.01%); split: -0.00%, +0.01%
SpillSGPRs: 1797 -> 1793 (-0.22%); split: -0.33%, +0.11%
Latency: 58973929 -> 58974343 (+0.00%); split: -0.00%, +0.00%
InvThroughput: 8591893 -> 8591911 (+0.00%); split: -0.00%, +0.00%
SClause: 209074 -> 209115 (+0.02%); split: -0.00%, +0.02%
Copies: 423965 -> 432420 (+1.99%)
Branches: 149976 -> 149979 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 200175 -> 200663 (+0.24%)
VALU: 3440165 -> 3440156 (-0.00%); split: -0.00%, +0.00%
SALU: 555727 -> 556143 (+0.07%); split: -0.00%, +0.08%
Fixes: b872ff6ef28 ("aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF")
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34659>
2025-04-22 19:42:02 +02:00
|
|
|
} else if (restore_exec && ctx.info[idx].exec[1].type & mask_type_global &&
|
|
|
|
|
ctx.had_demote_in_cf) {
|
|
|
|
|
/* Use s_wqm to restore exec after demote in divergent CF in order to disable dead
|
|
|
|
|
* quads.
|
|
|
|
|
*/
|
aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF
Totals from 4740 (5.97% of 79377) affected shaders: (Navi31)
Instrs: 6273963 -> 6273410 (-0.01%); split: -0.01%, +0.00%
CodeSize: 34306560 -> 34304284 (-0.01%); split: -0.01%, +0.00%
SpillSGPRs: 1793 -> 1797 (+0.22%); split: -0.11%, +0.33%
Latency: 62599300 -> 62598714 (-0.00%); split: -0.00%, +0.00%
InvThroughput: 9117199 -> 9117189 (-0.00%); split: -0.00%, +0.00%
SClause: 223548 -> 223529 (-0.01%); split: -0.02%, +0.01%
Copies: 464248 -> 454711 (-2.05%); split: -2.06%, +0.00%
Branches: 161446 -> 161443 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 226278 -> 225608 (-0.30%)
VALU: 3793235 -> 3793244 (+0.00%); split: -0.00%, +0.00%
SALU: 606184 -> 605759 (-0.07%); split: -0.08%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33619>
2025-02-18 10:31:04 +01:00
|
|
|
bld.sop1(Builder::s_wqm, Definition(exec, bld.lm), bld.def(s1, scc),
|
|
|
|
|
ctx.info[idx].exec[0].op);
|
2025-04-22 19:34:12 +02:00
|
|
|
ctx.info[idx].exec[1].op = Operand(exec, bld.lm);
|
aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF
Totals from 4740 (5.97% of 79377) affected shaders: (Navi31)
Instrs: 6273963 -> 6273410 (-0.01%); split: -0.01%, +0.00%
CodeSize: 34306560 -> 34304284 (-0.01%); split: -0.01%, +0.00%
SpillSGPRs: 1793 -> 1797 (+0.22%); split: -0.11%, +0.33%
Latency: 62599300 -> 62598714 (-0.00%); split: -0.00%, +0.00%
InvThroughput: 9117199 -> 9117189 (-0.00%); split: -0.00%, +0.00%
SClause: 223548 -> 223529 (-0.01%); split: -0.02%, +0.01%
Copies: 464248 -> 454711 (-2.05%); split: -2.06%, +0.00%
Branches: 161446 -> 161443 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 226278 -> 225608 (-0.30%)
VALU: 3793235 -> 3793244 (+0.00%); split: -0.00%, +0.00%
SALU: 606184 -> 605759 (-0.07%); split: -0.08%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33619>
2025-02-18 10:31:04 +01:00
|
|
|
restore_exec = false;
|
aco/insert_exec: only restore wqm mask after control flow if necessary
The next commit will make this not free, so we should avoid it if possible.
Foz-DB Navi31:
Totals from 3933 (4.93% of 79789) affected shaders:
Instrs: 5726914 -> 5727295 (+0.01%); split: -0.00%, +0.01%
CodeSize: 31307100 -> 31308884 (+0.01%); split: -0.00%, +0.01%
SpillSGPRs: 1797 -> 1793 (-0.22%); split: -0.33%, +0.11%
Latency: 58973929 -> 58974343 (+0.00%); split: -0.00%, +0.00%
InvThroughput: 8591893 -> 8591911 (+0.00%); split: -0.00%, +0.00%
SClause: 209074 -> 209115 (+0.02%); split: -0.00%, +0.02%
Copies: 423965 -> 432420 (+1.99%)
Branches: 149976 -> 149979 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 200175 -> 200663 (+0.24%)
VALU: 3440165 -> 3440156 (-0.00%); split: -0.00%, +0.00%
SALU: 555727 -> 556143 (+0.07%); split: -0.00%, +0.08%
Fixes: b872ff6ef28 ("aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF")
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34659>
2025-04-22 19:42:02 +02:00
|
|
|
ctx.had_demote_in_cf = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 18:56:11 +01:00
|
|
|
/* restore exec mask after divergent control flow */
|
2024-01-08 15:12:17 +01:00
|
|
|
if (restore_exec) {
|
2024-10-08 19:46:22 +02:00
|
|
|
Operand restore = ctx.info[idx].exec.back().op;
|
2019-11-27 11:04:47 +01:00
|
|
|
assert(restore.size() == bld.lm.size());
|
2022-02-07 18:56:11 +01:00
|
|
|
bld.copy(Definition(exec, bld.lm), restore);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
void
|
|
|
|
|
remove_disable_wqm(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
assert(instr_disables_wqm(instr));
|
|
|
|
|
|
2025-07-06 20:54:49 +02:00
|
|
|
if (instr->isMUBUF()) {
|
|
|
|
|
instr->mubuf().disable_wqm = false;
|
|
|
|
|
} else if (instr->isMTBUF()) {
|
|
|
|
|
instr->mtbuf().disable_wqm = false;
|
2025-07-06 21:06:48 +02:00
|
|
|
} else if (instr->isFlatLike()) {
|
|
|
|
|
instr->flatlike().disable_wqm = false;
|
2025-07-06 21:21:00 +02:00
|
|
|
} else if (instr->isMIMG()) {
|
|
|
|
|
instr->mimg().disable_wqm = false;
|
2025-07-06 21:51:05 +02:00
|
|
|
} else if (instr->isEXP()) {
|
|
|
|
|
instr->exp().disable_wqm = false;
|
2025-07-06 20:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
/* Remove the two masks so that the assembler doesn't need to handle them. */
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
instr->operands.pop_back();
|
2025-07-06 22:07:26 +02:00
|
|
|
|
|
|
|
|
assert(!instr_disables_wqm(instr));
|
2025-07-06 12:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void
|
|
|
|
|
process_instructions(exec_ctx& ctx, Block* block, std::vector<aco_ptr<Instruction>>& instructions,
|
|
|
|
|
unsigned idx)
|
|
|
|
|
{
|
2024-01-17 12:27:03 +01:00
|
|
|
block_info& info = ctx.info[block->index];
|
2019-09-17 13:22:17 +02:00
|
|
|
WQMState state;
|
2024-10-04 10:27:35 +02:00
|
|
|
if (info.exec.back().type & mask_type_wqm) {
|
2019-09-17 13:22:17 +02:00
|
|
|
state = WQM;
|
2022-02-07 18:56:11 +01:00
|
|
|
} else {
|
2025-07-06 22:10:58 +02:00
|
|
|
assert(!ctx.handle_wqm);
|
2019-09-17 13:22:17 +02:00
|
|
|
state = Exact;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Builder bld(ctx.program, &instructions);
|
|
|
|
|
|
|
|
|
|
for (; idx < block->instructions.size(); idx++) {
|
|
|
|
|
aco_ptr<Instruction> instr = std::move(block->instructions[idx]);
|
|
|
|
|
|
|
|
|
|
if (instr->opcode == aco_opcode::p_discard_if) {
|
2022-02-04 17:13:19 +01:00
|
|
|
Operand current_exec = Operand(exec, bld.lm);
|
|
|
|
|
|
2023-09-03 11:05:08 +02:00
|
|
|
if (block->instructions[idx + 1]->opcode == aco_opcode::p_end_wqm) {
|
|
|
|
|
/* Transition to Exact without extra instruction. */
|
2024-01-17 12:27:03 +01:00
|
|
|
info.exec.resize(1);
|
2024-10-04 10:27:35 +02:00
|
|
|
assert(info.exec[0].type == (mask_type_exact | mask_type_global));
|
2024-10-08 19:46:22 +02:00
|
|
|
current_exec = info.exec[0].op;
|
|
|
|
|
info.exec[0].op = Operand(exec, bld.lm);
|
2023-09-03 11:05:08 +02:00
|
|
|
state = Exact;
|
2024-01-17 12:27:03 +01:00
|
|
|
} else if (info.exec.size() >= 2 && ctx.handle_wqm) {
|
2023-09-03 11:05:08 +02:00
|
|
|
/* Preserve the WQM mask */
|
2024-10-04 10:27:35 +02:00
|
|
|
info.exec[1].type &= ~mask_type_global;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
|
2024-12-19 20:24:28 +01:00
|
|
|
Temp cond;
|
2022-01-31 14:26:50 +01:00
|
|
|
if (instr->operands[0].isConstant()) {
|
|
|
|
|
assert(instr->operands[0].constantValue() == -1u);
|
|
|
|
|
/* save condition and set exec to zero */
|
2024-12-19 20:24:28 +01:00
|
|
|
cond = bld.sop1(Builder::s_and_saveexec, bld.def(bld.lm), bld.def(s1, scc),
|
|
|
|
|
Definition(exec, bld.lm), Operand::zero(), Operand(exec, bld.lm));
|
2022-01-31 14:26:50 +01:00
|
|
|
} else {
|
|
|
|
|
cond = instr->operands[0].getTemp();
|
|
|
|
|
/* discard from current exec */
|
2024-12-19 20:24:28 +01:00
|
|
|
bld.sop2(Builder::s_andn2, Definition(exec, bld.lm), bld.def(s1, scc), current_exec,
|
|
|
|
|
cond);
|
2022-01-31 14:26:50 +01:00
|
|
|
}
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
|
2024-12-19 20:24:28 +01:00
|
|
|
if (info.exec.size() == 1) {
|
|
|
|
|
instr->operands[0] = Operand(exec, bld.lm);
|
|
|
|
|
} else {
|
|
|
|
|
/* discard from inner to outer exec mask on stack */
|
|
|
|
|
int num = info.exec.size() - 2;
|
|
|
|
|
Temp exit_cond;
|
|
|
|
|
for (int i = num; i >= 0; i--) {
|
|
|
|
|
Instruction* andn2 = bld.sop2(Builder::s_andn2, bld.def(bld.lm), bld.def(s1, scc),
|
|
|
|
|
info.exec[i].op, cond);
|
|
|
|
|
info.exec[i].op = Operand(andn2->definitions[0].getTemp());
|
|
|
|
|
exit_cond = andn2->definitions[1].getTemp();
|
|
|
|
|
}
|
|
|
|
|
instr->operands[0] = bld.scc(exit_cond);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
|
2025-01-02 12:27:11 +01:00
|
|
|
info.exec.back().op = Operand(exec, bld.lm);
|
2024-12-19 20:15:12 +01:00
|
|
|
instr->opcode = aco_opcode::p_exit_early_if_not;
|
2024-10-04 10:27:35 +02:00
|
|
|
assert(!ctx.handle_wqm || (info.exec[0].type & mask_type_wqm) == 0);
|
2025-07-06 20:38:00 +02:00
|
|
|
ctx.local_exact_mask = Temp();
|
2022-02-04 17:13:19 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::p_is_helper) {
|
2019-09-17 13:22:17 +02:00
|
|
|
Definition dst = instr->definitions[0];
|
2019-11-27 11:04:47 +01:00
|
|
|
assert(dst.size() == bld.lm.size());
|
2019-09-17 13:22:17 +02:00
|
|
|
if (state == Exact) {
|
2024-03-25 15:55:27 +01:00
|
|
|
instr.reset(create_instruction(bld.w64or32(Builder::s_mov), Format::SOP1, 1, 1));
|
2021-07-13 11:22:46 +02:00
|
|
|
instr->operands[0] = Operand::zero();
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->definitions[0] = dst;
|
|
|
|
|
} else {
|
2024-10-04 10:27:35 +02:00
|
|
|
exec_info& exact_mask = info.exec[0];
|
|
|
|
|
assert(exact_mask.type & mask_type_exact);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-03-25 15:55:27 +01:00
|
|
|
instr.reset(create_instruction(bld.w64or32(Builder::s_andn2), Format::SOP2, 2, 2));
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
instr->operands[0] = Operand(exec, bld.lm); /* current exec */
|
2024-10-04 10:27:35 +02:00
|
|
|
instr->operands[1] = Operand(exact_mask.op);
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->definitions[0] = dst;
|
|
|
|
|
instr->definitions[1] = bld.def(s1, scc);
|
|
|
|
|
}
|
|
|
|
|
} else if (instr->opcode == aco_opcode::p_demote_to_helper) {
|
2025-02-18 11:24:00 +01:00
|
|
|
assert(!ctx.handle_wqm || state == WQM);
|
2024-10-04 10:27:35 +02:00
|
|
|
assert((info.exec[0].type & mask_type_exact) && (info.exec[0].type & mask_type_global));
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2025-02-18 11:24:00 +01:00
|
|
|
if (block->instructions[idx + 1]->opcode == aco_opcode::p_end_wqm) {
|
aco: always terminate quads if they have been demoted entirely
Previously, quads got only terminated in top-level control flow.
This patch makes the behavior consistent.
Totals from 7811 (9.86% of 79242) affected shaders: (GFX11)
Instrs: 7859667 -> 7850757 (-0.11%); split: -0.18%, +0.07%
CodeSize: 41642280 -> 41611836 (-0.07%); split: -0.13%, +0.06%
Latency: 73692815 -> 73707588 (+0.02%); split: -0.02%, +0.04%
InvThroughput: 10672160 -> 10672323 (+0.00%); split: -0.01%, +0.01%
VClause: 137478 -> 137469 (-0.01%); split: -0.02%, +0.02%
SClause: 314905 -> 314924 (+0.01%); split: -0.19%, +0.20%
Copies: 587014 -> 576039 (-1.87%); split: -2.10%, +0.23%
Branches: 213101 -> 213123 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 313588 -> 313355 (-0.07%); split: -0.09%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27112>
2024-01-17 11:46:16 +01:00
|
|
|
/* Transition to Exact without extra instruction. */
|
|
|
|
|
info.exec.resize(1);
|
|
|
|
|
state = Exact;
|
2024-10-08 20:30:15 +02:00
|
|
|
} else {
|
2025-02-18 11:24:00 +01:00
|
|
|
/* Make sure to not use some previously stored temporary. */
|
2024-10-08 20:30:15 +02:00
|
|
|
info.exec.back().op = Operand(exec, bld.lm);
|
aco: always terminate quads if they have been demoted entirely
Previously, quads got only terminated in top-level control flow.
This patch makes the behavior consistent.
Totals from 7811 (9.86% of 79242) affected shaders: (GFX11)
Instrs: 7859667 -> 7850757 (-0.11%); split: -0.18%, +0.07%
CodeSize: 41642280 -> 41611836 (-0.07%); split: -0.13%, +0.06%
Latency: 73692815 -> 73707588 (+0.02%); split: -0.02%, +0.04%
InvThroughput: 10672160 -> 10672323 (+0.00%); split: -0.01%, +0.01%
VClause: 137478 -> 137469 (-0.01%); split: -0.02%, +0.02%
SClause: 314905 -> 314924 (+0.01%); split: -0.19%, +0.20%
Copies: 587014 -> 576039 (-1.87%); split: -2.10%, +0.23%
Branches: 213101 -> 213123 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 313588 -> 313355 (-0.07%); split: -0.09%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27112>
2024-01-17 11:46:16 +01:00
|
|
|
}
|
2020-01-10 17:19:40 +01:00
|
|
|
|
aco: always terminate quads if they have been demoted entirely
Previously, quads got only terminated in top-level control flow.
This patch makes the behavior consistent.
Totals from 7811 (9.86% of 79242) affected shaders: (GFX11)
Instrs: 7859667 -> 7850757 (-0.11%); split: -0.18%, +0.07%
CodeSize: 41642280 -> 41611836 (-0.07%); split: -0.13%, +0.06%
Latency: 73692815 -> 73707588 (+0.02%); split: -0.02%, +0.04%
InvThroughput: 10672160 -> 10672323 (+0.00%); split: -0.01%, +0.01%
VClause: 137478 -> 137469 (-0.01%); split: -0.02%, +0.02%
SClause: 314905 -> 314924 (+0.01%); split: -0.19%, +0.20%
Copies: 587014 -> 576039 (-1.87%); split: -2.10%, +0.23%
Branches: 213101 -> 213123 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 313588 -> 313355 (-0.07%); split: -0.09%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27112>
2024-01-17 11:46:16 +01:00
|
|
|
/* Remove invocations from global exact mask. */
|
|
|
|
|
Operand src = instr->operands[0].isConstant() ? Operand(exec, bld.lm) : instr->operands[0];
|
2025-02-18 11:24:00 +01:00
|
|
|
Operand exit_cond = Operand(exec, bld.lm);
|
aco: always terminate quads if they have been demoted entirely
Previously, quads got only terminated in top-level control flow.
This patch makes the behavior consistent.
Totals from 7811 (9.86% of 79242) affected shaders: (GFX11)
Instrs: 7859667 -> 7850757 (-0.11%); split: -0.18%, +0.07%
CodeSize: 41642280 -> 41611836 (-0.07%); split: -0.13%, +0.06%
Latency: 73692815 -> 73707588 (+0.02%); split: -0.02%, +0.04%
InvThroughput: 10672160 -> 10672323 (+0.00%); split: -0.01%, +0.01%
VClause: 137478 -> 137469 (-0.01%); split: -0.02%, +0.02%
SClause: 314905 -> 314924 (+0.01%); split: -0.19%, +0.20%
Copies: 587014 -> 576039 (-1.87%); split: -2.10%, +0.23%
Branches: 213101 -> 213123 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 313588 -> 313355 (-0.07%); split: -0.09%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27112>
2024-01-17 11:46:16 +01:00
|
|
|
|
2025-02-18 11:24:00 +01:00
|
|
|
if (state == Exact) {
|
|
|
|
|
assert(info.exec.size() == 1);
|
|
|
|
|
bld.sop2(Builder::s_andn2, Definition(exec, bld.lm), bld.def(s1, scc), info.exec[0].op,
|
|
|
|
|
src);
|
2025-03-30 11:22:33 +02:00
|
|
|
info.exec[0].op = Operand(exec, bld.lm);
|
2025-02-18 11:24:00 +01:00
|
|
|
} else {
|
|
|
|
|
Temp cond = bld.tmp(s1);
|
|
|
|
|
info.exec[0].op = bld.sop2(Builder::s_andn2, bld.def(bld.lm), Definition(cond, scc),
|
|
|
|
|
info.exec[0].op, src);
|
|
|
|
|
|
|
|
|
|
/* Update global WQM mask and store in exec. */
|
|
|
|
|
if (info.exec.back().type & mask_type_global) {
|
|
|
|
|
assert(info.exec.size() == 2);
|
|
|
|
|
bld.sop1(Builder::s_wqm, Definition(exec, bld.lm), bld.def(s1, scc),
|
|
|
|
|
info.exec[0].op);
|
|
|
|
|
} else {
|
|
|
|
|
/* Conditionally set exec=0. Note, that exec might already be zero, so don't use s_branch_execz. */
|
|
|
|
|
bld.sop2(Builder::s_cselect, Definition(exec, bld.lm), Operand(exec, bld.lm),
|
|
|
|
|
Operand::zero(bld.lm.bytes()), bld.scc(cond));
|
|
|
|
|
exit_cond = Operand(cond, scc);
|
aco/insert_exec: only restore wqm mask after control flow if necessary
The next commit will make this not free, so we should avoid it if possible.
Foz-DB Navi31:
Totals from 3933 (4.93% of 79789) affected shaders:
Instrs: 5726914 -> 5727295 (+0.01%); split: -0.00%, +0.01%
CodeSize: 31307100 -> 31308884 (+0.01%); split: -0.00%, +0.01%
SpillSGPRs: 1797 -> 1793 (-0.22%); split: -0.33%, +0.11%
Latency: 58973929 -> 58974343 (+0.00%); split: -0.00%, +0.00%
InvThroughput: 8591893 -> 8591911 (+0.00%); split: -0.00%, +0.00%
SClause: 209074 -> 209115 (+0.02%); split: -0.00%, +0.02%
Copies: 423965 -> 432420 (+1.99%)
Branches: 149976 -> 149979 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 200175 -> 200663 (+0.24%)
VALU: 3440165 -> 3440156 (-0.00%); split: -0.00%, +0.00%
SALU: 555727 -> 556143 (+0.07%); split: -0.00%, +0.08%
Fixes: b872ff6ef28 ("aco/insert_exec_mask: if applicable, use s_wqm to restore exec after divergent CF")
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34659>
2025-04-22 19:42:02 +02:00
|
|
|
/* Remember to disable empty quads in top level control flow. */
|
|
|
|
|
ctx.had_demote_in_cf = true;
|
2025-02-18 11:24:00 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
aco: always terminate quads if they have been demoted entirely
Previously, quads got only terminated in top-level control flow.
This patch makes the behavior consistent.
Totals from 7811 (9.86% of 79242) affected shaders: (GFX11)
Instrs: 7859667 -> 7850757 (-0.11%); split: -0.18%, +0.07%
CodeSize: 41642280 -> 41611836 (-0.07%); split: -0.13%, +0.06%
Latency: 73692815 -> 73707588 (+0.02%); split: -0.02%, +0.04%
InvThroughput: 10672160 -> 10672323 (+0.00%); split: -0.01%, +0.01%
VClause: 137478 -> 137469 (-0.01%); split: -0.02%, +0.02%
SClause: 314905 -> 314924 (+0.01%); split: -0.19%, +0.20%
Copies: 587014 -> 576039 (-1.87%); split: -2.10%, +0.23%
Branches: 213101 -> 213123 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 313588 -> 313355 (-0.07%); split: -0.09%, +0.01%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27112>
2024-01-17 11:46:16 +01:00
|
|
|
/* End shader if global mask is zero. */
|
2024-12-19 20:15:12 +01:00
|
|
|
instr->opcode = aco_opcode::p_exit_early_if_not;
|
2025-02-18 11:24:00 +01:00
|
|
|
instr->operands[0] = exit_cond;
|
2021-06-18 15:21:43 +02:00
|
|
|
|
2025-07-06 20:38:00 +02:00
|
|
|
ctx.local_exact_mask = Temp();
|
2021-06-18 15:21:43 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::p_elect) {
|
2024-10-04 10:27:35 +02:00
|
|
|
bool all_lanes_enabled = info.exec.back().op.constantEquals(-1u);
|
2021-06-18 15:21:43 +02:00
|
|
|
Definition dst = instr->definitions[0];
|
|
|
|
|
|
|
|
|
|
if (all_lanes_enabled) {
|
|
|
|
|
bld.copy(Definition(dst), Operand::c32_or_c64(1u, dst.size() == 2));
|
|
|
|
|
} else {
|
|
|
|
|
Temp first_lane_idx = bld.sop1(Builder::s_ff1_i32, bld.def(s1), Operand(exec, bld.lm));
|
|
|
|
|
bld.sop2(Builder::s_lshl, Definition(dst), bld.def(s1, scc),
|
|
|
|
|
Operand::c32_or_c64(1u, dst.size() == 2), Operand(first_lane_idx));
|
|
|
|
|
}
|
2023-09-03 11:05:08 +02:00
|
|
|
continue;
|
|
|
|
|
} else if (instr->opcode == aco_opcode::p_end_wqm) {
|
|
|
|
|
assert(block->kind & block_kind_top_level);
|
2024-01-17 12:27:03 +01:00
|
|
|
assert(info.exec.size() <= 2);
|
2023-09-03 11:05:08 +02:00
|
|
|
/* This instruction indicates the end of WQM mode. */
|
2024-10-04 10:27:35 +02:00
|
|
|
info.exec.back().type |= mask_type_global;
|
2023-09-03 11:05:08 +02:00
|
|
|
transition_to_Exact(ctx, bld, block->index);
|
|
|
|
|
state = Exact;
|
|
|
|
|
ctx.handle_wqm = false;
|
2021-06-18 15:21:43 +02:00
|
|
|
continue;
|
2025-07-06 20:38:00 +02:00
|
|
|
} else if (instr_disables_wqm(instr.get())) {
|
|
|
|
|
if (!ctx.handle_wqm) {
|
|
|
|
|
remove_disable_wqm(instr.get());
|
|
|
|
|
} else {
|
|
|
|
|
if (!info.exec.back().op.isTemp())
|
|
|
|
|
info.exec.back().op = bld.copy(bld.def(bld.lm), Operand(exec, bld.lm));
|
|
|
|
|
|
|
|
|
|
instr_wqm_mask(instr.get()) = info.exec.back().op;
|
|
|
|
|
|
|
|
|
|
if (info.exec.size() > 2) {
|
|
|
|
|
if (!ctx.local_exact_mask.id()) {
|
|
|
|
|
ctx.local_exact_mask = bld.sop2(Builder::s_and, bld.def(bld.lm), bld.def(s1, scc),
|
|
|
|
|
ctx.info[block->index].exec[0].op, Operand(exec, bld.lm));
|
|
|
|
|
}
|
|
|
|
|
instr_exact_mask(instr.get()) = Operand(ctx.local_exact_mask);
|
|
|
|
|
} else {
|
|
|
|
|
instr_exact_mask(instr.get()) = info.exec[0].op;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bld.insert(std::move(instr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
add_branch_code(exec_ctx& ctx, Block* block)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx = block->index;
|
|
|
|
|
Builder bld(ctx.program, block);
|
|
|
|
|
|
2023-01-19 17:36:06 +01:00
|
|
|
if (block->linear_succs.empty())
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (block->kind & block_kind_loop_preheader) {
|
|
|
|
|
/* collect information about the succeeding loop */
|
|
|
|
|
bool has_divergent_break = false;
|
|
|
|
|
bool has_divergent_continue = false;
|
|
|
|
|
bool has_discard = false;
|
|
|
|
|
unsigned loop_nest_depth = ctx.program->blocks[idx + 1].loop_nest_depth;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = idx + 1; ctx.program->blocks[i].loop_nest_depth >= loop_nest_depth; i++) {
|
|
|
|
|
Block& loop_block = ctx.program->blocks[i];
|
|
|
|
|
|
2022-01-31 16:30:08 +01:00
|
|
|
if (loop_block.kind & block_kind_uses_discard)
|
2019-09-17 13:22:17 +02:00
|
|
|
has_discard = true;
|
|
|
|
|
if (loop_block.loop_nest_depth != loop_nest_depth)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (loop_block.kind & block_kind_uniform)
|
|
|
|
|
continue;
|
|
|
|
|
else if (loop_block.kind & block_kind_break)
|
|
|
|
|
has_divergent_break = true;
|
|
|
|
|
else if (loop_block.kind & block_kind_continue)
|
|
|
|
|
has_divergent_continue = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-06 12:59:51 +01:00
|
|
|
if (has_divergent_break) {
|
|
|
|
|
/* save restore exec mask */
|
2024-10-08 20:37:26 +02:00
|
|
|
const Operand& current_exec = ctx.info[idx].exec.back().op;
|
|
|
|
|
if (!current_exec.isTemp() && !current_exec.isConstant()) {
|
2024-01-06 12:59:51 +01:00
|
|
|
bld.reset(bld.instructions, std::prev(bld.instructions->end()));
|
|
|
|
|
Operand restore = bld.copy(bld.def(bld.lm), Operand(exec, bld.lm));
|
2024-10-08 20:30:15 +02:00
|
|
|
ctx.info[idx].exec.back().op = restore;
|
2024-01-06 12:59:51 +01:00
|
|
|
bld.reset(bld.instructions);
|
|
|
|
|
}
|
2024-10-08 20:30:15 +02:00
|
|
|
uint8_t mask = ctx.info[idx].exec.back().type & (mask_type_wqm | mask_type_exact);
|
|
|
|
|
ctx.info[idx].exec.emplace_back(Operand(exec, bld.lm), mask);
|
2024-01-06 12:59:51 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
unsigned num_exec_masks = ctx.info[idx].exec.size();
|
|
|
|
|
|
2022-02-07 18:56:11 +01:00
|
|
|
ctx.loop.emplace_back(&ctx.program->blocks[block->linear_succs[0]], num_exec_masks,
|
2019-09-17 13:22:17 +02:00
|
|
|
has_divergent_break, has_divergent_continue, has_discard);
|
|
|
|
|
|
2024-10-08 14:33:02 +02:00
|
|
|
Pseudo_branch_instruction& branch = block->instructions.back()->branch();
|
|
|
|
|
branch.target[0] = block->linear_succs[0];
|
|
|
|
|
} else if (block->kind & block_kind_uniform) {
|
2021-01-21 16:13:34 +00:00
|
|
|
Pseudo_branch_instruction& branch = block->instructions.back()->branch();
|
|
|
|
|
if (branch.opcode == aco_opcode::p_branch) {
|
|
|
|
|
branch.target[0] = block->linear_succs[0];
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
2021-01-21 16:13:34 +00:00
|
|
|
branch.target[0] = block->linear_succs[1];
|
|
|
|
|
branch.target[1] = block->linear_succs[0];
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2024-10-08 14:33:02 +02:00
|
|
|
} else if (block->kind & block_kind_branch) {
|
2019-09-17 13:22:17 +02:00
|
|
|
// orig = s_and_saveexec_b64
|
|
|
|
|
assert(block->linear_succs.size() == 2);
|
|
|
|
|
assert(block->instructions.back()->opcode == aco_opcode::p_cbranch_z);
|
|
|
|
|
Temp cond = block->instructions.back()->operands[0].getTemp();
|
2024-07-12 19:36:07 +01:00
|
|
|
aco_ptr<Instruction> branch = std::move(block->instructions.back());
|
2019-09-17 13:22:17 +02:00
|
|
|
block->instructions.pop_back();
|
|
|
|
|
|
2024-10-04 10:27:35 +02:00
|
|
|
uint8_t mask_type = ctx.info[idx].exec.back().type & (mask_type_wqm | mask_type_exact);
|
|
|
|
|
if (ctx.info[idx].exec.back().op.constantEquals(-1u)) {
|
2022-02-07 18:56:11 +01:00
|
|
|
bld.copy(Definition(exec, bld.lm), cond);
|
aco/insert_exec: reuse old exec temp instead using s_and_saveexec
This means the v_cmpx optimization in ssa_elimination no longer
needs to insert a copy to save exec.
Foz-DB Navi31:
Totals from 13816 (17.40% of 79395) affected shaders:
Instrs: 23694267 -> 23670199 (-0.10%); split: -0.11%, +0.01%
CodeSize: 124559288 -> 124457508 (-0.08%); split: -0.09%, +0.01%
SpillSGPRs: 5324 -> 5354 (+0.56%); split: -1.00%, +1.56%
Latency: 207245846 -> 207213681 (-0.02%); split: -0.03%, +0.01%
InvThroughput: 35442657 -> 35437220 (-0.02%); split: -0.02%, +0.01%
VClause: 444672 -> 444670 (-0.00%); split: -0.00%, +0.00%
SClause: 639419 -> 639373 (-0.01%); split: -0.04%, +0.03%
Copies: 1529008 -> 1515871 (-0.86%); split: -1.02%, +0.16%
Branches: 557201 -> 557701 (+0.09%); split: -0.00%, +0.09%
PreSGPRs: 682840 -> 686048 (+0.47%)
VALU: 13978010 -> 13978032 (+0.00%); split: -0.00%, +0.00%
SALU: 2214600 -> 2197061 (-0.79%); split: -0.81%, +0.02%
VOPD: 5561 -> 5560 (-0.02%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31567>
2024-10-08 21:59:35 +02:00
|
|
|
} else if (ctx.info[idx].exec.back().op.isTemp()) {
|
|
|
|
|
bld.sop2(Builder::s_and, Definition(exec, bld.lm), bld.def(s1, scc), cond,
|
|
|
|
|
Operand(exec, bld.lm));
|
aco: Don't use s_and_saveexec with branches when exec is constant.
When exec is constant, we can remember the constant as the old exec,
and just copy the condition and use it as the new exec. There is no
need to save the constant.
Due to using p_parallelcopy which is lowered to s_mov_b64 (or 32),
many exec restores now become copies, hence the increase in the copy
stats.
Fossil DB changes on Sienna Cichlid:
Totals from 73969 (49.37% of 149839) affected shaders:
SpillSGPRs: 1768 -> 1610 (-8.94%)
CodeSize: 99053892 -> 99047884 (-0.01%); split: -0.02%, +0.01%
Instrs: 19372852 -> 19370398 (-0.01%); split: -0.02%, +0.01%
VClause: 515154 -> 515142 (-0.00%); split: -0.00%, +0.00%
SClause: 719236 -> 718395 (-0.12%); split: -0.14%, +0.02%
Copies: 1109770 -> 1254634 (+13.05%); split: -0.07%, +13.12%
Branches: 374338 -> 374348 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 1776481 -> 1653761 (-6.91%)
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10691>
2021-05-07 15:03:36 +02:00
|
|
|
} else {
|
|
|
|
|
Temp old_exec = bld.sop1(Builder::s_and_saveexec, bld.def(bld.lm), bld.def(s1, scc),
|
|
|
|
|
Definition(exec, bld.lm), cond, Operand(exec, bld.lm));
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec.back().op = Operand(old_exec);
|
aco: Don't use s_and_saveexec with branches when exec is constant.
When exec is constant, we can remember the constant as the old exec,
and just copy the condition and use it as the new exec. There is no
need to save the constant.
Due to using p_parallelcopy which is lowered to s_mov_b64 (or 32),
many exec restores now become copies, hence the increase in the copy
stats.
Fossil DB changes on Sienna Cichlid:
Totals from 73969 (49.37% of 149839) affected shaders:
SpillSGPRs: 1768 -> 1610 (-8.94%)
CodeSize: 99053892 -> 99047884 (-0.01%); split: -0.02%, +0.01%
Instrs: 19372852 -> 19370398 (-0.01%); split: -0.02%, +0.01%
VClause: 515154 -> 515142 (-0.00%); split: -0.00%, +0.00%
SClause: 719236 -> 718395 (-0.12%); split: -0.14%, +0.02%
Copies: 1109770 -> 1254634 (+13.05%); split: -0.07%, +13.12%
Branches: 374338 -> 374348 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 1776481 -> 1653761 (-6.91%)
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10691>
2021-05-07 15:03:36 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
/* add next current exec to the stack */
|
2024-10-08 19:46:22 +02:00
|
|
|
ctx.info[idx].exec.emplace_back(Operand(exec, bld.lm), mask_type);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
aco: remove definition from Pseudo branch instructions
They are not needed anymore.
Totals from 7019 (8.84% of 79395) affected shaders: (Navi31)
Instrs: 14805400 -> 14824196 (+0.13%); split: -0.00%, +0.13%
CodeSize: 78079972 -> 78132932 (+0.07%); split: -0.01%, +0.08%
SpillSGPRs: 4485 -> 4515 (+0.67%); split: -0.76%, +1.43%
Latency: 165862000 -> 165836134 (-0.02%); split: -0.02%, +0.00%
InvThroughput: 30061764 -> 30057781 (-0.01%); split: -0.01%, +0.00%
SClause: 392323 -> 392286 (-0.01%); split: -0.01%, +0.00%
Copies: 1012262 -> 1012234 (-0.00%); split: -0.04%, +0.04%
Branches: 365910 -> 365909 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 360167 -> 355363 (-1.33%)
VALU: 8837197 -> 8837276 (+0.00%); split: -0.00%, +0.00%
SALU: 1402593 -> 1402621 (+0.00%); split: -0.03%, +0.03%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32037>
2024-11-07 09:42:04 +01:00
|
|
|
Builder::Result r = bld.branch(aco_opcode::p_cbranch_z, Operand(exec, bld.lm),
|
2022-02-23 10:13:54 +01:00
|
|
|
block->linear_succs[1], block->linear_succs[0]);
|
2024-07-12 19:36:07 +01:00
|
|
|
r->branch().rarely_taken = branch->branch().rarely_taken;
|
|
|
|
|
r->branch().never_taken = branch->branch().never_taken;
|
2024-10-08 14:33:02 +02:00
|
|
|
} else if (block->kind & block_kind_invert) {
|
2019-09-17 13:22:17 +02:00
|
|
|
// exec = s_andn2_b64 (original_exec, exec)
|
2021-05-19 15:42:10 +02:00
|
|
|
assert(block->instructions.back()->opcode == aco_opcode::p_branch);
|
2024-07-12 19:36:07 +01:00
|
|
|
aco_ptr<Instruction> branch = std::move(block->instructions.back());
|
2019-09-17 13:22:17 +02:00
|
|
|
block->instructions.pop_back();
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
assert(ctx.info[idx].exec.size() >= 2);
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand orig_exec = ctx.info[idx].exec[ctx.info[idx].exec.size() - 2].op;
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
bld.sop2(Builder::s_andn2, Definition(exec, bld.lm), bld.def(s1, scc), orig_exec,
|
|
|
|
|
Operand(exec, bld.lm));
|
2019-09-17 13:22:17 +02:00
|
|
|
|
aco: remove definition from Pseudo branch instructions
They are not needed anymore.
Totals from 7019 (8.84% of 79395) affected shaders: (Navi31)
Instrs: 14805400 -> 14824196 (+0.13%); split: -0.00%, +0.13%
CodeSize: 78079972 -> 78132932 (+0.07%); split: -0.01%, +0.08%
SpillSGPRs: 4485 -> 4515 (+0.67%); split: -0.76%, +1.43%
Latency: 165862000 -> 165836134 (-0.02%); split: -0.02%, +0.00%
InvThroughput: 30061764 -> 30057781 (-0.01%); split: -0.01%, +0.00%
SClause: 392323 -> 392286 (-0.01%); split: -0.01%, +0.00%
Copies: 1012262 -> 1012234 (-0.00%); split: -0.04%, +0.04%
Branches: 365910 -> 365909 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 360167 -> 355363 (-1.33%)
VALU: 8837197 -> 8837276 (+0.00%); split: -0.00%, +0.00%
SALU: 1402593 -> 1402621 (+0.00%); split: -0.03%, +0.03%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32037>
2024-11-07 09:42:04 +01:00
|
|
|
Builder::Result r = bld.branch(aco_opcode::p_cbranch_z, Operand(exec, bld.lm),
|
2022-02-23 10:13:54 +01:00
|
|
|
block->linear_succs[1], block->linear_succs[0]);
|
2024-07-12 19:36:07 +01:00
|
|
|
r->branch().rarely_taken = branch->branch().rarely_taken;
|
|
|
|
|
r->branch().never_taken = branch->branch().never_taken;
|
2024-10-08 14:33:02 +02:00
|
|
|
} else if (block->kind & block_kind_break) {
|
2019-09-17 13:22:17 +02:00
|
|
|
// loop_mask = s_andn2_b64 (loop_mask, exec)
|
|
|
|
|
assert(block->instructions.back()->opcode == aco_opcode::p_branch);
|
|
|
|
|
block->instructions.pop_back();
|
|
|
|
|
|
|
|
|
|
Temp cond = Temp();
|
|
|
|
|
for (int exec_idx = ctx.info[idx].exec.size() - 2; exec_idx >= 0; exec_idx--) {
|
|
|
|
|
cond = bld.tmp(s1);
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand exec_mask = ctx.info[idx].exec[exec_idx].op;
|
2019-11-27 11:04:47 +01:00
|
|
|
exec_mask = bld.sop2(Builder::s_andn2, bld.def(bld.lm), bld.scc(Definition(cond)),
|
2024-10-08 14:18:02 +02:00
|
|
|
exec_mask, Operand(exec, bld.lm));
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec[exec_idx].op = exec_mask;
|
|
|
|
|
if (ctx.info[idx].exec[exec_idx].type & mask_type_loop)
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 09:16:05 +01:00
|
|
|
/* Implicitly set exec to zero and branch. */
|
|
|
|
|
ctx.info[idx].exec.back().op = Operand::zero(bld.lm.bytes());
|
aco: remove definition from Pseudo branch instructions
They are not needed anymore.
Totals from 7019 (8.84% of 79395) affected shaders: (Navi31)
Instrs: 14805400 -> 14824196 (+0.13%); split: -0.00%, +0.13%
CodeSize: 78079972 -> 78132932 (+0.07%); split: -0.01%, +0.08%
SpillSGPRs: 4485 -> 4515 (+0.67%); split: -0.76%, +1.43%
Latency: 165862000 -> 165836134 (-0.02%); split: -0.02%, +0.00%
InvThroughput: 30061764 -> 30057781 (-0.01%); split: -0.01%, +0.00%
SClause: 392323 -> 392286 (-0.01%); split: -0.01%, +0.00%
Copies: 1012262 -> 1012234 (-0.00%); split: -0.04%, +0.04%
Branches: 365910 -> 365909 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 360167 -> 355363 (-1.33%)
VALU: 8837197 -> 8837276 (+0.00%); split: -0.00%, +0.00%
SALU: 1402593 -> 1402621 (+0.00%); split: -0.03%, +0.03%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32037>
2024-11-07 09:42:04 +01:00
|
|
|
bld.branch(aco_opcode::p_cbranch_nz, bld.scc(cond), block->linear_succs[1],
|
2021-07-28 15:11:03 +01:00
|
|
|
block->linear_succs[0]);
|
2024-10-08 14:33:02 +02:00
|
|
|
} else if (block->kind & block_kind_continue) {
|
2019-09-17 13:22:17 +02:00
|
|
|
assert(block->instructions.back()->opcode == aco_opcode::p_branch);
|
|
|
|
|
block->instructions.pop_back();
|
|
|
|
|
|
|
|
|
|
Temp cond = Temp();
|
|
|
|
|
for (int exec_idx = ctx.info[idx].exec.size() - 2; exec_idx >= 0; exec_idx--) {
|
2024-10-04 10:27:35 +02:00
|
|
|
if (ctx.info[idx].exec[exec_idx].type & mask_type_loop)
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
cond = bld.tmp(s1);
|
2024-10-04 10:27:35 +02:00
|
|
|
Operand exec_mask = ctx.info[idx].exec[exec_idx].op;
|
2019-11-27 11:04:47 +01:00
|
|
|
exec_mask = bld.sop2(Builder::s_andn2, bld.def(bld.lm), bld.scc(Definition(cond)),
|
aco: make all exec accesses non-temporaries
So that they are not counted into the register demand.
Totals from 107336 (77.00% of 139391) affected shaders (Navi10):
VGPRs: 4023452 -> 4023248 (-0.01%); split: -0.01%, +0.01%
SpillSGPRs: 14088 -> 12571 (-10.77%); split: -11.03%, +0.26%
CodeSize: 266816164 -> 266765528 (-0.02%); split: -0.04%, +0.02%
MaxWaves: 1553339 -> 1553374 (+0.00%); split: +0.00%, -0.00%
Instrs: 50977701 -> 50973093 (-0.01%); split: -0.02%, +0.01%
Cycles: 1733911128 -> 1733605320 (-0.02%); split: -0.05%, +0.03%
VMEM: 40867650 -> 40900204 (+0.08%); split: +0.13%, -0.05%
SMEM: 6835980 -> 6829073 (-0.10%); split: +0.10%, -0.20%
VClause: 1032783 -> 1032788 (+0.00%); split: -0.01%, +0.01%
SClause: 2103705 -> 2104115 (+0.02%); split: -0.09%, +0.11%
Copies: 3195658 -> 3193656 (-0.06%); split: -0.30%, +0.24%
Branches: 1140213 -> 1140120 (-0.01%); split: -0.05%, +0.04%
PreSGPRs: 3603785 -> 3437064 (-4.63%); split: -5.13%, +0.50%
PreVGPRs: 3321996 -> 3321850 (-0.00%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8870>
2021-02-03 15:44:49 +01:00
|
|
|
exec_mask, Operand(exec, bld.lm));
|
2024-10-04 10:27:35 +02:00
|
|
|
ctx.info[idx].exec[exec_idx].op = exec_mask;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
assert(cond != Temp());
|
|
|
|
|
|
2025-02-13 09:16:05 +01:00
|
|
|
/* Implicitly set exec to zero and branch. */
|
|
|
|
|
ctx.info[idx].exec.back().op = Operand::zero(bld.lm.bytes());
|
aco: remove definition from Pseudo branch instructions
They are not needed anymore.
Totals from 7019 (8.84% of 79395) affected shaders: (Navi31)
Instrs: 14805400 -> 14824196 (+0.13%); split: -0.00%, +0.13%
CodeSize: 78079972 -> 78132932 (+0.07%); split: -0.01%, +0.08%
SpillSGPRs: 4485 -> 4515 (+0.67%); split: -0.76%, +1.43%
Latency: 165862000 -> 165836134 (-0.02%); split: -0.02%, +0.00%
InvThroughput: 30061764 -> 30057781 (-0.01%); split: -0.01%, +0.00%
SClause: 392323 -> 392286 (-0.01%); split: -0.01%, +0.00%
Copies: 1012262 -> 1012234 (-0.00%); split: -0.04%, +0.04%
Branches: 365910 -> 365909 (-0.00%); split: -0.00%, +0.00%
PreSGPRs: 360167 -> 355363 (-1.33%)
VALU: 8837197 -> 8837276 (+0.00%); split: -0.00%, +0.00%
SALU: 1402593 -> 1402621 (+0.00%); split: -0.03%, +0.03%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32037>
2024-11-07 09:42:04 +01:00
|
|
|
bld.branch(aco_opcode::p_cbranch_nz, bld.scc(cond), block->linear_succs[1],
|
2021-07-28 15:11:03 +01:00
|
|
|
block->linear_succs[0]);
|
2024-10-08 14:33:02 +02:00
|
|
|
} else {
|
2025-07-23 09:17:35 +02:00
|
|
|
UNREACHABLE("unknown/invalid block type");
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
process_block(exec_ctx& ctx, Block* block)
|
|
|
|
|
{
|
|
|
|
|
std::vector<aco_ptr<Instruction>> instructions;
|
|
|
|
|
instructions.reserve(block->instructions.size());
|
|
|
|
|
|
|
|
|
|
unsigned idx = add_coupling_code(ctx, block, instructions);
|
|
|
|
|
|
2023-01-19 17:36:06 +01:00
|
|
|
assert(!block->linear_succs.empty() || ctx.info[block->index].exec.size() <= 2);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
process_instructions(ctx, block, instructions, idx);
|
|
|
|
|
|
|
|
|
|
block->instructions = std::move(instructions);
|
|
|
|
|
|
|
|
|
|
add_branch_code(ctx, block);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 17:02:35 +02:00
|
|
|
template <typename T, typename U>
|
|
|
|
|
bool
|
|
|
|
|
regs_intersect(const T& a, const U& b)
|
|
|
|
|
{
|
|
|
|
|
const unsigned a_lo = a.physReg();
|
|
|
|
|
const unsigned a_hi = a_lo + a.size();
|
|
|
|
|
const unsigned b_lo = b.physReg();
|
|
|
|
|
const unsigned b_hi = b_lo + b.size();
|
|
|
|
|
|
|
|
|
|
return a_hi > b_lo && b_hi > a_lo;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
void
|
|
|
|
|
disable_wqm_block(Program* program, Block* block)
|
|
|
|
|
{
|
|
|
|
|
std::vector<aco_ptr<Instruction>> instructions;
|
|
|
|
|
instructions.reserve(block->instructions.size());
|
|
|
|
|
|
|
|
|
|
Builder bld(program, &instructions);
|
|
|
|
|
|
2025-08-04 17:02:35 +02:00
|
|
|
unsigned local_exact_and_idx = 0;
|
|
|
|
|
unsigned local_wqm_mov_idx = 0;
|
|
|
|
|
Instruction* local_exact_and = nullptr;
|
|
|
|
|
Instruction* local_wqm_mov = nullptr;
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
for (unsigned i = 0; i < block->instructions.size(); i++) {
|
|
|
|
|
aco_ptr<Instruction>& instr = block->instructions[i];
|
|
|
|
|
if (!instr_disables_wqm(instr.get())) {
|
2025-08-04 17:02:35 +02:00
|
|
|
for (const Definition& def : instr->definitions) {
|
|
|
|
|
if (def.physReg() == exec_lo || def.physReg() == exec_hi) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
local_wqm_mov = nullptr;
|
|
|
|
|
} else if (def.physReg() == scc) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
} else if (local_exact_and && regs_intersect(def, local_exact_and->operands[0])) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
} else if (local_exact_and && regs_intersect(def, local_exact_and->definitions[0])) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
} else if (local_wqm_mov && regs_intersect(def, local_wqm_mov->definitions[0])) {
|
|
|
|
|
local_wqm_mov = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const Operand& op : instr->operands) {
|
|
|
|
|
if (op.physReg() == scc) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
} else if (local_exact_and && regs_intersect(op, local_exact_and->definitions[0])) {
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
} else if (local_wqm_mov && regs_intersect(op, local_wqm_mov->definitions[0])) {
|
|
|
|
|
local_wqm_mov = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->opcode == bld.w64or32(Builder::s_and) && instr->operands[1].physReg() == exec) {
|
|
|
|
|
local_exact_and = instr.get();
|
|
|
|
|
local_exact_and_idx = instructions.size();
|
|
|
|
|
} else if (instr->opcode == bld.w64or32(Builder::s_mov) &&
|
|
|
|
|
instr->operands[0].physReg() == exec) {
|
|
|
|
|
local_wqm_mov = instr.get();
|
|
|
|
|
local_wqm_mov_idx = instructions.size();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
bld.insert(std::move(instr));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Operand exact_mask = instr_exact_mask(instr.get());
|
|
|
|
|
Operand wqm_mask = instr_wqm_mask(instr.get());
|
|
|
|
|
assert(exact_mask.hasRegClass() && exact_mask.regClass() == bld.lm);
|
|
|
|
|
assert(wqm_mask.hasRegClass() && wqm_mask.regClass() == bld.lm);
|
|
|
|
|
|
2025-08-04 17:02:35 +02:00
|
|
|
if (local_exact_and && local_exact_and->definitions[0].physReg() != exact_mask.physReg())
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
if (local_wqm_mov && local_wqm_mov->definitions[0].physReg() != wqm_mask.physReg())
|
|
|
|
|
local_wqm_mov = nullptr;
|
|
|
|
|
|
|
|
|
|
if (local_exact_and) {
|
|
|
|
|
bld.sop1(Builder::s_and_saveexec, Definition(wqm_mask.physReg(), bld.lm),
|
|
|
|
|
Definition(scc, s1), Definition(exec, bld.lm), local_exact_and->operands[0],
|
|
|
|
|
Operand(exec, bld.lm));
|
|
|
|
|
} else {
|
|
|
|
|
bld.sop1(Builder::s_mov, Definition(exec, bld.lm), exact_mask);
|
|
|
|
|
}
|
2025-07-06 12:15:56 +02:00
|
|
|
|
|
|
|
|
remove_disable_wqm(instr.get());
|
|
|
|
|
bld.insert(std::move(instr));
|
|
|
|
|
|
|
|
|
|
/* Keep exact mask for whole clauses. */
|
|
|
|
|
for (; i + 1 < block->instructions.size(); i++) {
|
|
|
|
|
aco_ptr<Instruction>& next = block->instructions[i + 1];
|
|
|
|
|
if (!instr_disables_wqm(next.get()) ||
|
|
|
|
|
instr_exact_mask(next.get()).physReg() != exact_mask.physReg() ||
|
|
|
|
|
instr_wqm_mask(next.get()).physReg() != wqm_mask.physReg())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
remove_disable_wqm(next.get());
|
|
|
|
|
bld.insert(std::move(next));
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 17:02:35 +02:00
|
|
|
if (local_exact_and) {
|
|
|
|
|
bld.sop1(Builder::s_or_saveexec, Definition(exact_mask.physReg(), bld.lm),
|
|
|
|
|
Definition(scc, s1), Definition(exec, bld.lm), wqm_mask, Operand(exec, bld.lm));
|
|
|
|
|
|
|
|
|
|
if (local_wqm_mov && local_wqm_mov_idx < local_exact_and_idx) {
|
|
|
|
|
instructions.erase(instructions.begin() + local_exact_and_idx);
|
|
|
|
|
instructions.erase(instructions.begin() + local_wqm_mov_idx);
|
|
|
|
|
} else if (local_wqm_mov) {
|
|
|
|
|
instructions.erase(instructions.begin() + local_wqm_mov_idx);
|
|
|
|
|
instructions.erase(instructions.begin() + local_exact_and_idx);
|
|
|
|
|
} else {
|
|
|
|
|
instructions.erase(instructions.begin() + local_exact_and_idx);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
bld.sop1(Builder::s_mov, Definition(exec, bld.lm), wqm_mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local_exact_and = nullptr;
|
|
|
|
|
local_wqm_mov = nullptr;
|
2025-07-06 12:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block->instructions = std::move(instructions);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
} /* end namespace */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
insert_exec_mask(Program* program)
|
|
|
|
|
{
|
|
|
|
|
exec_ctx ctx(program);
|
|
|
|
|
|
|
|
|
|
if (program->needs_wqm && program->needs_exact)
|
2023-09-04 10:07:27 +02:00
|
|
|
ctx.handle_wqm = true;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
for (Block& block : program->blocks)
|
|
|
|
|
process_block(ctx, &block);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
bool
|
|
|
|
|
instr_disables_wqm(Instruction* instr)
|
|
|
|
|
{
|
2025-07-06 20:54:49 +02:00
|
|
|
if (instr->isMUBUF()) {
|
|
|
|
|
return instr->mubuf().disable_wqm;
|
|
|
|
|
} else if (instr->isMTBUF()) {
|
|
|
|
|
return instr->mtbuf().disable_wqm;
|
2025-07-06 21:06:48 +02:00
|
|
|
} else if (instr->isFlatLike()) {
|
|
|
|
|
return instr->flatlike().disable_wqm;
|
2025-07-06 21:21:00 +02:00
|
|
|
} else if (instr->isMIMG()) {
|
|
|
|
|
return instr->mimg().disable_wqm;
|
2025-07-06 21:51:05 +02:00
|
|
|
} else if (instr->isEXP()) {
|
|
|
|
|
return instr->exp().disable_wqm;
|
2025-07-06 22:07:26 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::p_dual_src_export_gfx11) {
|
|
|
|
|
return instr->operands.size() > 8;
|
2025-07-06 20:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-06 12:15:56 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Operand&
|
|
|
|
|
instr_exact_mask(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
return instr->operands[instr->operands.size() - 2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Operand&
|
|
|
|
|
instr_wqm_mask(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
return instr->operands[instr->operands.size() - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
disable_wqm(Program* program)
|
|
|
|
|
{
|
|
|
|
|
if (!program->needs_wqm || !program->needs_exact)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (Block& block : program->blocks)
|
|
|
|
|
disable_wqm_block(program, &block);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
} // namespace aco
|