[Mesa-dev] [PATCH 4/3] glsl: tidy up IR after loop unrolling

Nicolai Hähnle nhaehnle at gmail.com
Mon Oct 9 14:28:36 UTC 2017


On 22.09.2017 01:49, Timothy Arceri wrote:
> c7affbf6875622a enabled GLSLOptimizeConservatively on some
> drivers. The idea was to speed up compile times by running
> the GLSL IR passes only once each time do_common_optimization()
> is called. However loop unrolling can create a big mess and
> with large loops can actually case compile times to increase
> significantly due to a bunch of redundant if statements being
> propagated to other IRs.
> 
> Here we make sure to clean things up before moving on.
> 
> There was no measureable difference in shader-db compile times,
> but it makes compile times of some piglit tests go from a couple
> of seconds to basically instant.
> 
> The shader-db results seemed positive also:
> 
> Totals:
> SGPRS: 2829456 -> 2828376 (-0.04 %)
> VGPRS: 1720793 -> 1721457 (0.04 %)
> Spilled SGPRs: 7707 -> 7707 (0.00 %)
> Spilled VGPRs: 33 -> 33 (0.00 %)
> Private memory VGPRs: 3140 -> 2060 (-34.39 %)
> Scratch size: 3308 -> 2180 (-34.10 %) dwords per thread
> Code Size: 79441464 -> 79214616 (-0.29 %) bytes
> LDS: 436 -> 436 (0.00 %) blocks
> Max Waves: 558670 -> 558571 (-0.02 %)
> Wait states: 0 -> 0 (0.00 %)
> ---
>   src/compiler/glsl/glsl_parser_extras.cpp | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
> index 9cbc2355f9..764c05ad80 100644
> --- a/src/compiler/glsl/glsl_parser_extras.cpp
> +++ b/src/compiler/glsl/glsl_parser_extras.cpp
> @@ -2209,21 +2209,27 @@ do_common_optimization(exec_list *ir, bool linked,
>      OPT(lower_vector_insert, ir, false);
>      OPT(do_swizzle_swizzle, ir);
>      OPT(do_noop_swizzle, ir);
>   
>      OPT(optimize_split_arrays, ir, linked);
>      OPT(optimize_redundant_jumps, ir);
>   
>      if (options->MaxUnrollIterations) {
>         loop_state *ls = analyze_loop_variables(ir);
>         if (ls->loop_found) {
> -         OPT(unroll_loops, ir, ls, options);
> +         bool loop_progress = unroll_loops(ir, ls, options);
> +         while (loop_progress) {
> +            loop_progress = false;
> +            loop_progress |= do_constant_propagation(ir);
> +            loop_progress |= do_if_simplification(ir);
> +         }
> +         progress |= loop_progress;

It would be nice to keep the debug output when debug == true. Although 
that could be done as a follow-up, since the existing OPT macro doesn't 
easily work for it.

I've sent two minor comments on patch #3, with those fixed the series is

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

>         }
>         delete ls;
>      }
>   
>   #undef OPT
>   
>      return progress;
>   }
>   
>   extern "C" {
> 


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list