The a/b -> -((-a)/b) CSE is not valid for complex float with
signed zeros, similar for multiplication.
Bootstrapped and tested on x86_64-unknown-linux-gnu, will push when
sashiko is happy.
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.
---
gcc/testsuite/gcc.dg/torture/pr128628.c | 12 ++++++++++++
gcc/tree-ssa-sccvn.cc | 4 +++-
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr128628.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr128628.c
b/gcc/testsuite/gcc.dg/torture/pr128628.c
new file mode 100644
index 00000000000..d52a727ae64
--- /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 f8a68d4e4fd..f5a2ae37885 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;
--
2.51.0