[Mesa-dev] [PATCH 2/7] panfrost/midgard: Fix nested/chained if-else

Alyssa Rosenzweig alyssa at rosenzweig.io
Mon Feb 18 04:37:39 UTC 2019


An if-else statement is compiled to a conditional branch (from the start
to the second block) and an unconditional branch (from the end of the
first block to the end of the else). We previously incorrectly computed
the block index of the unconditional branch to be exactly one after that
of the conditional branch, valid for a single if-else statement but
nothing fancier. This patch correctly computes the unconditional branch
target, fixing more complex if-else chains.

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
---
 src/gallium/drivers/panfrost/midgard/midgard_compile.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
index de9420685f5..bcd6bf151c1 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -3182,20 +3182,20 @@ emit_if(struct compiler_context *ctx, nir_if *nif)
         int else_idx = ctx->block_count;
         int count_in = ctx->instruction_count;
         midgard_block *else_block = emit_cf_list(ctx, &nif->else_list);
+        int after_else_idx = ctx->block_count;
 
         /* Now that we have the subblocks emitted, fix up the branches */
 
         assert(then_block);
         assert(else_block);
 
-
         if (ctx->instruction_count == count_in) {
                 /* The else block is empty, so don't emit an exit jump */
                 mir_remove_instruction(then_exit);
-                then_branch->branch.target_block = else_idx + 1;
+                then_branch->branch.target_block = after_else_idx;
         } else {
                 then_branch->branch.target_block = else_idx;
-                then_exit->branch.target_block = else_idx + 1;
+                then_exit->branch.target_block = after_else_idx;
         }
 }
 
-- 
2.20.1



More information about the mesa-dev mailing list