Bug 38998 - Missed full redundancies during PRE
Summary: Missed full redundancies during PRE
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2009-01-28 10:06 UTC by Richard Biener
Modified: 2021-12-27 05:44 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2009-01-28 10:06:23 UTC
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.
Comment 1 Andrew Pinski 2009-02-26 23:59:14 UTC
Confirmed.
Comment 2 Richard Biener 2019-03-13 08:18:29 UTC
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.