Mesa (master): aco: split self-intersecting copies instead of swapping

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 28 23:29:08 UTC 2020


Module: Mesa
Branch: master
Commit: 09c584caeb2a1e7446ac2016ce7a7d8f0586774b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=09c584caeb2a1e7446ac2016ce7a7d8f0586774b

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Mon Apr 27 20:13:53 2020 +0100

aco: split self-intersecting copies instead of swapping

Example situation:
v1 = {v0.hi, v1.lo}
v0.hi = v1.hi

The 4-byte copy's definition is completely used, but swapping it makes no
sense. We have to split it to generate correct code:
swap(v0.hi, v1.lo)
swap(v0.hi, v1.hi)

Found in dEQP-VK.spirv_assembly.type.vec3.i16.constant_composite_vert

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4772>

---

 src/amd/compiler/aco_lower_to_hw_instr.cpp | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp
index 6e826dbf048..6f051200b53 100644
--- a/src/amd/compiler/aco_lower_to_hw_instr.cpp
+++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp
@@ -1091,6 +1091,39 @@ void handle_operands(std::map<PhysReg, copy_operation>& copy_map, lower_context*
 
       /* to resolve the cycle, we have to swap the src reg with the dst reg */
       copy_operation swap = it->second;
+
+      /* if this is self-intersecting, we have to split it because
+       * self-intersecting swaps don't make sense */
+      PhysReg lower = swap.def.physReg();
+      PhysReg higher = swap.op.physReg();
+      if (lower.reg_b > higher.reg_b)
+         std::swap(lower, higher);
+      if (higher.reg_b - lower.reg_b < (int)swap.bytes) {
+         unsigned offset = higher.reg_b - lower.reg_b;
+         RegType type = swap.def.regClass().type();
+
+         copy_operation middle;
+         lower.reg_b += offset;
+         higher.reg_b += offset;
+         middle.bytes = swap.bytes - offset * 2;
+         memcpy(middle.uses, swap.uses + offset, middle.bytes);
+         middle.op = Operand(lower, RegClass::get(type, middle.bytes));
+         middle.def = Definition(higher, RegClass::get(type, middle.bytes));
+         copy_map[higher] = middle;
+
+         copy_operation end;
+         lower.reg_b += middle.bytes;
+         higher.reg_b += middle.bytes;
+         end.bytes = swap.bytes - (offset + middle.bytes);
+         memcpy(end.uses, swap.uses + offset + middle.bytes, end.bytes);
+         end.op = Operand(lower, RegClass::get(type, end.bytes));
+         end.def = Definition(higher, RegClass::get(type, end.bytes));
+         copy_map[higher] = end;
+
+         memset(swap.uses + offset, 0, swap.bytes - offset);
+         swap.bytes = offset;
+      }
+
       do_swap(ctx, bld, swap, preserve_scc, pi);
 
       /* remove from map */



More information about the mesa-commit mailing list