From: Alyssa Rosenzweig Date: Tue, 18 Jul 2023 20:19:03 +0000 (-0400) Subject: ir3: Model cost of phi nodes for opt_preamble X-Git-Tag: upstream/23.3.3~1069 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6576add3dc64586d3dd9dec1b6d86b4cdecf2d43;p=platform%2Fupstream%2Fmesa.git ir3: Model cost of phi nodes for opt_preamble 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 Reviewed-by: Connor Abbott Part-of: --- diff --git a/src/freedreno/ir3/ir3_nir_opt_preamble.c b/src/freedreno/ir3/ir3_nir_opt_preamble.c index d6463dc..86e81c2 100644 --- a/src/freedreno/ir3/ir3_nir_opt_preamble.c +++ b/src/freedreno/ir3/ir3_nir_opt_preamble.c @@ -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; }