[Mesa-dev] [PATCH 1/6] glsl: Optimize ~~x into x.

Ian Romanick idr at freedesktop.org
Mon Jan 20 11:49:49 PST 2014


On 01/19/2014 11:18 PM, Eric Anholt wrote:
> ---
>  src/glsl/opt_algebraic.cpp | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 332f0b7..6b0d992 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -218,6 +218,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>        this->mem_ctx = ralloc_parent(ir);
>  
>     switch (ir->operation) {
> +   case ir_unop_bit_not:
> +      if (op_expr[0] == NULL)
> +	 break;
> +
> +      switch (op_expr[0]->operation) {
> +      case ir_unop_bit_not:
> +         return abs(op_expr[0]->operands[0]);

abs?  Looks like a copy and paste bug.

Also, could this merge with the neg path?

      case ir_unop_bit_not:
      case ir_unop_neg:
         if (op_expr[0] == NULL)
            break;

         if (op_expr[0]->operation == ir->operation)
            return op_expr[0]->operands[0];
         break;


> +      default:
> +         break;
> +      }
> +      break;
> +
>     case ir_unop_abs:
>        if (op_expr[0] == NULL)
>  	 break;
> 



More information about the mesa-dev mailing list