pan/bi: Optimize out redundant jumps to #0x0
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 18 Feb 2021 18:53:33 +0000 (13:53 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 22 Feb 2021 17:12:55 +0000 (17:12 +0000)
If it's the last instruction, that's silly.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9137>

src/panfrost/bifrost/bifrost_compile.c

index baf67ff..ee938cd 100644 (file)
@@ -2895,6 +2895,13 @@ bi_lower_branch(bi_block *block)
 
                 if (bi_is_terminal_block(ins->branch_target))
                         ins->branch_target = NULL;
+
+                /* If there is nowhere to go, there is no point in branching */
+                if (bi_is_terminal_block((bi_block *) block->base.successors[0]) &&
+                        bi_is_terminal_block((bi_block *) block->base.successors[1]) &&
+                        ins->branch_target == NULL) {
+                        bi_remove_instruction(ins);
+                }
         }
 }