https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124525
Bug ID: 124525
Summary: New signed overflow introduced by pcom
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Blocks: 118443
Target Milestone: ---
pcom introduces new signed overflows when the function below is compiled for
x86_64 with -O3:
int in[8][4];
int out[4];
void
foo (void)
{
int sum = 1;
int i, j, k;
for (k = 0; k < 4; k++)
{
for (j = 0; j < 4; j++)
for (i = 0; i < 4; i++)
sum *= in[i + k][j];
out[k] = sum;
}
}
pcom changes the order of the multiplications, and the result may now overflow
in cases where the original did not. For example, if in[0][0] has the value 0
and the rest of the elements have the value 0x7fffffff, then the multiplication
_150 in the beginning of the optimized function will overflow:
<bb 2> :
_141 = MEM[(int *)&in];
_142 = MEM[(int *)&in + 12B];
_143 = _141 * _142;
_144 = MEM[(int *)&in + 8B];
_145 = _143 * _144;
_146 = MEM[(int *)&in + 4B];
_147 = _145 * _146;
_148 = MEM[(int *)&in + 16B];
_149 = MEM[(int *)&in + 28B];
_150 = _148 * _149;
_151 = MEM[(int *)&in + 24B];
_152 = _150 * _151;
...
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing