From: Kenneth Graunke Date: Thu, 22 Jan 2015 07:47:06 +0000 (-0800) Subject: nir: Add algebraic optimizations for exponential/logarithmic functions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bbd60f6d7916d5758ba1b8d49cb0c37c1543199e;p=mesa.git nir: Add algebraic optimizations for exponential/logarithmic functions. Most of these exist in the GLSL IR algebraic pass already. However, SSA allows us to find more instances of the patterns. total NIR instructions in shared programs: 2015593 -> 2011430 (-0.21%) NIR instructions in affected programs: 124189 -> 120026 (-3.35%) helped: 604 total i965 instructions in shared programs: 6025505 -> 6018717 (-0.11%) i965 instructions in affected programs: 261295 -> 254507 (-2.60%) helped: 1295 HURT: 3 Signed-off-by: Kenneth Graunke Reviewed-by: Jason Ekstrand Reviewed-by: Matt Turner --- diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py index 40722de1ea5..42846e1202b 100644 --- a/src/glsl/nir/nir_opt_algebraic.py +++ b/src/glsl/nir/nir_opt_algebraic.py @@ -96,6 +96,16 @@ optimizations = [ (('ishr', a, 0), a), (('ushr', 0, a), 0), (('ushr', a, 0), 0), + # Exponential/logarithmic identities + (('fexp2', ('flog2', a)), a), # 2^lg2(a) = a + (('fexp', ('flog', a)), a), # e^ln(a) = a + (('flog2', ('fexp2', a)), a), # lg2(2^a) = a + (('flog', ('fexp', a)), a), # ln(e^a) = a + (('fexp2', ('fmul', ('flog2', a), b)), ('fpow', a, b)), # 2^(lg2(a)*b) = a^b + (('fexp', ('fmul', ('flog', a), b)), ('fpow', a, b)), # e^(ln(a)*b) = a^b + (('fpow', a, 1.0), a), + (('fpow', a, 2.0), ('fmul', a, a)), + (('fpow', 2.0, a), ('fexp2', a)), # This one may not be exact (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),