agx: Fix subdivision coalescing
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 19 Feb 2023 04:33:12 +0000 (23:33 -0500)
committerMarge Bot <emma+marge@anholt.net>
Sat, 11 Mar 2023 14:15:50 +0000 (14:15 +0000)
As intended. We can't CSE with partial null destinations in the way, so we
shouldn't eliminate dead destinations until after CSE has run. But we should
still eliminate dead instructions to ensure CSE doesn't move things around
needlessly, hurting register pressure.

Noticed while debugging live range splitting.

No GLES3.0 shader-db changes.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21674>

src/asahi/compiler/agx_compile.c

index 06f6d3b..1e2711f 100644 (file)
@@ -2142,12 +2142,17 @@ agx_compile_function_nir(nir_shader *nir, nir_function_impl *impl,
    agx_validate(ctx, "IR translation");
 
    if (likely(!(agx_compiler_debug & AGX_DBG_NOOPT))) {
-      /* Dead code eliminate before instruction combining so use counts are
-       * right */
-      agx_dce(ctx, true);
-      agx_optimizer(ctx);
+      /* Eliminate dead instructions before CSE to avoid silly scheduling */
+      agx_dce(ctx, false);
+
+      /* CSE before eliminating dead destinations so that subdivision is
+       * optimized properly.
+       */
       agx_opt_cse(ctx);
 
+      /* After DCE, use counts are right so we can run the optimizer. */
+      agx_optimizer(ctx);
+
       /* For correctness, lower uniform sources after copyprop (for correctness,
        * as copyprop creates uniform sources). To keep register pressure in
        * check, lower after CSE, since moves are cheaper than registers.