https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128628
Bug ID: 128628
Summary: [14/15/16/17 Regression] wrong code at -O1: FRE reuses
-((-a)/b) for a/b on _Complex double, wrong sign of
zero since r11-3258
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: jeffchen006 at gmail dot com
Target Milestone: ---
int printf(const char *, ...);
_Complex double a = 1;
int main(void) {
_Complex double x = -a / a, y = a / a;
printf("%g %g\n", __imag__ x, __imag__ y);
}
$ gcc -O0 t.c && ./a.out
0 0
$ gcc -O1 t.c && ./a.out
0 -0
Expected: 0 0. a = 1+0i. a/a = 1+0i, so the imaginary part of y must be +0. At
-O1 y is computed as -((-a)/a), which reuses x = -a/a, and the imaginary part
becomes -0. Both x and y must be printed (if x is dead, the output is correct).
Suspected cause: SCCVN visit_nary_op: the a/b -> -((-a)/b) CSE (first bad
c7f4be78cb6, 2020-09-17) is not valid for complex float with signed zeros.
Avoided by: -fno-tree-fre.
Known to fail: 11.4.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0, 17.0.
Known to work: 8.5.0, 10.5.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