<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 28, 2015 at 4:28 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 01/27/2015 05:31 PM, Jason Ekstrand wrote:<br>
> v2 Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>>:<br>
>  - Add better comments<br>
>  - Use nir_ssa_dest_init and nir_src_for_ssa more places<br>
>  - Fix some void * casts<br>
><br>
> v3 Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>>:<br>
>  - Rework the way we determine whether or not to sccalarize a phi node to<br>
>    make the recursion non-bogus<br>
>  - Treat load_const instructions as scalarizable<br>
> ---<br>
>  src/glsl/Makefile.sources               |   1 +<br>
>  src/glsl/nir/nir.h                      |   2 +<br>
>  src/glsl/nir/nir_lower_phis_to_scalar.c | 266 ++++++++++++++++++++++++++++++++<br>
>  3 files changed, 269 insertions(+)<br>
>  create mode 100644 src/glsl/nir/nir_lower_phis_to_scalar.c<br>
><br>
> diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources<br>
> index face22e..bf6b70b 100644<br>
> --- a/src/glsl/Makefile.sources<br>
> +++ b/src/glsl/Makefile.sources<br>
> @@ -31,6 +31,7 @@ NIR_FILES = \<br>
>       nir/nir_lower_global_vars_to_local.c \<br>
>       nir/nir_lower_locals_to_regs.c \<br>
>       nir/nir_lower_io.c \<br>
> +     nir/nir_lower_phis_to_scalar.c \<br>
>       nir/nir_lower_samplers.cpp \<br>
>       nir/nir_lower_system_values.c \<br>
>       nir/nir_lower_to_source_mods.c \<br>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
> index 980fdd0..4f58eee 100644<br>
> --- a/src/glsl/nir/nir.h<br>
> +++ b/src/glsl/nir/nir.h<br>
> @@ -1526,6 +1526,8 @@ void nir_remove_dead_variables(nir_shader *shader);<br>
>  void nir_lower_vec_to_movs(nir_shader *shader);<br>
>  void nir_lower_alu_to_scalar(nir_shader *shader);<br>
><br>
> +void nir_lower_phis_to_scalar(nir_shader *shader);<br>
> +<br>
>  void nir_lower_samplers(nir_shader *shader,<br>
>                          struct gl_shader_program *shader_program,<br>
>                          struct gl_program *prog);<br>
> diff --git a/src/glsl/nir/nir_lower_phis_to_scalar.c b/src/glsl/nir/nir_lower_phis_to_scalar.c<br>
> new file mode 100644<br>
> index 0000000..a94b8b0<br>
> --- /dev/null<br>
> +++ b/src/glsl/nir/nir_lower_phis_to_scalar.c<br>
> @@ -0,0 +1,266 @@<br>
> +/*<br>
> + * Copyright © 2015 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
> + * IN THE SOFTWARE.<br>
> + *<br>
> + * Authors:<br>
> + *    Jason Ekstrand (<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>)<br>
> + *<br>
> + */<br>
> +<br>
> +#include "nir.h"<br>
> +<br>
> +/*<br>
> + * Implements a pass that lowers vector phi nodes to scalar phi nodes when<br>
> + * we don't think it will hurt anything.<br>
> + */<br>
> +<br>
> +struct lower_phis_to_scalar_state {<br>
> +   void *mem_ctx;<br>
> +   void *dead_ctx;<br>
> +<br>
> +   /* Hash table marking which phi nodes are scalarizable.  The key is<br>
> +    * pointers to phi instructions and the entry is either NULL for not<br>
> +    * scalarizable or non-null for scalarizable.<br>
> +    */<br>
> +   struct hash_table *phi_table;<br>
> +};<br>
> +<br>
> +static bool<br>
> +should_lower_phi(nir_phi_instr *phi, struct lower_phis_to_scalar_state *state);<br>
> +<br>
> +static bool<br>
> +is_phi_src_scalarizable(nir_phi_src *src,<br>
> +                        struct lower_phis_to_scalar_state *state)<br>
> +{<br>
> +   /* Don't know what to do with non-ssa sources */<br>
> +   if (!src->src.is_ssa)<br>
> +      return false;<br>
> +<br>
> +   nir_instr *src_instr = src->src.ssa->parent_instr;<br>
> +   switch (src_instr->type) {<br>
> +   case nir_instr_type_alu: {<br>
> +      nir_alu_instr *src_alu = nir_instr_as_alu(src_instr);<br>
> +<br>
> +      /* ALU operations with output_size == 0 should be scalarized.  We<br>
> +       * will also see a bunch of vecN operations from scalarizing ALU<br>
> +       * operations and, since they can easily be copy-propagated, they<br>
> +       * are ok too.<br>
> +       */<br>
> +      return nir_op_infos[src_alu->op].output_size == 0 ||<br>
> +             src_alu->op != nir_op_vec2 ||<br>
> +             src_alu->op != nir_op_vec3 ||<br>
> +             src_alu->op != nir_op_vec4;<br>
<br>
</div></div>I don't think this logic is correct.  It will return true if src_alu->op<br>
is nir_op_vec2 because that's not nir_op_vec4.  Right?<br>
<br>
</blockquote></div>Bah!  Yeah, that's completely bogus.  That said, I don't think you're looking at the latest version.<br></div></div>