Module: Mesa
Branch: staging/22.3
Commit: fd6cdd8b47d509d275d36aa6189e0cb369bfec62
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd6cdd8b47d509d275d36aa6189e0cb369bfec62

Author: Rhys Perry <[email protected]>
Date:   Thu Jan 26 16:14:26 2023 +0000

aco: limit VALUPartialForwardingHazard search

Complicated CFG and lots of SALU can cause this to take an extremely long
time to finish.

Fixes
dEQP-VK.graphicsfuzz.cov-value-tracking-selection-dag-negation-clamp-loop
and Monster Hunter Rise demo compile times.

fossil-db (gfx1100):
Totals from 57 (0.04% of 134574) affected shaders:
Instrs: 170919 -> 171165 (+0.14%)
CodeSize: 860144 -> 861128 (+0.11%)
Latency: 961466 -> 961505 (+0.00%)
InvThroughput: 127598 -> 127608 (+0.01%)

Signed-off-by: Rhys Perry <[email protected]>
Reviewed-by: Timur Kristóf <[email protected]>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8153
Fixes: 5806f0246fd ("aco/gfx11: workaround VALUPartialForwardingHazard")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20941>
(cherry picked from commit bfd4ac4581bae0d36b2c58524131f91c7c0d27ce)

---

 .pick_status.json                    |  2 +-
 src/amd/compiler/aco_insert_NOPs.cpp | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index f583bf5df09..02d5a9072eb 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -328,7 +328,7 @@
         "description": "aco: limit VALUPartialForwardingHazard search",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "5806f0246fdeba22eba4fcf2d1b4cfa03b33e886"
     },
diff --git a/src/amd/compiler/aco_insert_NOPs.cpp 
b/src/amd/compiler/aco_insert_NOPs.cpp
index 2269324e7d4..51bd5caf98d 100644
--- a/src/amd/compiler/aco_insert_NOPs.cpp
+++ b/src/amd/compiler/aco_insert_NOPs.cpp
@@ -1129,6 +1129,9 @@ struct VALUPartialForwardingHazardBlockState {
    enum VALUPartialForwardingHazardState state = nothing_written;
    unsigned num_valu_since_read = 0;
    unsigned num_valu_since_write = 0;
+
+   unsigned num_instrs = 0;
+   unsigned num_blocks = 0;
 };
 
 bool
@@ -1191,6 +1194,13 @@ 
handle_valu_partial_forwarding_hazard_instr(VALUPartialForwardingHazardGlobalSta
    if (block_state.num_vgprs_read == 0)
       return true; /* All VGPRs have been written and a hazard was never 
found. */
 
+   block_state.num_instrs++;
+   if (block_state.num_instrs > 256 || block_state.num_blocks > 32) {
+      /* Exit to limit compile times and set hazard_found=true to be safe. */
+      global_state.hazard_found = true;
+      return true;
+   }
+
    return false;
 }
 
@@ -1205,6 +1215,8 @@ 
handle_valu_partial_forwarding_hazard_block(VALUPartialForwardingHazardGlobalSta
       global_state.loop_headers_visited.insert(block->index);
    }
 
+   block_state.num_blocks++;
+
    return true;
 }
 

Reply via email to