freedreno/ir3: fix location of inserted mov's
authorRob Clark <robdclark@chromium.org>
Mon, 6 Apr 2020 15:28:35 +0000 (08:28 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 13 Apr 2020 20:47:28 +0000 (20:47 +0000)
If the group pass must insert a mov to resolve conflicts, avoid the mov
appearing *after* the meta:collect whose src it is.

The current pre-RA scheduler doesn't really care about the initial
instruction order, but the new one will in some cases.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4440>

src/freedreno/ir3/ir3_group.c

index 07d0681ceefaa66ad6fa0884b59b15b800d09f04..4fc236708d701844ce82db2103a1261fef2f14b1 100644 (file)
@@ -34,7 +34,17 @@ static void
 insert_mov(struct ir3_instruction *collect, int idx)
 {
        struct ir3_instruction *src = ssa(collect->regs[idx+1]);
-       collect->regs[idx+1]->instr = ir3_MOV(src->block, src, TYPE_F32);
+       struct ir3_instruction *mov = ir3_MOV(src->block, src, TYPE_F32);
+       collect->regs[idx+1]->instr = mov;
+
+       /* if collect and src are in the same block, move the inserted mov
+        * to just before the collect to avoid a use-before-def.  Otherwise
+        * it should be safe to leave at the end of the block it is in:
+        */
+       if (src->block == collect->block) {
+               list_delinit(&mov->node);
+               list_addtail(&mov->node, &collect->node);
+       }
 }
 
 /* verify that cur != instr, but cur is also not in instr's neighbor-list: */