These will optimize any tree of a commutative and associative operation that contains more than one constant to have only one constant in the end. For example, it will optimize
((4 * a) * b) * (5 * c) into 20 * ((a * b) * c) Note that when we port Matt's tree balancing pass, we'll have to think carefully to make sure they don't fight. Signed-off-by: Connor Abbott <cwabbo...@gmail.com> --- src/glsl/nir/nir_opt_algebraic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py index a5fe19a..f4466b4 100644 --- a/src/glsl/nir/nir_opt_algebraic.py +++ b/src/glsl/nir/nir_opt_algebraic.py @@ -128,6 +128,16 @@ optimizations = [ # next round of opt_algebraic, get picked up by one of the above two. (('bcsel', '#a', b, c), ('bcsel', ('ine', 'a', 0), b, c)), + # constant reassociation + # the idea is that we make sure each expression tree always ends with + # "constant thing plus tree of non-constant things' + (('!a@associative,commutative', '#a', ('!a', '#b', 'c')), + ('!a', ('!a', 'a', 'b'), 'c')), + (('!a@associative,commutative', ('!a', '#a', 'b'), ('!a', '#c', 'd')), + ('!a', ('!a', 'a', 'c'), ('!a', 'b', 'd'))), + (('!a@associative,commutative', ('!a', '#a', 'b'), 'c'), + ('!a', 'a', ('!a', 'b', 'c'))), + # This one may not be exact (('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))), ] -- 2.1.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev