panfrost/midgard: Check write-before-read in liveness analysis
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 19 Jul 2019 19:11:09 +0000 (12:11 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 22 Jul 2019 15:20:34 +0000 (08:20 -0700)
If we write to an index before reading it, the old copy we're checking
liveness for isn't live in this block, even if it does get read later.
Fixes abnormally high register pressure in shaders with loops.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/midgard_liveness.c

index a18d8b9..899c8ea 100644 (file)
@@ -60,11 +60,24 @@ is_live_after_successors(compiler_context *ctx, midgard_block *bl, int src)
 
                 succ->visited = true;
 
+                /* Within this block, check if it's overwritten first */
+                bool block_done = false;
+
                 mir_foreach_instr_in_block(succ, ins) {
                         if (midgard_is_live_in_instr(ins, src))
                                 return true;
+
+                        /* If written-before-use, we're gone */
+
+                        if (ins->ssa_args.dest == src && ins->type == TAG_LOAD_STORE_4 && ins->load_store.op == midgard_op_ld_int4 && ins->load_store.unknown == 0x1EEA) {
+                                block_done = true;
+                                break;
+                        }
                 }
 
+                if (block_done)
+                        continue;
+
                 /* ...and also, check *its* successors */
                 if (is_live_after_successors(ctx, succ, src))
                         return true;