Hello, 

This patch improves the some_nonzerop(tree t) function from tree-complex.c file 
(the function is only used there). 

This function returns true if a tree as a parameter is not the constant 0 (or 
+0.0 only for reals when !flag_signed_zeros ). The former result is then used 
to determine if some simplifications are possible for complex expansions 
(addition, multiplication, and division). 

Unfortunately, if the tree is a real constant, the function always return true, 
even for +0.0 because of the explicit test on flag_signed_zeros (so if your 
system enables signed zeros you cannot benefit from those simplifications). To 
avoid this behavior and allow complex expansion simplifications, I propose the 
following patch, which test for the sign of the real constant 0.0 instead of 
checking the flag. 

This first fix reveals a bug (thanks to c-c++-common/torture/complex-sign-add.c 
) in the simplification section of expand_complex_addition (also fixed in the 
patch). 

The patch has passed bootstrap and testing on x86_64-pc-linux-gnu . 

Best regards, 
Laurent Thévenoux 
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2191d62..a6124ce 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2017-10-05  Laurent Thévenoux  <laurent.theven...@inria.fr>
+
+	* tree-complex.c (some_nonzerop): Adjust the way of testing real
+	constants. Allows existing simplifications of complex expansions
+	to be well done.
+	* tree-complex.c (expand_complex_addition): Bug fixing for complex
+	addition expansion simplification.
+
 2017-10-02  Bill Schmidt  <wschm...@linux.vnet.ibm.com>
 
 	Backport from mainline
diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c
index e0dd3d9..413b601 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -110,8 +110,11 @@ some_nonzerop (tree t)
   /* Operations with real or imaginary part of a complex number zero
      cannot be treated the same as operations with a real or imaginary
      operand if we care about the signs of zeros in the result.  */
-  if (TREE_CODE (t) == REAL_CST && !flag_signed_zeros)
-    zerop = real_identical (&TREE_REAL_CST (t), &dconst0);
+  if (TREE_CODE (t) == REAL_CST)
+    {
+      if (real_identical (&TREE_REAL_CST (t), &dconst0))
+	zerop = !real_isneg (&TREE_REAL_CST (t));
+    }
   else if (TREE_CODE (t) == FIXED_CST)
     zerop = fixed_zerop (t);
   else if (TREE_CODE (t) == INTEGER_CST)
@@ -937,7 +940,7 @@ expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
 
     case PAIR (VARYING, ONLY_REAL):
       rr = gimplify_build2 (gsi, code, inner_type, ar, br);
-      ri = ai;
+      ri = bi;
       break;
 
     case PAIR (VARYING, ONLY_IMAG):

Reply via email to