<p dir="ltr">On Sep 6, 2016 1:50 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>
> > ---<br>
><br>
> This seems fine, but the commit message needs some expansion.  Questions<br>
> I had:<br>
><br>
> Does this help compared to an implementation with nir CSE already?</p>
<p dir="ltr">Yes, value numbering is capable of detecting common values even if one does not dominate the other.  For instance, in you have</p>
<p dir="ltr">if (...) {<br>
   ssa_1 = ssa_0 + 7;<br>
   /* use ssa_1 */<br>
} else {<br>
   ssa_2 = ssa_0 + 7;<br>
   /* use ssa_2 */<br>
}</p>
<p dir="ltr">Global value numbering doesn't care about dominance relationships so it figures out that ssa_1 and ssa_2 are the same and converts this to</p>
<p dir="ltr">if (...) {<br>
   ssa_1 = ssa_0 + 7;<br>
   /* use ssa_1 */<br>
} else {<br>
   /* use ssa_2 */<br>
}</p>
<p dir="ltr">Obviously, we just broke SSA form which is bad.  Global code motion, however, will repair this for us by turning this into</p>
<p dir="ltr">ssa_1 = ssa_0 + 7;<br>
if (...) {<br>
   /* use ssa_1 */<br>
} else {<br>
   /* use ssa_2 */<br>
}</p>
<p dir="ltr">> Does nir CSE still get us anything that this doesn't?</p>
<p dir="ltr">It's still useful primarily because it's less of a scorched-earth approach and doesn't require GCM.  This makes it q bit more appropriate for use as a clean-up in a late optimization run.</p>
<p dir="ltr">I can add since of that to the commit message.</p>