Mesa (master): aco: decrease the uses of other copy operations after splitting/removing

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 23 11:49:28 UTC 2020


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

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Wed Apr 22 21:56:02 2020 +0100

aco: decrease the uses of other copy operations after splitting/removing

For copies like v[7:8] = v[8:9], what currently happens is:
- do_copy() will skip the second dword
- the uses of the second dword will be reduced to 0
- the copy operation will be removed from the map
and v8 will never be set to v9.

So just decrease the uses of other operations after splitting or removing
the current operation, so: "v8 = v9" will be split off, it's uses reduced
and then the new copy will be done in the next iteration.

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/4686>

---

 src/amd/compiler/aco_lower_to_hw_instr.cpp | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp
index da381dc7ced..6e826dbf048 100644
--- a/src/amd/compiler/aco_lower_to_hw_instr.cpp
+++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp
@@ -1006,17 +1006,7 @@ void handle_operands(std::map<PhysReg, copy_operation>& copy_map, lower_context*
 
       bool did_copy = do_copy(ctx, bld, it->second, &preserve_scc);
 
-      /* reduce the number of uses of the operand reg by one */
-      if (did_copy && !it->second.op.isConstant()) {
-         for (std::pair<const PhysReg, copy_operation>& copy : copy_map) {
-             for (uint16_t i = 0; i < copy.second.bytes; i++) {
-               /* distance might underflow */
-               unsigned distance = copy.first.reg_b + i - it->second.op.physReg().reg_b;
-               if (distance < it->second.bytes && !it->second.uses[distance])
-                  copy.second.uses[i] -= 1;
-            }
-         }
-      }
+      std::pair<PhysReg, copy_operation> copy = *it;
 
       if (it->second.is_used == 0) {
          /* the target reg is not used as operand for any other copy, so we
@@ -1047,6 +1037,20 @@ void handle_operands(std::map<PhysReg, copy_operation>& copy_map, lower_context*
 
          it = copy_map.begin();
       }
+
+      /* Reduce the number of uses of the operand reg by one. Do this after
+       * splitting the copy or removing it in case the copy writes to it's own
+       * operand (for example, v[7:8] = v[8:9]) */
+      if (did_copy && !copy.second.op.isConstant()) {
+         for (std::pair<const PhysReg, copy_operation>& other : copy_map) {
+             for (uint16_t i = 0; i < other.second.bytes; i++) {
+               /* distance might underflow */
+               unsigned distance = other.first.reg_b + i - copy.second.op.physReg().reg_b;
+               if (distance < copy.second.bytes && !copy.second.uses[distance])
+                  other.second.uses[i] -= 1;
+            }
+         }
+      }
    }
 
    if (copy_map.empty())



More information about the mesa-commit mailing list