[Mesa-dev] [PATCH 3/3] nir: Simplify a bcsel to logical-or

Jason Ekstrand jason at jlekstrand.net
Thu Mar 31 00:37:32 UTC 2016


On Mar 30, 2016 4:24 PM, "Ian Romanick" <idr at freedesktop.org> wrote:
>
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Oddly, this did not affect the shader where I first noticed the pattern.
> That particular shader doesn't get its if-statement converted to a bcsel
> because there are two assignments in the else-statement.  This led to me
> submitting https://bugs.freedesktop.org/show_bug.cgi?id=94747.

We have code for this.  It's called nir_opt_peephole_select.  We just need
to make it more aggressive.

> shader-db results:
>
> Sandy Bridge
> total instructions in shared programs: 8467384 -> 8467069 (-0.00%)
> instructions in affected programs: 36594 -> 36279 (-0.86%)
> helped: 46
> HURT: 0
>
> total cycles in shared programs: 117573448 -> 117568518 (-0.00%)
> cycles in affected programs: 339114 -> 334184 (-1.45%)
> helped: 46
> HURT: 0
>
> Ivy Bridge / Haswell / Broadwell / Skylake:
> total instructions in shared programs: 7774258 -> 7773999 (-0.00%)
> instructions in affected programs: 30874 -> 30615 (-0.84%)
> helped: 46
> HURT: 0
>
> total cycles in shared programs: 65739190 -> 65734530 (-0.01%)
> cycles in affected programs: 180380 -> 175720 (-2.58%)
> helped: 45
> HURT: 1
>
> No change on G45 or Ironlake.
>
> I also tried these expressions, but none of them affected any shaders in
> shader-db:
>
>    (('bcsel', a, 'a at bool', 'b at bool'), ('ior', a, b)),
>    (('bcsel', a, 'b at bool', False),    ('iand', a, b)),
>    (('bcsel', a, 'b at bool', 'a at bool'), ('iand', a, b)),
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/nir/nir_opt_algebraic.py | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py
b/src/compiler/nir/nir_opt_algebraic.py
> index 5363323..59c3c36 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -126,6 +126,7 @@ optimizations = [
>     (('bcsel', ('flt', a, b), b, a), ('fmax', a, b)),
>     (('bcsel', ('inot', 'a at bool'), b, c), ('bcsel', a, c, b)),
>     (('bcsel', a, ('bcsel', a, b, c), d), ('bcsel', a, b, d)),
> +   (('bcsel', a, True, 'b at bool'), ('ior', a, b)),

Seems reasonable

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

>     (('fmin', a, a), a),
>     (('fmax', a, a), a),
>     (('imin', a, a), a),
> --
> 2.5.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160330/97334b97/attachment.html>


More information about the mesa-dev mailing list