We propagate negations to the right-most leaves of the multiplication expression trees:
- mul(neg(x), neg(y)) -> mul(x, y) - mul(neg(x), y) -> neg(mul(x, y)) - mul(x, neg(y)) -> neg(mul(x, y)) total instructions in shared programs: 5943123 -> 5937229 (-0.10%) instructions in affected programs: 868221 -> 862327 (-0.68%) helped: 4518 HURT: 356 GAINED: 1 --- src/glsl/opt_algebraic.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index 7bc65da..aecd6e1 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -514,6 +514,20 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) if (is_vec_negative_one(op_const[1])) return neg(ir->operands[0]); + if (op_expr[0] && op_expr[0]->operation == ir_unop_neg) { + if (op_expr[1] && op_expr[1]->operation == ir_unop_neg) { + /* mul(neg(x), neg(y)) -> mul(x, y) */ + return mul(op_expr[0]->operands[0], op_expr[1]->operands[0]); + } + + /* mul(neg(x), y) -> neg(mul(x, y)) */ + return neg(mul(op_expr[0]->operands[0], ir->operands[1])); + } + + /* mul(x, neg(y)) -> neg(mul(x, y)) */ + if (op_expr[1] && op_expr[1]->operation == ir_unop_neg) { + return neg(mul(ir->operands[0], op_expr[1]->operands[0])); + } /* Reassociate multiplication of constants so that we can do * constant folding. -- 2.0.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev