[Mesa-dev] [PATCH] glsl: Optimize (x + y cmp 0) into (x cmp -y).

Ian Romanick idr at freedesktop.org
Fri Apr 4 15:47:33 PDT 2014


And we don't need to explicitly handle (x - y cmp 0) becuase we've
already converted x - y into x + -y.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 04/04/2014 03:27 PM, Matt Turner wrote:
> Cuts a small handful of instructions in Serious Sam 3:
> 
> instructions in affected programs:     4692 -> 4666 (-0.55%)
> ---
>  src/glsl/opt_algebraic.cpp | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 8494bd9..2db877d 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 */
> 



More information about the mesa-dev mailing list