From ae20bee75e9de3698dd40fb13e7e1324186536ed Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 6 Jun 2019 11:19:13 -0700 Subject: [PATCH] panfrost/midgard: Cull dead branches This fixes bugs with complex control flow. Signed-off-by: Alyssa Rosenzweig --- .../drivers/panfrost/ci/expected-failures.txt | 2 -- .../panfrost/midgard/midgard_compile.c | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/panfrost/ci/expected-failures.txt b/src/gallium/drivers/panfrost/ci/expected-failures.txt index cd80d78169d..0ea3543a16c 100644 --- a/src/gallium/drivers/panfrost/ci/expected-failures.txt +++ b/src/gallium/drivers/panfrost/ci/expected-failures.txt @@ -304,8 +304,6 @@ dEQP-GLES2.functional.polygon_offset.fixed16_render_with_units dEQP-GLES2.functional.polygon_offset.fixed16_result_depth_clamp dEQP-GLES2.functional.rasterization.limits.points dEQP-GLES2.functional.shaders.builtin_variable.fragcoord_w -dEQP-GLES2.functional.shaders.functions.control_flow.return_in_loop_if_fragment -dEQP-GLES2.functional.shaders.functions.control_flow.return_in_loop_if_vertex dEQP-GLES2.functional.shaders.preprocessor.predefined_macros.line_2_fragment dEQP-GLES2.functional.shaders.preprocessor.predefined_macros.line_2_vertex dEQP-GLES2.functional.shaders.random.all_features.fragment.0 diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c index 92bfe51ce85..faf5d086518 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c +++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c @@ -1713,6 +1713,30 @@ midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block) return progress; } +/* Dead code elimination for branches at the end of a block - only one branch + * per block is legal semantically */ + +static void +midgard_opt_cull_dead_branch(compiler_context *ctx, midgard_block *block) +{ + bool branched = false; + + mir_foreach_instr_in_block_safe(block, ins) { + if (!midgard_is_branch_unit(ins->unit)) continue; + + /* We ignore prepacked branches since the fragment epilogue is + * just generally special */ + if (ins->prepacked_branch) continue; + + if (branched) { + /* We already branched, so this is dead */ + mir_remove_instruction(ins); + } + + branched = true; + } +} + static bool mir_nontrivial_mod(midgard_vector_alu_src src, bool is_int, unsigned mask) { @@ -2401,6 +2425,13 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl } } while (progress); + /* Nested control-flow can result in dead branches at the end of the + * block. This messes with our analysis and is just dead code, so cull + * them */ + mir_foreach_block(ctx, block) { + midgard_opt_cull_dead_branch(ctx, block); + } + /* Schedule! */ schedule_program(ctx); -- 2.30.2