]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/72824 (Signed floating point zero semantics broken...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:07:25 +0000 (09:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:07:25 +0000 (09:07 +0200)
Backported from mainline
2016-08-09  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/72824
* tree-loop-distribution.c (const_with_all_bytes_same): Verify
real_zerop is not negative.

* gcc.c-torture/execute/ieee/pr72824.c: New test.

From-SVN: r248593

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/ieee/pr72824.c [new file with mode: 0644]
gcc/tree-loop-distribution.c

index a7cb8d67ce196d557d3eb3ca3214ee34d15405a2..afc11fa2bf0156e4a9afd32fed84094276b7d6b6 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-08-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/72824
+       * tree-loop-distribution.c (const_with_all_bytes_same): Verify
+       real_zerop is not negative.
+
        2016-07-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/71953
index f9c9aaa751bb69150c3a07ee4f74b1cfe4a34c9e..317787d928d0fa168058e13c52dca555378fc702 100644 (file)
@@ -1,3 +1,11 @@
+2017-05-30  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2016-08-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/72824
+       * gcc.c-torture/execute/ieee/pr72824.c: New test.
+
 2017-05-29  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/ieee/pr72824.c b/gcc/testsuite/gcc.c-torture/execute/ieee/pr72824.c
new file mode 100644 (file)
index 0000000..1c21373
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR tree-optimization/72824 */
+
+static inline void
+foo (float *x, float value)
+{
+  int i;
+  for (i = 0; i < 32; ++i)
+    x[i] = value;
+}
+
+int
+main ()
+{
+  float x[32];
+  foo (x, -0.f);
+  if (__builtin_copysignf (1.0, x[3]) != -1.0f)
+    __builtin_abort ();
+  return 0;
+}
index 904f4e8db60bd1efa3df808f2b3f9f350182b3a3..e5e4d3c4e1a9352485fdf6b535ae177188540c20 100644 (file)
@@ -90,6 +90,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "gimple-pretty-print.h"
 #include "tree-vectorizer.h"
+#include "real.h"
 
 
 /* A Reduced Dependence Graph (RDG) vertex representing a statement.  */
@@ -775,12 +776,40 @@ const_with_all_bytes_same (tree val)
   int i, len;
 
   if (integer_zerop (val)
-      || real_zerop (val)
       || (TREE_CODE (val) == CONSTRUCTOR
           && !TREE_CLOBBER_P (val)
           && CONSTRUCTOR_NELTS (val) == 0))
     return 0;
 
+  if (real_zerop (val))
+    {
+      /* Only return 0 for +0.0, not for -0.0, which doesn't have
+        an all bytes same memory representation.  Don't transform
+        -0.0 stores into +0.0 even for !HONOR_SIGNED_ZEROS.  */
+      switch (TREE_CODE (val))
+       {
+       case REAL_CST:
+         if (!real_isneg (TREE_REAL_CST_PTR (val)))
+           return 0;
+         break;
+       case COMPLEX_CST:
+         if (!const_with_all_bytes_same (TREE_REALPART (val))
+             && !const_with_all_bytes_same (TREE_IMAGPART (val)))
+           return 0;
+         break;
+       case VECTOR_CST:
+         unsigned int j;
+         for (j = 0; j < VECTOR_CST_NELTS (val); ++j)
+           if (const_with_all_bytes_same (VECTOR_CST_ELT (val, i)))
+             break;
+         if (j == VECTOR_CST_NELTS (val))
+           return 0;
+         break;
+       default:
+         break;
+       }
+    }
+
   if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
     return -1;