<div dir="ltr">Current PRE tries to not increase code size.<div>It does this with a check whether or not the number of places it would have to insert is 1 or not.</div><div><br></div><div>The problem with this is that the answer could also be "we have to insert in zero places" in the case it's available in all predecessors.</div><div> :)</div><div><br></div><div>Normal dominator based elimination in GVN will not catch these cases because the branches do not dominate the merge point.</div><div><br></div><div>A simple example</div><div><span style="font-size:13.1999998092651px">int c;</span></div><div><div>int d;</div><div>int pre(int foo, int a, int b)</div><div>{</div><div><span style="font-size:13.1999998092651px">      int g;</span></div><div><span style="font-size:13.1999998092651px">      if (foo) {</span></div><div><span class="Apple-tab-span" style="white-space:pre">    </span>  c = a+b;</div><div>      } <span style="font-size:13.1999998092651px">else </span><span style="font-size:13.1999998092651px">{</span></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>  d = a+ b;</div><div>      }</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>g = a+b;</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>return g;</div><div>}</div></div><div><br></div><div>Without this patch, PRE (and GVN) will not eliminate g = a+b.</div><div>With this patch, PRE will create phi(c, d) and eliminate g = a + b.</div><div><br></div><div>(It is tremendously more difficult to make current GVN understand the problem, and GCC solves this the same way i'm about to).</div><div><br></div><div>The patch looks large because of code movement, but it basically all boils down to changing this check:</div><div><br></div><div>if (NumWithout != 1 || NumWith == 0)</div><div><br></div><div>to</div><div>if (NumWithout > 1 || NumWith == 0)</div><div><br></div><div>and skipping insertion when NumWithout == 0</div><div><br></div><div>testcase included.</div><div><br></div></div>