r600/sfn: simplify if clauses with empty then branch
nir_opt_if doesn't catch all the possible cases of empty then branches, so resolve this on the fly when creating the backend IR. Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20141>
This commit is contained in:
@@ -693,36 +693,12 @@ Shader::process_if(nir_if *if_stmt)
|
||||
{
|
||||
SFN_TRACE_FUNC(SfnLog::flow, "IF");
|
||||
|
||||
if (!emit_if_start(if_stmt))
|
||||
return false;
|
||||
|
||||
foreach_list_typed(nir_cf_node, n, node, &if_stmt->then_list)
|
||||
{
|
||||
SFN_TRACE_FUNC(SfnLog::flow, "IF-then");
|
||||
if (!process_cf_node(n))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!child_block_empty(if_stmt->else_list)) {
|
||||
if (!emit_control_flow(ControlFlowInstr::cf_else))
|
||||
return false;
|
||||
foreach_list_typed(nir_cf_node,
|
||||
n,
|
||||
node,
|
||||
&if_stmt->else_list) if (!process_cf_node(n)) return false;
|
||||
}
|
||||
|
||||
if (!emit_control_flow(ControlFlowInstr::cf_endif))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Shader::emit_if_start(nir_if *if_stmt)
|
||||
{
|
||||
auto value = value_factory().src(if_stmt->condition, 0);
|
||||
AluInstr *pred = new AluInstr(op2_pred_setne_int,
|
||||
|
||||
EAluOp op = child_block_empty(if_stmt->then_list) ? op2_prede_int :
|
||||
op2_pred_setne_int;
|
||||
|
||||
AluInstr *pred = new AluInstr(op,
|
||||
value_factory().temp_register(),
|
||||
value,
|
||||
value_factory().zero(),
|
||||
@@ -734,6 +710,35 @@ Shader::emit_if_start(nir_if *if_stmt)
|
||||
IfInstr *ir = new IfInstr(pred);
|
||||
emit_instruction(ir);
|
||||
start_new_block(1);
|
||||
|
||||
if (!child_block_empty(if_stmt->then_list)) {
|
||||
foreach_list_typed(nir_cf_node, n, node, &if_stmt->then_list)
|
||||
{
|
||||
SFN_TRACE_FUNC(SfnLog::flow, "IF-then");
|
||||
if (!process_cf_node(n))
|
||||
return false;
|
||||
}
|
||||
if (!child_block_empty(if_stmt->else_list)) {
|
||||
if (!emit_control_flow(ControlFlowInstr::cf_else))
|
||||
return false;
|
||||
foreach_list_typed(nir_cf_node,
|
||||
n,
|
||||
node,
|
||||
&if_stmt->else_list)
|
||||
if (!process_cf_node(n)) return false;
|
||||
}
|
||||
} else {
|
||||
assert(!child_block_empty(if_stmt->else_list));
|
||||
foreach_list_typed(nir_cf_node,
|
||||
n,
|
||||
node,
|
||||
&if_stmt->else_list)
|
||||
if (!process_cf_node(n)) return false;
|
||||
}
|
||||
|
||||
if (!emit_control_flow(ControlFlowInstr::cf_endif))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,6 @@ private:
|
||||
bool read_input(std::istream& is);
|
||||
virtual bool read_prop(std::istream& is) = 0;
|
||||
|
||||
bool emit_if_start(nir_if *if_stmt);
|
||||
bool emit_control_flow(ControlFlowInstr::CFType type);
|
||||
bool emit_store_scratch(nir_intrinsic_instr *intr);
|
||||
bool emit_load_scratch(nir_intrinsic_instr *intr);
|
||||
|
||||
Reference in New Issue
Block a user