nir: Perform 'weak' global value numbering in all GCM passes
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 17 Nov 2022 09:32:07 +0000 (01:32 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 14 Dec 2022 20:56:55 +0000 (20:56 +0000)
commitd5d03a7273dc12001831d6ff067c011e158873a6
treecf89f1c7ef4cc8ae0212ee0ae70d8f4483c6c230
parente930bff19e7721fefe7c827a85e3cc9871531743
nir: Perform 'weak' global value numbering in all GCM passes

Full global value numbering (GVN) can be pretty aggressive, moving
values far away from their original locations, even out of loops,
and can extend their live ranges a lot.  So we've left it disabled.

This patch introduces a weaker form of GVN: we only allow coalescing
identical values when they appear on either side of the same if/else
construct.  For now, we also only allow ALU instructions.

This allows nir_opt_gcm to clean up identical instructions appearing
on both sides of if/then/else control flow.  But it avoids aggressively
combining every other occurrence of a value in the program.

This can still have surprisingly large cascading effects, as simple
constructs are cleaned up, leading to more opportunities to do the
same clean up, up a chain of nested ifs.  It also enables greater use
of the select peephole as ifs are cleaned up.

shader-db and fossil-db results show a reduction in spills/fills on
Icelake, so it doesn't seem to be hurting register pressure.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19823>
src/compiler/nir/nir_opt_gcm.c