diff --git a/src/gallium/drivers/r600/sfn/sfn_shader.cpp b/src/gallium/drivers/r600/sfn/sfn_shader.cpp index d4fe00f138c..b4d387f4d0c 100644 --- a/src/gallium/drivers/r600/sfn/sfn_shader.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_shader.cpp @@ -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; } diff --git a/src/gallium/drivers/r600/sfn/sfn_shader.h b/src/gallium/drivers/r600/sfn/sfn_shader.h index e02c981d06c..391fe42d647 100644 --- a/src/gallium/drivers/r600/sfn/sfn_shader.h +++ b/src/gallium/drivers/r600/sfn/sfn_shader.h @@ -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);