[Mesa-dev] [PATCH 03/10] nir: add helpers to check if we can unroll loops

Erik Faye-Lund kusmabite at gmail.com
Fri Sep 16 14:52:33 UTC 2016


On Thu, Sep 15, 2016 at 9:03 AM, Timothy Arceri
<timothy.arceri at collabora.com> wrote:
> This will be used by the loop unroll and lcssa passes.
>
> V2:
> - Check instruction count is not too large for unrolling
> - Add helper for complex loop unrolling
> ---
>  src/compiler/nir/nir.h | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 49e8cd8..3a2a13a 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2590,6 +2590,37 @@ bool nir_normalize_cubemap_coords(nir_shader *shader);
>
>  void nir_live_ssa_defs_impl(nir_function_impl *impl);
>
> +static inline bool
> +is_loop_small_enough_to_unroll(nir_shader *shader, nir_loop_info *li)
> +{
> +   unsigned max_iter = shader->options->max_unroll_iterations;
> +
> +   if (li->trip_count > max_iter)
> +      return false;
> +
> +   if (li->force_unroll)
> +      return true;
> +
> +   bool loop_not_too_large =
> +      li->num_instructions * li->trip_count <= max_iter * 25;


"max_iter * 25" seems like a pretty arbirary limit at first glance.
How was it found? Perhaps a comment explaining a bit could be added?

> +static inline bool
> +is_complex_loop(nir_shader *shader, nir_loop_info *li)
> +{
> +   unsigned num_lt = list_length(&li->loop_terminator_list);
> +   return is_loop_small_enough_to_unroll(shader, li) && num_lt == 2;

Perhaps you could add a comment to explain the "num_lt == 2"-part?


More information about the mesa-dev mailing list