nir: Add identities for the log function.
authorMatt Turner <mattst88@gmail.com>
Thu, 26 Mar 2015 17:07:58 +0000 (10:07 -0700)
committerMatt Turner <mattst88@gmail.com>
Wed, 1 Apr 2015 20:43:57 +0000 (13:43 -0700)
The rcp(log(x)) pattern affects instruction counts.

instructions in affected programs:     144 -> 138 (-4.17%)
helped:                                6

Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/nir/nir_opt_algebraic.py

index db2fe03..185c291 100644 (file)
@@ -145,6 +145,14 @@ optimizations = [
    (('frcp', ('fexp', a)), ('fexp', ('fneg', a))),
    (('frsq', ('fexp2', a)), ('fexp2', ('fmul', -0.5, a))),
    (('frsq', ('fexp', a)), ('fexp', ('fmul', -0.5, a))),
+   (('flog2', ('fsqrt', a)), ('fmul', 0.5, ('flog2', a))),
+   (('flog', ('fsqrt', a)), ('fmul', 0.5, ('flog', a))),
+   (('flog2', ('frcp', a)), ('fneg', ('flog2', a))),
+   (('flog', ('frcp', a)), ('fneg', ('flog', a))),
+   (('flog2', ('frsq', a)), ('fmul', -0.5, ('flog2', a))),
+   (('flog', ('frsq', a)), ('fmul', -0.5, ('flog', a))),
+   (('flog2', ('fpow', a, b)), ('fmul', b, ('flog2', a))),
+   (('flog', ('fpow', a, b)), ('fmul', b, ('flog', a))),
    # Division and reciprocal
    (('fdiv', 1.0, a), ('frcp', a)),
    (('frcp', ('frcp', a)), a),