diff options
author | Eric Anholt <eric@anholt.net> | 2020-08-12 11:17:28 -0700 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2021-06-18 04:30:43 +0000 |
commit | 47804f53f991c3467671e05421df437b0f34eb22 (patch) | |
tree | 09d3fc55c6230b5d1aefdb19c58cb864692459dc /src/compiler | |
parent | aba8b6675ae3ddc136f4f48cbabb7d3e24c6d58b (diff) |
nir: Do peephole select on other instructions if the limit is ~0.
limit==0 is the signal for "don't peephole anything but a move that will
be optimized aways." limit > 0 is "up to N alu instructions may be moved
out." nir-to-tgsi uses ~0 as the indicator of "No, we really need to
eliminate all if instructions" on hardware like i915 that doesn't have
control flow.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11329>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir_opt_peephole_select.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c index 62530ddd793..dec36670cbc 100644 --- a/src/compiler/nir/nir_opt_peephole_select.c +++ b/src/compiler/nir/nir_opt_peephole_select.c @@ -61,9 +61,37 @@ static bool block_check_for_allowed_instrs(nir_block *block, unsigned *count, - bool alu_ok, bool indirect_load_ok, + unsigned limit, bool indirect_load_ok, bool expensive_alu_ok) { + bool alu_ok = limit != 0; + + /* Used on non-control-flow HW to flatten all IFs. */ + if (limit == ~0) { + nir_foreach_instr(instr, block) { + switch (instr->type) { + case nir_instr_type_alu: + case nir_instr_type_deref: + case nir_instr_type_load_const: + case nir_instr_type_phi: + case nir_instr_type_ssa_undef: + case nir_instr_type_tex: + break; + + case nir_instr_type_intrinsic: + if (!nir_intrinsic_can_reorder(nir_instr_as_intrinsic(instr))) + return false; + break; + + case nir_instr_type_call: + case nir_instr_type_jump: + case nir_instr_type_parallel_copy: + return false; + } + } + return true; + } + nir_foreach_instr(instr, block) { switch (instr->type) { case nir_instr_type_intrinsic: { @@ -379,9 +407,9 @@ nir_opt_peephole_select_block(nir_block *block, nir_shader *shader, /* ... and those blocks must only contain "allowed" instructions. */ unsigned count = 0; - if (!block_check_for_allowed_instrs(then_block, &count, limit != 0, + if (!block_check_for_allowed_instrs(then_block, &count, limit, indirect_load_ok, expensive_alu_ok) || - !block_check_for_allowed_instrs(else_block, &count, limit != 0, + !block_check_for_allowed_instrs(else_block, &count, limit, indirect_load_ok, expensive_alu_ok)) return false; |