From: Ian Romanick <ian.d.roman...@intel.com> Invert the condition and just emit the non-empty else-branch.
total instructions in shared programs: 8448571 -> 8448373 (-0.00%) instructions in affected programs: 20880 -> 20682 (-0.95%) helped: 114 HURT: 0 Jason suggested that there were several places that tried to determine that a flow control path had no instructions and the code should be refactored. Using 'grep -r is_empty' in src/mesa/drivers/dri/i965 and src/compiler/nir, I could not find any such locations. As a result, I just open coded the check. Did I just miss the other occurrences? Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp index db20c71..06e8aff 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp @@ -417,13 +417,21 @@ fs_visitor::nir_emit_if(nir_if *if_stmt) BRW_REGISTER_TYPE_D)); inst->conditional_mod = BRW_CONDITIONAL_NZ; - bld.IF(BRW_PREDICATE_NORMAL); + fs_inst *if_inst = bld.IF(BRW_PREDICATE_NORMAL); - nir_emit_cf_list(&if_stmt->then_list); + const nir_cf_node *const cf = nir_if_first_then_node(if_stmt); + const nir_block *const block = nir_cf_node_as_block(cf); - /* note: if the else is empty, dead CF elimination will remove it */ - bld.emit(BRW_OPCODE_ELSE); + /* If the then-list has no instructions, don't emit it. */ + if (nir_cf_node_is_last(cf) && block->instr_list.is_empty()) { + if_inst->predicate_inverse = true; + } else { + nir_emit_cf_list(&if_stmt->then_list); + bld.emit(BRW_OPCODE_ELSE); + } + + /* note: if the else is empty, dead CF elimination will remove it */ nir_emit_cf_list(&if_stmt->else_list); bld.emit(BRW_OPCODE_ENDIF); -- 2.5.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev