ir3: Model cost of phi nodes for opt_preamble
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 18 Jul 2023 20:19:03 +0000 (16:19 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 10 Oct 2023 13:51:00 +0000 (13:51 +0000)
It can be beneficial to move phi nodes, even though they can often be coalesced.
Model this cost so nir_opt_preamble can make good decisions about hoisting phi
nodes (and by extension, if-statements) into the preamble.

At this point in the series, this has no effect, but it will avoid certain
shader-db regressions associated with the nir_opt_preamble changes later in the
series.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24011>

src/freedreno/ir3/ir3_nir_opt_preamble.c

index d6463dc..86e81c2 100644 (file)
@@ -209,6 +209,18 @@ instr_cost(nir_instr *instr, const void *data)
       }
    }
 
+   case nir_instr_type_phi:
+      /* Although we can often coalesce phis, the cost of a phi is a proxy for
+       * the cost of the if-else statement... If all phis are moved, then the
+       * branches move too. So this needs to have a nonzero cost, even if we're
+       * optimistic about coalescing.
+       *
+       * Value chosen empirically. On Rob's shader-db, cost of 2 performs better
+       * across the board than a cost of 1. Values greater than 2 do not seem to
+       * have any change, so sticking with 2.
+       */
+      return 2;
+
    default:
       return 0;
    }