diff options
author | Matt Turner <[email protected]> | 2014-03-29 12:31:24 -0700 |
---|---|---|
committer | Matt Turner <[email protected]> | 2014-04-05 09:47:37 -0700 |
commit | 34ec1a24d61f8b2f6ed58efa9fe7ea8cec917612 (patch) | |
tree | 0d157306f5281dd7892232d2543886bdc5a4f2de /src/glsl/opt_algebraic.cpp | |
parent | 6499ecafa5ffd8c3c62ac449a78ecefdbdd7dbbd (diff) |
glsl: Optimize (x + y cmp 0) into (x cmp -y).
Cuts a small handful of instructions in Serious Sam 3:
instructions in affected programs: 4692 -> 4666 (-0.55%)
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r-- | src/glsl/opt_algebraic.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index 8494bd9ec53..2db877d5b8b 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -445,6 +445,28 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) } break; + case ir_binop_less: + case ir_binop_lequal: + case ir_binop_greater: + case ir_binop_gequal: + case ir_binop_equal: + case ir_binop_nequal: + for (int add_pos = 0; add_pos < 2; add_pos++) { + ir_expression *add = op_expr[add_pos]; + + if (!add || add->operation != ir_binop_add) + continue; + + ir_constant *zero = op_const[1 - add_pos]; + if (!is_vec_zero(zero)) + continue; + + return new(mem_ctx) ir_expression(ir->operation, + add->operands[0], + neg(add->operands[1])); + } + break; + case ir_binop_rshift: case ir_binop_lshift: /* 0 >> x == 0 */ |