Bug 106883 - SLSR may generate signed wrap
Summary: SLSR may generate signed wrap
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2022-09-08 00:05 UTC by Krister Walfridsson
Modified: 2022-09-14 13:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-09-08 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-09-08 00:05:37 UTC
SLSR may generate new signed wrap for cases where the original did not wrap.
This can be seen in the function f from gcc.dg/tree-ssa/slsr-19.c:

int
f (int c, int s)
{
  int x1, x2, y1, y2;

  y1 = c + 2;
  x1 = s * y1;
  y2 = y1 + 2;
  x2 = s * y2;
  return x1 + x2;
}

SLSR optimizes this to

int f (int c, int s)
{
   int y1;
   int x2;
   int x1;
   int _7;
   int slsr_9;

   <bb 2>:
   y1_2 = c_1(D) + 2;
   x1_4 = y1_2 * s_3(D);
   slsr_9 = s_3(D) * 2;
   x2_6 = x1_4 + slsr_9;
   _7 = x1_4 + x2_6;
   return _7;

Calling f(-3, 0x75181005) does not make any operation wrap in the original
function, but slsr_9 overflow in the optimized code.
Comment 1 Richard Biener 2022-09-08 09:44:35 UTC
Confirmed - thanks for reporting!  Since there's a VRP pass after SLSR it might be possible to craft a testcase that fails at runtime.