[Mesa-dev] [PATCH 06/10] nir: Add a bunch of algebraic optimizations on logic/bit operations.

Matt Turner mattst88 at gmail.com
Fri Jan 23 13:49:08 PST 2015


On Thu, Jan 22, 2015 at 7:27 AM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> On Jan 22, 2015 3:41 AM, "Kenneth Graunke" <kenneth at whitecape.org> wrote:
>> Matt and I noticed a bunch of "val <- ior a a" operations in a shader,
>> so we decided to add an algebraic optimization for that.  While there,
>> I decided to add a bunch more of them.
>>
>> total NIR instructions in shared programs: 2023511 -> 2020814 (-0.13%)
>> NIR instructions in affected programs:     149634 -> 146937 (-1.80%)
>> helped:                                    1032
>>
>> i965 already cleans these up, so the final results aren't impressive:
>>
>> total i965 instructions in shared programs: 6035392 -> 6035397 (0.00%)
>> i965 instructions in affected programs:     764 -> 769 (0.65%)
>> HURT:                                       3
>>
>> However, improving the result of the NIR compile is worth doing.
>>
>> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
>> ---
>>  src/glsl/nir/nir_opt_algebraic.py | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>
>> diff --git a/src/glsl/nir/nir_opt_algebraic.py
>> b/src/glsl/nir/nir_opt_algebraic.py
>> index 169bb41..cf16b19 100644
>> --- a/src/glsl/nir/nir_opt_algebraic.py
>> +++ b/src/glsl/nir/nir_opt_algebraic.py
>> @@ -68,6 +68,22 @@ optimizations = [
>>     (('fadd', ('fmul', a, b), c), ('ffma', a, b, c)),
>>     (('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
>>     (('fmin', ('fmax', a, 1.0), 0.0), ('fsat', a)),
>> +   # Logical and bit operations
>> +   (('fand', a, a), a),
>
> This isn't correct.  The fand operation will normalize to 0.0/1.0.
>
>> +   (('fand', a, 0.0), 0.0),
>
> This is ok
>
>> +   (('iand', a, a), a),
>> +   (('iand', a, 0), 0),
>> +   (('for', a, a), a),
>> +   (('for', a, 0.0), a),
>
> Can't do these two either
>
>> +   (('ior', a, a), a),
>> +   (('ior', a, 0), a),
>> +   (('fxor', a, a), 0.0),
>
> This one should be ok
>
> With the junk optimizations removed,
> Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>

Same,

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the mesa-dev mailing list