nir/opt_sink: Also consider load_preamble as const

Acts like constants, schedule them like constants. This lets us move lowered
frag coord code down. Results on dolphin ubers:

   total instructions in shared programs: 195144 -> 196633 (0.76%)
   instructions in affected programs: 175737 -> 177226 (0.85%)
   helped: 28
   HURT: 27
   Instructions are HURT.

   total bytes in shared programs: 1379980 -> 1388308 (0.60%)
   bytes in affected programs: 1244250 -> 1252578 (0.67%)
   helped: 28
   HURT: 27
   Bytes are HURT.

   total halfregs in shared programs: 13591 -> 13557 (-0.25%)
   halfregs in affected programs: 2176 -> 2142 (-1.56%)
   helped: 12
   HURT: 2
   Inconclusive result (%-change mean confidence interval includes 0).

   total threads in shared programs: 233728 -> 234112 (0.16%)
   threads in affected programs: 3264 -> 3648 (11.76%)
   helped: 6
   HURT: 0
   Threads are helped.

Results on Android shader-db:

   total instructions in shared programs: 1775324 -> 1775912 (0.03%)
   instructions in affected programs: 155305 -> 155893 (0.38%)
   helped: 353
   HURT: 548
   Instructions are HURT.

   total bytes in shared programs: 11676650 -> 11678454 (0.02%)
   bytes in affected programs: 1058924 -> 1060728 (0.17%)
   helped: 370
   HURT: 547
   Inconclusive result (value mean confidence interval includes 0).

   total halfregs in shared programs: 484143 -> 471212 (-2.67%)
   halfregs in affected programs: 98833 -> 85902 (-13.08%)
   helped: 2478
   HURT: 674
   Halfregs are helped.

Instr count changes due to losing the RA lottery.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24833>
This commit is contained in:
Alyssa Rosenzweig 2023-08-27 17:38:02 -04:00
parent aead5316d2
commit 4bcb62d203

View file

@ -35,6 +35,26 @@
* anscestor of consuming instructions.
*/
/*
* Detect whether a source is like a constant for the purposes of register
* pressure calculations (e.g. can be remat anywhere effectively for free).
*/
static bool
is_constant_like(nir_src *src)
{
/* Constants are constants */
if (nir_src_is_const(*src))
return true;
/* Otherwise, look for constant-like intrinsics */
nir_instr *parent = src->ssa->parent_instr;
if (parent->type != nir_instr_type_intrinsic)
return false;
return (nir_instr_as_intrinsic(parent)->intrinsic ==
nir_intrinsic_load_preamble);
}
bool
nir_can_move_instr(nir_instr *instr, nir_move_options options)
{
@ -70,7 +90,7 @@ nir_can_move_instr(nir_instr *instr, nir_move_options options)
unsigned constant_inputs = 0;
for (unsigned i = 0; i < inputs; ++i) {
if (nir_src_is_const(alu->src[i].src))
if (is_constant_like(&alu->src[i].src))
constant_inputs++;
}