https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126471
Bug ID: 126471
Summary: Wrong parity folding with non-even precision
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ktkachov at gcc dot gnu.org
Target Milestone: ---
typedef unsigned _BitInt(129) u129;
typedef unsigned _BitInt(66) u66;
__attribute__((noipa)) int
p129 (u129 x)
{
return __builtin_parityg ((u129) ~x);
}
/* Even precision: the identity does hold, so this must keep working. */
__attribute__((noipa)) int
p66 (u66 x)
{
return __builtin_parityg ((u66) ~x);
}
int
main (void)
{
if (p129 (0) != 1)
__builtin_abort ();
if (p66 (0) != 0)
__builtin_abort ();
return 0;
}
Passes at -O0 and aborts at -O1 and above.
/* parity(~X) is parity(X). * /
(simplify
(PARITY (bit_not @0))
(PARITY @0))
Complementing an N bit value flips all N bits, so parity (~X) == parity (X) ^
(N & 1). The identity should therefore only hold for an even precision.