https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128635
Bug ID: 128635
Summary: wrong code at -O1: _Decimal32 x * 2.00DF expanded as x
+ x, quantum (exponent) lost
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: dfp, wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
int printf(const char *, ...);
_Decimal32 g = 1;
int main(void) {
_Decimal32 c = 2.00DF;
union { _Decimal32 d; unsigned u; } r = { g * c };
printf("%x\n", r.u);
}
$ gcc -O0 t.c && ./a.out
318000c8
$ gcc -O1 t.c && ./a.out
32800002
Expected: 318000c8. g = 1 (exponent 0), c = 2.00 (exponent -2). The product
exponent is 0 + (-2) = -2, so the result is 200E-2 (0x318000c8). -O1 gives 2E0
(0x32800002). The value is the same; the quantum is wrong (IEEE 754-2008, C23).
Suspected cause: expmed.cc expand_mult rewrites x * 2.0 as x + x also for
decimal float modes. With the literal in the multiply (g * 2.00DF), -O0 is also
wrong.
Known to fail: 7.5.0, 8.5.0, 10.5.0, 11.4.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0,
16.2.0, 17.0.
-O0 -fsanitize=undefined,address is clean.
gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release