The a/b -> -((-a)/b) CSE is not valid for complex float with
signed zeros.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/128628
* tree-ssa-sccvn.cc (visit_nary_op): Do not CSE negated
division for complex float.
* gcc.dg/torture/pr128628.c: New testcase.
---
gcc/testsuite/gcc.dg/torture/pr128628.c | 12 ++++++++++++
gcc/tree-ssa-sccvn.cc | 5 ++++-
2 files changed, 16 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..eea6880789a 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5931,7 +5931,10 @@ 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)
+ && (code != RDIV_EXPR
+ || ! COMPLEX_FLOAT_TYPE_P (type)
+ || ! HONOR_SIGNED_ZEROS (type)))
{
tree rhs[2];
rhs[0] = rhs1;
base-commit: 1600ba65f603ec6e92583ba8aeba5c825cd7c887
prerequisite-patch-id: e52d299db98b0892f974152cd9fa5f6859fec5b7
prerequisite-patch-id: 39da6ec3264bae454fa504f127cd5b80a0662f04
prerequisite-patch-id: 6d6c263a964425334ad8c2edd4dd89dcbff44bfe
prerequisite-patch-id: 9a12a1706cbdff1edf8959682cd3cf9d900cd8f1
prerequisite-patch-id: b24057443c46d6979436cce479836178b19355de
prerequisite-patch-id: d61bf2c4249ecd3d9da5eeda002d332ed3a8b4fd
prerequisite-patch-id: 59cbeca60f782f48f945bc532c2235a50de6f0e5
prerequisite-patch-id: 8eddd3172e2007d0fc591124a56b372dfe83e683
prerequisite-patch-id: 862842dd3742066d039f66ffe9528bc490308c50
prerequisite-patch-id: e413d39d9af45f25483eaf229cf883c771444fbb
prerequisite-patch-id: 2faef186ad1d816bb104d89638bc4cec6d863a46
prerequisite-patch-id: b32cceb111f4f57798e4b1d58822281e7bbaf25e
prerequisite-patch-id: 08ff1c06921c5e253d911128be3a8ebb76137d3c
prerequisite-patch-id: 72aa7ba47bd81909871a9e1a2e9de14f2cf42174
prerequisite-patch-id: 2ce10434bf0a7ab22e27ff177073e10b4b7d0d72
prerequisite-patch-id: e286b2e30887f3f43a3458c7c9b3f8c8b513a91b
prerequisite-patch-id: dc07b9957107f8b453a87ad64fd8477ae26e370c
prerequisite-patch-id: 146a9a34e1f46284793e3329e70d1d689efb4145
prerequisite-patch-id: fd2a357c32e58df9d7f99dfa559891d56ebf5a5e
--
2.51.0