extern double cos(double); void test2(double x, double y) { if (cos(y<10 ? x : -y) != cos(y<10 ? x : y)) link_error (); } PRE figures out new full redundancies because it phi-translates. This leads to missed optimizations wrt the SCCVN value-numbers because we do not iterate with the new redundancy. The immediate effect is that PRE inserts a duplicate PHI: <bb 4>: # x_2 = PHI <x_5(D)(3), y_3(D)(7)> # D.1601_16 = PHI <D.1601_8(3), D.1601_9(7)> # prephitmp.13_15 = PHI <D.1601_8(3), D.1601_9(7)> which only DOM removes later. The second-order missed optimization is that elimination does not optimize the following predicate D.1606_12 = prephitmp.13_15; if (D.1601_16 != D.1606_12) See also http://gcc.gnu.org/ml/gcc-patches/2008-08/msg01545.html which added a broken patch that caused PR38926.
Confirmed.
Note that these days backprop figures the sign of the cos argument isn't important and turns the whole thing into sth CSE-able to FRE2 which now optimizes this to <bb 2> [local count: 1073741824]: if (y_6(D) < 1.0e+1) goto <bb 4>; [50.00%] else goto <bb 3>; [50.00%] <bb 3> [local count: 536870913]: <bb 4> [local count: 1073741824]: # iftmp.0_3 = PHI <x_7(D)(2), y_6(D)(3)> _1 = cos (iftmp.0_3); if (_1 != _1) goto <bb 5>; [33.00%] else goto <bb 6>; [67.00%] <bb 5> [local count: 354334802]: link_error (); <bb 6> [local count: 1073741824]: return; and with -ffinite-math-only we optimize the call to link_error. Of course that's not what the bug asks for which asks for handling this completely within VN.