[Mesa-dev] [PATCH] nir: remove some redundant bcsel instructions
Ian Romanick
idr at freedesktop.org
Thu Oct 18 22:01:59 UTC 2018
On 10/16/2018 08:49 PM, Timothy Arceri wrote:
> For example:
>
> vec1 32 ssa_386 = feq ssa_333.x, ssa_6
> vec1 32 ssa_387 = feq ssa_333.x, ssa_2
> vec1 32 ssa_391 = bcsel ssa_387, ssa_388, ssa_324
> vec1 32 ssa_396 = bcsel ssa_386, ssa_324, ssa_391
>
> Can be simplified to:
>
> vec1 32 ssa_386 = feq ssa_333.x, ssa_6
> vec1 32 ssa_391 = bcsel ssa_387, ssa_388, ssa_324
>
> There are a bunch of these in Rise of The Tomb Raiders Vulkan
> shaders. There are also a hadful of shaders helped in shader-db
> but the changes there are smaller.
>
> For RADV:
>
> Totals from affected shaders:
> SGPRS: 11184 -> 11168 (-0.14 %)
> VGPRS: 11484 -> 11484 (0.00 %)
> Spilled SGPRs: 1119 -> 1116 (-0.27 %)
> Spilled VGPRs: 0 -> 0 (0.00 %)
> Private memory VGPRs: 0 -> 0 (0.00 %)
> Scratch size: 0 -> 0 (0.00 %) dwords per thread
> Code Size: 1210856 -> 1210372 (-0.04 %) bytes
> LDS: 0 -> 0 (0.00 %) blocks
> Max Waves: 360 -> 360 (0.00 %)
> Wait states: 0 -> 0 (0.00 %)
> ---
> src/compiler/nir/nir_opt_algebraic.py | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index cc747250ba5..7530710cbe0 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -34,6 +34,7 @@ a = 'a'
> b = 'b'
> c = 'c'
> d = 'd'
> +e = 'e'
>
> # Written in the form (<search>, <replace>) where <search> is an expression
> # and <replace> is either an expression or a value. An expression is
> @@ -525,6 +526,9 @@ optimizations = [
> # The result of this should be hit by constant propagation and, in the
> # next round of opt_algebraic, get picked up by one of the above two.
> (('bcsel', '#a', b, c), ('bcsel', ('ine', 'a', 0), b, c)),
> + # Remove redundant bcsel
> + (('bcsel', ('ieq', '#a', b), c, ('bcsel', ('ieq', '#d', b), e, c)), ('bcsel', ('ieq', d, b), e, c)),
> + (('bcsel', ('feq', '#a', b), c, ('bcsel', ('feq', '#d', b), e, c)), ('bcsel', ('feq', d, b), e, c)),
There are a bunch of similar bcsel-of-bcsel patterns around line 296. I
think these should go up there.
As for enforcing the a != d restriction, I've been thinking of adding
some extra functions that could be invoked from the 'options->foo' field
to enforce things like this.
It seems like in one of the patches that recognized open-coded flrp I
wanted to detect cases where #a == -2.0 * #b. Instead I had to just
hard code 2.0 and -1.0 since those were the most common cases. I think
I was converting (ffma 2.0, a, -1.0) to (flrp -1.0, 1.0, a). I can't
seem to find that patch. :( I think I also had a patch where I wanted
to restrict #a == -#b.
>
> (('bcsel', a, b, b), b),
> (('fcsel', a, b, b), b),
More information about the mesa-dev
mailing list