https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126325
Bug ID: 126325
Summary: [17 Regression] (FP)ival < 2^N miscompiled with
-fno-trapping-math since r17-2324-g081959973e38fd
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dhruvc at gcc dot gnu.org
CC: sayle at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
This shows up in the 767.nest_r benchmark as a runtime miscompare. The
miscompile works slightly differently for unsigned vs. signed cases:
int f (int i)
{
return (float)i < 2147483648.0f; /* = 2^31 (INT_MAX + 1) */
}
int g (unsigned int i)
{
return (float)i < 4294967296.0f; /* = 2^32 (UINT_MAX + 1) */
}
These get compiled to:
;; Function f (null)
;; enabled by -tree-original
{
# DEBUG BEGIN STMT;
return 0;
}
;; Function g (null)
;; enabled by -tree-original
{
# DEBUG BEGIN STMT;
return i <= 2147483646;
}
i.e. the signed case gets folded to false (even though it is always true), and
the unsigned case gets folded to (INT_MAX - 2) which is also incorrect. The
same occurs with int64_t / double.
Flags: -fno-trapping-math
Compiler explorer: https://godbolt.org/z/oM65ae7oE