[Mesa-dev] [PATCH 3/6] nir: Turn -(b2f(a) + b2f(b) >= 0 into !(a || b).

Ian Romanick idr at freedesktop.org
Wed Aug 10 17:58:49 UTC 2016


On 08/09/2016 07:30 PM, Kenneth Graunke wrote:
> On Haswell (GL 3.3):
> 
> total instructions in shared programs: 6211485 -> 6211427 (-0.00%)
> instructions in affected programs: 16260 -> 16202 (-0.36%)
> helped: 25
> HURT: 37
> 
> On Broadwell (GL 4.4):
> 
> total instructions in shared programs: 11640288 -> 11640218 (-0.00%)
> instructions in affected programs: 16313 -> 16243 (-0.43%)
> helped: 27
> HURT: 37

Interesting... I had a similar version of this that worked on arbitrary
length sequences of (b2f(a_0) + .. b2f(a_n)), but I didn't get any
benefit.  I also had tests for a couple other relational operators with
0 that didn't see benefit.  Maybe one of us should try to revive my old,
more generic series at some point.

For now, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/compiler/nir/nir_opt_algebraic.py | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 4e9896f..ef87d4d 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -135,6 +135,9 @@ optimizations = [
>     # inot(a)
>     (('fge', 0.0, ('b2f', a)), ('inot', a)),
>  
> +   # -(b2f(a) + b2f(b)) >= 0 becomes !(a || b)
> +   (('fge', ('fneg', ('fadd', ('b2f', 'a at bool'), ('b2f', 'b at bool'))), 0.0), ('inot', ('ior', a, b))),
> +
>     # 0.0 < fabs(a)
>     # fabs(a) > 0.0
>     # fabs(a) != 0.0 because fabs(a) must be >= 0



More information about the mesa-dev mailing list