https://gcc.gnu.org/g:cc36ceb085de6111d3e0f41290f872363d208d21
commit r17-6167-gcc36ceb085de6111d3e0f41290f872363d208d21 Author: Richard Biener <[email protected]> Date: Thu Nov 12 09:12:12 2026 +0100 tree-optimization/128628 - wrong CSE of negated complex division The a/b -> -((-a)/b) CSE is not valid for complex float with signed zeros, similar for multiplication. PR tree-optimization/128628 * tree-ssa-sccvn.cc (visit_nary_op): Do not CSE negated division or multiplication for complex float. * gcc.dg/torture/pr128628.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr128628.c | 12 ++++++++++++ gcc/tree-ssa-sccvn.cc | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr128628.c b/gcc/testsuite/gcc.dg/torture/pr128628.c new file mode 100644 index 000000000000..d52a727ae64f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr128628.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ +/* { dg-add-options ieee } */ + +_Complex double a = 1; +int main() +{ + _Complex double x = -a / a, y = a / a; + if (__builtin_copysign (1., __imag__ y) + != __builtin_copysign (1., __imag__ x)) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index f8a68d4e4fd6..f5a2ae378854 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5931,7 +5931,9 @@ visit_nary_op (tree lhs, gassign *stmt) case RDIV_EXPR: case MULT_EXPR: /* Match up ([-]a){/,*}([-])b with v=a{/,*}b, replacing it with -v. */ - if (! HONOR_SIGN_DEPENDENT_ROUNDING (type)) + if (! HONOR_SIGN_DEPENDENT_ROUNDING (type) + && (! COMPLEX_FLOAT_TYPE_P (type) + || ! HONOR_SIGNED_ZEROS (type))) { tree rhs[2]; rhs[0] = rhs1;
