https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127969
Bug ID: 127969
Summary: wrong code with -fno-signed-zeros: _Decimal64 (x == C)
? x : C folded to C, changing the quantum
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: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <string.h>
_Decimal64 f(_Decimal64 x) {
if (x == 1.0dd)
return x;
return 1.0dd;
}
int main(void) {
_Decimal64 x = 1.00dd, r = f(x);
return memcmp(&x, &r, sizeof x) != 0;
}
godbolt: https://godbolt.org/z/vx3dzxvzh
With -O0, or with -O2 without -fno-signed-zeros, it returns 0, but with GCC -O1
and above with -fno-signed-zeros it returns 1: f(1.00dd) returns the constant
1.0dd (equal value, different quantum exponent) instead of x. -fno-ssa-phiopt
avoids it. Written as `return x == 1.0dd ? x : 1.0dd;`, f returns 1.0dd already
at -O0 -fno-signed-zeros, and -fno-ssa-phiopt then makes no difference.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.