https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122733
Bug ID: 122733
Summary: wrong code for (y << x) < x
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: ---
The following test case is miscompiled when using -O1 or higher:
__attribute__ ((noipa)) bool
lshift_lt(unsigned x, unsigned y)
{
if (y <= 0)
__builtin_unreachable ();
return (y << x) < x;
}
__attribute__ ((noipa)) bool
lshift_gt(unsigned x, unsigned y)
{
if (y <= 0)
__builtin_unreachable ();
return (y << x) > x;
}
int main()
{
if (!lshift_lt(1, 0x80000000))
__builtin_abort();
if (lshift_gt(1, 0x80000000))
__builtin_abort();
}
The problem comes from the match.pd rules:
(y << x) {<,<=} x -> 0 when y > 0.
(y << x) {>,>=} x -> 1 when y > 0.
These transformations are incorrect because (y << x) may evaluate to 0 even
when y > 0.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing