[Mesa-dev] [PATCH 5/8] nir: Add addition/multiplication identities of exp/log.

Matt Turner mattst88 at gmail.com
Fri Mar 27 17:03:28 PDT 2015


On Fri, Mar 27, 2015 at 11:56 AM, Eric Anholt <eric at anholt.net> wrote:
> Matt Turner <mattst88 at gmail.com> writes:
>
>> instructions in affected programs:     2858 -> 2808 (-1.75%)
>> helped:                                12
>> ---
>>  src/glsl/nir/nir_opt_algebraic.py | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
>> index 6730408..34a401a 100644
>> --- a/src/glsl/nir/nir_opt_algebraic.py
>> +++ b/src/glsl/nir/nir_opt_algebraic.py
>> @@ -149,6 +149,14 @@ optimizations = [
>>     (('flog', ('frsq', a)), ('fmul', -0.5, ('flog', a))),
>>     (('flog2', ('fpow', a, b)), ('fmul', b, ('flog2', a))),
>>     (('flog', ('fpow', a, b)), ('fmul', b, ('flog', a))),
>> +   (('fadd', ('flog2', a), ('flog2', b)), ('flog2', ('fmul', a, b))),
>> +   (('fadd', ('flog', a), ('flog', b)), ('flog', ('fmul', a, b))),
>> +   (('fadd', ('flog2', a), ('fneg', ('flog2', b))), ('flog2', ('fdiv', a, b))),
>> +   (('fadd', ('flog', a), ('fneg', ('flog', b))), ('flog', ('fdiv', a, b))),
>
>> +   (('fmul', ('fexp2', a), ('fexp2', a)), ('fmul', 2.0, ('fexp2', a))),
>> +   (('fmul', ('fexp', a), ('fexp', a)), ('fmul', 2.0, ('fexp', a))),
>
>
> e^a * e^a -> 2 * e^a?  This doesn't seem right.  And something specific
> to this doesn't seem particularly better than the general case below.

Whoops. That was supposed to be e^a * e^a = e^2a.

When I added the two patterns below, I hit a case where they were
increasing instruction counts because 'a' was the same expression as
'b' but upon removing the two patterns above I can't find it.

I'll just remove them.

Thanks!

>> +   (('fmul', ('fexp2', a), ('fexp2', b)), ('fexp2', ('fadd', a, b))),
>> +   (('fmul', ('fexp', a), ('fexp', b)), ('fexp', ('fadd', a, b))),


More information about the mesa-dev mailing list