Module: Mesa
Branch: main
Commit: 445ca949cd82ee84579395d69f64ae228218833d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=445ca949cd82ee84579395d69f64ae228218833d

Author: Alyssa Rosenzweig <[email protected]>
Date:   Wed Feb 15 00:02:14 2023 -0500

agx: Clean up after lowering address arithmetic

This avoids creating silly preambles that don't actually do anything except push
a constant that we could've inlined for cheaper anyway, since nir_opt_preamble's
cost model is sensitive to e.g. constant folding.

This avoids a pointless preamble in split-hell.

As a nice bonus, this also improves compile-time on address-heavy shaders. With
a release build, CPU time in dEQP-GLES31.functional.ssbo.* reduces from 12.87s
to 10.77... a 16% improvement is nothing to sneeze at.

shader-db results are mostly noise.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21430>

---

 src/asahi/compiler/agx_compile.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c
index f24cdaed1f4..2979fd50500 100644
--- a/src/asahi/compiler/agx_compile.c
+++ b/src/asahi/compiler/agx_compile.c
@@ -1907,8 +1907,19 @@ agx_optimize_nir(nir_shader *nir, unsigned 
*preamble_size)
 {
    agx_optimize_loop_nir(nir);
 
-   NIR_PASS_V(nir, agx_nir_lower_address);
-   NIR_PASS_V(nir, nir_lower_int64);
+   bool progress = false;
+   NIR_PASS(progress, nir, agx_nir_lower_address);
+
+   /* If address lowering made progress, clean up before forming preambles.
+    * Otherwise the optimized preambles might just be constants! Do it before
+    * lowering int64 too, to avoid lowering constant int64 arithmetic.
+    */
+   if (progress) {
+      NIR_PASS_V(nir, nir_opt_constant_folding);
+      NIR_PASS_V(nir, nir_opt_dce);
+   }
+
+   NIR_PASS(progress, nir, nir_lower_int64);
 
    if (likely(!(agx_debug & AGX_DBG_NOPREAMBLE)))
       NIR_PASS_V(nir, agx_nir_opt_preamble, preamble_size);

Reply via email to