[Mesa-dev] [PATCH 1/5] glsl/cse: Use ir_rvalue_enter_visitor instead of ir_rvalue_visitor

Ian Romanick idr at freedesktop.org
Wed Apr 8 16:38:27 PDT 2015


From: Ian Romanick <ian.d.romanick at intel.com>

ir_rvalue_visitor visits each rvalue on exit.  When visiting a large
expression, the leaf expressions will be visited and eliminated first.
Once one leaf expression was replaced, it would no longer match a
potentially much larger tree.  This means that code like:

    x = a + (b * c);
    y = -(a + (b * c));

would effectively be replaced by

    tmp = b * c;
    x = a + tmp;
    y = -(a + tmp);

As a result both opportunities for generating a MAD would be lost, and
we would generate worse code.

Using ir_rvalue_enter_visitor means that larger expression trees will be
checked first, and we have the potential to eliminate much larger
expressions.

I believe that opt_cse.cpp predates the existence of
ir_rvalue_enter_visitor.

Shader-db results:

GM45:
total instructions in shared programs: 4063165 -> 4061744 (-0.03%)
instructions in affected programs:     21664 -> 20243 (-6.56%)
helped:                                259

GM45 NIR:
total instructions in shared programs: 4082044 -> 4080646 (-0.03%)
instructions in affected programs:     21091 -> 19693 (-6.63%)
helped:                                255
HURT:                                  1

Iron Lake:
total instructions in shared programs: 5480334 -> 5478897 (-0.03%)
instructions in affected programs:     25798 -> 24361 (-5.57%)
helped:                                273
HURT:                                  1

Iron Lake NIR:
total instructions in shared programs: 5678776 -> 5677395 (-0.02%)
instructions in affected programs:     21744 -> 20363 (-6.35%)
helped:                                263
HURT:                                  2

Sandy Bridge:
total instructions in shared programs: 7318903 -> 7316983 (-0.03%)
instructions in affected programs:     37937 -> 36017 (-5.06%)
helped:                                398
HURT:                                  26

Sandy Bridge NIR:
total instructions in shared programs: 7329995 -> 7328069 (-0.03%)
instructions in affected programs:     32487 -> 30561 (-5.93%)
helped:                                384
HURT:                                  6

Ivy Bridge:
total instructions in shared programs: 6766579 -> 6765409 (-0.02%)
instructions in affected programs:     18110 -> 16940 (-6.46%)
helped:                                288
HURT:                                  16
GAINED:                                1

Ivy Bridge NIR:
total instructions in shared programs: 6769314 -> 6768159 (-0.02%)
instructions in affected programs:     11063 -> 9908 (-10.44%)
helped:                                264
HURT:                                  6

Haswell:
total instructions in shared programs: 6226294 -> 6225102 (-0.02%)
instructions in affected programs:     17555 -> 16363 (-6.79%)
helped:                                297
HURT:                                  10
GAINED:                                1

Haswell NIR:
total instructions in shared programs: 6183693 -> 6182538 (-0.02%)
instructions in affected programs:     10990 -> 9835 (-10.51%)
helped:                                264
HURT:                                  6

Broadwell:
total instructions in shared programs: 7285895 -> 7284537 (-0.02%)
instructions in affected programs:     31977 -> 30619 (-4.25%)
helped:                                357
HURT:                                  6

Broadwell NIR:
total instructions in shared programs: 7501711 -> 7501544 (-0.00%)
instructions in affected programs:     7174 -> 7007 (-2.33%)
helped:                                87
HURT:                                  2

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/opt_cse.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/glsl/opt_cse.cpp b/src/glsl/opt_cse.cpp
index 4b8e9a0..425eebc 100644
--- a/src/glsl/opt_cse.cpp
+++ b/src/glsl/opt_cse.cpp
@@ -99,7 +99,7 @@ public:
    ir_variable *var;
 };
 
-class cse_visitor : public ir_rvalue_visitor {
+class cse_visitor : public ir_rvalue_enter_visitor {
 public:
    cse_visitor(exec_list *validate_instructions)
       : validate_instructions(validate_instructions)
-- 
2.1.0



More information about the mesa-dev mailing list