[Mesa-dev] [PATCH 4/9] nir: Add a flag for lowering fsqrt(x) to frcp(frsqrt(x)).

Eric Anholt eric at anholt.net
Sun Feb 1 13:17:23 PST 2015


vc4 cse/algebraic-disabled stats:
total uniforms in shared programs: 13972 -> 13966 (-0.04%)
uniforms in affected programs:     408 -> 402 (-1.47%)
total instructions in shared programs: 44973 -> 44911 (-0.14%)
instructions in affected programs:     1551 -> 1489 (-4.00%)
---
 src/gallium/drivers/vc4/vc4_program.c | 1 +
 src/glsl/nir/nir.h                    | 1 +
 src/glsl/nir/nir_opt_algebraic.py     | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 806ac6f..fd818b4 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -2099,6 +2099,7 @@ nir_to_qir(struct vc4_compile *c)
 
 static const nir_shader_compiler_options nir_options = {
         .lower_fpow = true,
+        .lower_fsqrt = true,
 };
 
 static struct vc4_compile *
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index a2163ed..b0ad4b0 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1328,6 +1328,7 @@ typedef struct nir_function {
 
 typedef struct nir_shader_compiler_options {
    bool lower_fpow;
+   bool lower_fsqrt;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader {
diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index 41bfe04..2020997 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -117,7 +117,8 @@ optimizations = [
    (('fdiv', 1.0, a), ('frcp', a)),
    (('frcp', ('frcp', a)), a),
    (('frcp', ('fsqrt', a)), ('frsq', a)),
-   (('frcp', ('frsq', a)), ('fsqrt', a)),
+   (('fsqrt', a), ('frcp', ('frsq', a)), 'options->lower_fsqrt'),
+   (('frcp', ('frsq', a)), ('fsqrt', a), '!options->lower_fsqrt'),
    # Boolean simplifications
    (('ine', 'a at bool', 0), 'a'),
    (('ieq', 'a at bool', 0), ('inot', 'a')),
-- 
2.1.4



More information about the mesa-dev mailing list