panfrost/midgard: Cull dead branches
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 6 Jun 2019 18:19:13 +0000 (11:19 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 7 Jun 2019 16:05:28 +0000 (09:05 -0700)
This fixes bugs with complex control flow.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/ci/expected-failures.txt
src/gallium/drivers/panfrost/midgard/midgard_compile.c

index cd80d78169dde4a49ce00c75c8371d0554f8e1cb..0ea3543a16c408ce81e3a1f01ec03e0734985b2e 100644 (file)
@@ -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
index 92bfe51ce854038c3126c9743d601ba21087e5b2..faf5d086518475af5681e916827e5ed3d06e8a7b 100644 (file)
@@ -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);