<p dir="ltr"><br>
On Aug 12, 2015 4:21 PM, "Eric Anholt" <<a href="mailto:eric@anholt.net">eric@anholt.net</a>> wrote:<br>
><br>
> Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
><br>
> > On Wed, Aug 12, 2015 at 11:55 AM, Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a>> wrote:<br>
> >> NIR instruction count results on i965:<br>
> >> total instructions in shared programs: 1261954 -> 1261937 (-0.00%)<br>
> >> instructions in affected programs:     455 -> 438 (-3.74%)<br>
> >><br>
> >> One in yofrankie, two in tropics.  Apparently i965 had also optimized all<br>
> >> of these out anyway.<br>
> >><br>
> >> Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> >> ---<br>
> >>  src/glsl/nir/nir_opt_cse.c | 43 +++++++++++++++++++++++++++++++++++++++----<br>
> >>  1 file changed, 39 insertions(+), 4 deletions(-)<br>
> >><br>
> >> diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c<br>
> >> index 553906e..864795c 100644<br>
> >> --- a/src/glsl/nir/nir_opt_cse.c<br>
> >> +++ b/src/glsl/nir/nir_opt_cse.c<br>
> >> @@ -86,8 +86,41 @@ nir_instrs_equal(nir_instr *instr1, nir_instr *instr2)<br>
> >>        }<br>
> >>        return true;<br>
> >>     }<br>
> >> -   case nir_instr_type_tex:<br>
> >> -      return false;<br>
> >> +   case nir_instr_type_tex: {<br>
> >> +      nir_tex_instr *tex1 = nir_instr_as_tex(instr1);<br>
> >> +      nir_tex_instr *tex2 = nir_instr_as_tex(instr2);<br>
> >> +<br>
> >> +      if (tex1->op != tex2->op)<br>
> >> +         return false;<br>
> >> +<br>
> >> +      if (tex1->num_srcs != tex2->num_srcs)<br>
> >> +         return false;<br>
> >> +      for (unsigned i = 0; i < tex1->num_srcs; i++) {<br>
> >> +         if (tex1->src[i].src_type != tex2->src[i].src_type ||<br>
> >> +             !nir_srcs_equal(tex1->src[i].src, tex2->src[i].src)) {<br>
> >> +            return false;<br>
> ><br>
> > We should probably loop over both arrays of sources and match by<br>
> > source type instead of assuming that they are always in the same<br>
> > order.  They *probably* are, but you can pretty easily get cases where<br>
> > they aren't.<br>
> ><br>
> > Otherwise, this looks fine to me.<br>
><br>
> What circumstance would produce arrays in different order?  I can't<br>
> imagine one, so conservative seems appropriate to me.</p>
<p dir="ltr">I was remembering a place that adds a source but that place is nir_lower_samplers and its probably the only place that adds the sampler index source type.  Therefore, it should be justjust as deterministic as whatever generated it (glsl ir or mesa ir).  I think I'd still rather the double loop since there is no defined order, but I'm not going to complain too much.  Either way,</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>></p>
<p dir="ltr">You can apply that to the patch that zeros texture instructions too.</p>