aco: find a scratch register for sub-dword copies on GFX7 if scc is empty
authorRhys Perry <pendingchaos02@gmail.com>
Fri, 11 Jun 2021 13:43:50 +0000 (14:43 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Sep 2021 14:36:03 +0000 (14:36 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12172>

src/amd/compiler/aco_register_allocation.cpp

index c3d13f0..95e5540 100644 (file)
@@ -1794,32 +1794,28 @@ handle_pseudo(ra_ctx& ctx, const RegisterFile& reg_file, Instruction* instr)
       if (op.isTemp() && op.regClass().is_subdword())
          reads_subdword = true;
    }
-   bool needs_scratch_reg =
-      (writes_sgpr && reads_sgpr) || (ctx.program->chip_class <= GFX7 && reads_subdword);
+   bool needs_scratch_reg = (writes_sgpr && reads_sgpr && reg_file[scc]) ||
+                            (ctx.program->chip_class <= GFX7 && reads_subdword);
    if (!needs_scratch_reg)
       return;
 
-   if (reg_file[scc]) {
-      instr->pseudo().tmp_in_scc = true;
+   instr->pseudo().tmp_in_scc = reg_file[scc];
 
-      int reg = ctx.max_used_sgpr;
-      for (; reg >= 0 && reg_file[PhysReg{(unsigned)reg}]; reg--)
+   int reg = ctx.max_used_sgpr;
+   for (; reg >= 0 && reg_file[PhysReg{(unsigned)reg}]; reg--)
+      ;
+   if (reg < 0) {
+      reg = ctx.max_used_sgpr + 1;
+      for (; reg < ctx.program->max_reg_demand.sgpr && reg_file[PhysReg{(unsigned)reg}]; reg++)
          ;
-      if (reg < 0) {
-         reg = ctx.max_used_sgpr + 1;
-         for (; reg < ctx.program->max_reg_demand.sgpr && reg_file[PhysReg{(unsigned)reg}]; reg++)
-            ;
-         if (reg == ctx.program->max_reg_demand.sgpr) {
-            assert(reads_subdword && reg_file[m0] == 0);
-            reg = m0;
-         }
+      if (reg == ctx.program->max_reg_demand.sgpr) {
+         assert(reads_subdword && reg_file[m0] == 0);
+         reg = m0;
       }
-
-      adjust_max_used_regs(ctx, s1, reg);
-      instr->pseudo().scratch_sgpr = PhysReg{(unsigned)reg};
-   } else {
-      instr->pseudo().tmp_in_scc = false;
    }
+
+   adjust_max_used_regs(ctx, s1, reg);
+   instr->pseudo().scratch_sgpr = PhysReg{(unsigned)reg};
 }
 
 bool