https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109626
Bug ID: 109626
Summary: forwprop introduces new signed multiplication UB
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Target Milestone: ---
Consider the function
int foo(_Bool v0, unsigned v1, unsigned v2)
{
signed int v5 = v1 >> v2;
unsigned v6 = -v1;
unsigned int v7 = v2 - v0;
return (int)v7 * (int)v6;
}
This does not invoke undefined behavior when called as foo(0, 0x80000000, 1),
but forwprop1 optimizes this to the equivalent of
int foo(_Bool v0, unsigned v1, unsigned v2)
{
signed int v5 = v1 >> v2;
unsigned int v7 = v0 - v2;
return (int)v7 * (int)v1;
}
where the signed multiplication now is calculating -1 * INT_MIN.