Bug 106523 - [10/11/12/13 Regression] forwprop miscompile
Summary: [10/11/12/13 Regression] forwprop miscompile
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P2 normal
Target Milestone: 10.5
Assignee: Not yet assigned to anyone
URL:
Keywords: needs-bisection, wrong-code
Depends on:
Blocks:
 
Reported: 2022-08-04 10:23 UTC by Krister Walfridsson
Modified: 2022-09-14 13:53 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5
Known to fail: 10.1.0, 12.1.0, 4.9.0, 5.1.0, 7.5.0
Last reconfirmed: 2022-08-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krister Walfridsson 2022-08-04 10:23:41 UTC
The function f7 from testsuite/c-c++-common/rotate-2.c is miscompiled by
forwprop. This can be seen by running the function as

__attribute__((noinline)) unsigned char
f7 (unsigned char x, unsigned int y)
{
  unsigned int t = x;
  return (t << y) | (t >> ((-y) & 7));
}

int
main (void)
{
  volatile unsigned char x = 152;
  volatile unsigned int y = 19;
  if (f7(x, y) != 4)
    __builtin_abort ();

  return 0;
}

This fails at -O1 and higher optimization levels.

What is happening here is that forwprop1 has optimized the function
to
  _10 = x_7(D) r<< y_9(D);
  return _10;
Comment 1 Richard Biener 2022-08-04 10:48:58 UTC
Confirmed.
Comment 2 Martin Liška 2022-08-09 12:40:01 UTC
Started with 4.9.0.