[Mesa-dev] [PATCH 1/3] i965/vec4: Call opt_algebraic after opt_cse.

Ian Romanick idr at freedesktop.org
Tue Sep 30 14:10:11 PDT 2014


On 09/27/2014 12:12 PM, Matt Turner wrote:
> The next patch adds an algebraic optimization for the pattern
> 
>    sqrt a, b
>    rcp  c, a
> 
> and turns it into
> 
>    sqrt a, b
>    rsq  c, b
> 
> but many vertex shaders do
> 
>    a = sqrt(b);
>    var1 /= a;
>    var2 /= a;
> 
> which generates
> 
>    sqrt a, b
>    rcp  c, a
>    rcp  d, a
> 
> If we apply the algebraic optimization before CSE, we'll end up with
> 
>    sqrt a, b
>    rsq  c, b
>    rcp  d, a

Why doesn't a second pass through opt_algebraic turn this into

   rsq  c, b
   rsq  d, b

Seems like this could cause us to miss other optimization opportunities...

> Applying CSE combines the RCP instructions, preventing this from
> happening.
> 
> No shader-db changes.
> ---
>  src/mesa/drivers/dri/i965/brw_vec4.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
> index 022ed37..e0a3d5f 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
> @@ -1790,8 +1790,8 @@ vec4_visitor::run()
>        OPT(dead_code_eliminate);
>        OPT(dead_control_flow_eliminate, this);
>        OPT(opt_copy_propagation);
> -      OPT(opt_algebraic);
>        OPT(opt_cse);
> +      OPT(opt_algebraic);
>        OPT(opt_register_coalesce);
>     } while (progress);
>  



More information about the mesa-dev mailing list