From 47804f53f991c3467671e05421df437b0f34eb22 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Aug 2020 11:17:28 -0700 Subject: [PATCH] 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 Reviewed-by: Adam Jackson Part-of: --- src/compiler/nir/nir_opt_peephole_select.c | 34 ++++++++++++++++++++-- 1 file 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;