<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 17, 2014 at 2:26 PM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<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 Wed, Dec 17, 2014 at 5:20 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
><br>
><br>
> On Wed, Dec 17, 2014 at 1:10 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> wrote:<br>
>><br>
>><br>
>><br>
>> On Wed, Dec 17, 2014 at 12:07 PM, Connor Abbott <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> On Tue, Dec 16, 2014 at 1:04 AM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
>>> wrote:<br>
>>> > From: Connor Abbott <<a href="mailto:connor.abbott@intel.com">connor.abbott@intel.com</a>><br>
>>> ><br>
>>> > ---<br>
>>> > src/glsl/Makefile.sources | 1 +<br>
>>> > src/glsl/nir/nir.h | 3 +<br>
>>> > src/glsl/nir/nir_opt_copy_propagate.c | 313<br>
>>> > ++++++++++++++++++++++++++++++++++<br>
>>> > 3 files changed, 317 insertions(+)<br>
>>> > create mode 100644 src/glsl/nir/nir_opt_copy_propagate.c<br>
>>> ><br>
>>> > diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources<br>
>>> > index 0aaea58..556648b 100644<br>
>>> > --- a/src/glsl/Makefile.sources<br>
>>> > +++ b/src/glsl/Makefile.sources<br>
>>> > @@ -25,6 +25,7 @@ NIR_FILES = \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_lower_variables_scalar.c \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_opcodes.c \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_opcodes.h \<br>
>>> > + $(GLSL_SRCDIR)/nir/nir_opt_copy_propagate.c \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_opt_global_to_local.c \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_print.c \<br>
>>> > $(GLSL_SRCDIR)/nir/nir_remove_dead_variables.c \<br>
>>> > diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
>>> > index c2b4724..a5cb5ed 100644<br>
>>> > --- a/src/glsl/nir/nir.h<br>
>>> > +++ b/src/glsl/nir/nir.h<br>
>>> > @@ -1293,6 +1293,9 @@ void nir_convert_to_ssa(nir_shader *shader);<br>
>>> ><br>
>>> > bool nir_opt_global_to_local(nir_shader *shader);<br>
>>> ><br>
>>> > +bool nir_copy_prop_impl(nir_function_impl *impl);<br>
>>> > +bool nir_copy_prop(nir_shader *shader);<br>
>>> > +<br>
>>> > #ifdef __cplusplus<br>
>>> > } /* extern "C" */<br>
>>> > #endif<br>
>>> > diff --git a/src/glsl/nir/nir_opt_copy_propagate.c<br>
>>> > b/src/glsl/nir/nir_opt_copy_propagate.c<br>
>>> > new file mode 100644<br>
>>> > index 0000000..a2be047<br>
>>> > --- /dev/null<br>
>>> > +++ b/src/glsl/nir/nir_opt_copy_propagate.c<br>
>>> > @@ -0,0 +1,313 @@<br>
>>> > +/*<br>
>>> > + * Copyright © 2014 Intel Corporation<br>
>>> > + *<br>
>>> > + * Permission is hereby granted, free of charge, to any person<br>
>>> > obtaining a<br>
>>> > + * copy of this software and associated documentation files (the<br>
>>> > "Software"),<br>
>>> > + * to deal in the Software without restriction, including without<br>
>>> > limitation<br>
>>> > + * the rights to use, copy, modify, merge, publish, distribute,<br>
>>> > sublicense,<br>
>>> > + * and/or sell copies of the Software, and to permit persons to whom<br>
>>> > the<br>
>>> > + * Software is furnished to do so, subject to the following<br>
>>> > conditions:<br>
>>> > + *<br>
>>> > + * The above copyright notice and this permission notice (including<br>
>>> > the next<br>
>>> > + * paragraph) shall be included in all copies or substantial portions<br>
>>> > of the<br>
>>> > + * Software.<br>
>>> > + *<br>
>>> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
>>> > EXPRESS OR<br>
>>> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
>>> > MERCHANTABILITY,<br>
>>> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT<br>
>>> > SHALL<br>
>>> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES<br>
>>> > OR OTHER<br>
>>> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
>>> > ARISING<br>
>>> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
>>> > DEALINGS<br>
>>> > + * IN THE SOFTWARE.<br>
>>> > + *<br>
>>> > + * Authors:<br>
>>> > + * Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
>>> > + *<br>
>>> > + */<br>
>>> > +<br>
>>> > +#include "nir.h"<br>
>>> > +#include <main/imports.h><br>
>>> > +<br>
>>> > +/**<br>
>>> > + * SSA-based copy propagation<br>
>>> > + */<br>
>>> > +<br>
>>> > +static bool is_move(nir_alu_instr *instr)<br>
>>> > +{<br>
>>> > + if (instr->op != nir_op_fmov &&<br>
>>> > + instr->op != nir_op_imov)<br>
>>> > + return false;<br>
>>> > +<br>
>>> > + if (instr->dest.saturate)<br>
>>> > + return false;<br>
>>> > +<br>
>>> > + /* we handle modifiers in a separate pass */<br>
>>><br>
>>> This comment is stale now, since this pass should never see<br>
>>> modifiers... maybe we should replace those if's with asserts to make<br>
>>> that clear.<br>
>><br>
>><br>
>> Easy enough to do.<br>
><br>
><br>
> Wait, I just remembered that I left them in intentionally. We may want to<br>
> run copy prop after lowering to source mods. In fact, when I wrote<br>
> lower_to_source_mods, I was lazy and just changed sat instructions to mov<br>
> and trusted in copy prop to clan up the swizzles for me. If anything, we<br>
> may want to make copy prop simply handle them correctly.<br>
> --Jason<br>
<br>
</div></div>Ok, that's fine. In that case, we should probably have a separate pass<br>
to move sat/abs/neg out of moves like the comment mentions, similar to<br>
what we do in i965 fs. Or did you already write one?<br></blockquote><div><br></div><div>I don't think that we actually have that problem. Moving them into their own instructions, copy prop, and lowering back to modifiers should clean that up just fine. <br></div><div>--Jason<br></div></div></div></div>