[Bug tree-optimization/108540] [13 Regression] Frange miscompilation of ruby since r13-3261

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 26 11:41:04 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108540

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think
int
foo (int x, double d)
{
  if (x == 42)
    d = -0.0;
  if (d == 0.0)
    return 42;
  return 12;
}
behaves similarly with threading.  The above function is basically return (x ==
42 || d == 0.0) ? 42 : 12;
In forwprop1 at -O2 we still have correct:
  <bb 2> :
  if (x_3(D) == 42)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :

  <bb 4> :
  # d_1 = PHI <d_4(D)(2), -0.0(3)>
  if (d_1 == 0.0)
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 5> :
  // predicted unlikely by early return (on trees) predictor.

  <bb 6> :
  # RANGE [irange] int [-INF, +INF] NONZERO 0x2e
  # _2 = PHI <42(5), 12(4)>
but then comes ethread and turns that into:
  <bb 2> :
  if (x_3(D) == 42)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  # d_5 = PHI <-0.0(2)>
  goto <bb 6>; [100.00%]

  <bb 4> :
  # d_1 = PHI <d_4(D)(2)>
  if (d_1 == 0.0)
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 5> :
  // predicted unlikely by early return (on trees) predictor.

  <bb 6> :
  # RANGE [irange] int [-INF, +INF] NONZERO 0x2e
  # _2 = PHI <42(5), 12(4), 12(3)>
as if -0.0 == 0.0 was false rather than true.


More information about the Gcc-bugs mailing list