]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/84841 (ICE: tree check: expected ssa_name, have...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:46:37 +0000 (22:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:46:37 +0000 (22:46 +0200)
Backported from mainline
2018-03-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/84841
* tree-ssa-reassoc.c (INTEGER_CONST_TYPE): Change to 1 << 4 from
1 << 3.
(FLOAT_ONE_CONST_TYPE): Define.
(constant_type): Return FLOAT_ONE_CONST_TYPE for -1.0 and 1.0.
(sort_by_operand_rank): Put entries with higher constant_type last
rather than first to match comments.

* gcc.dg/pr84841.c: New test.

From-SVN: r261927

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84841.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

index 53055f1cf83547060f338903926c45beced9e975..d3d6ec7a6db2208f5d0553569df3ce18b9a67fe6 100644 (file)
@@ -1,6 +1,16 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/84841
+       * tree-ssa-reassoc.c (INTEGER_CONST_TYPE): Change to 1 << 4 from
+       1 << 3.
+       (FLOAT_ONE_CONST_TYPE): Define.
+       (constant_type): Return FLOAT_ONE_CONST_TYPE for -1.0 and 1.0.
+       (sort_by_operand_rank): Put entries with higher constant_type last
+       rather than first to match comments.
+
        2018-03-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79085
index cf5428f5de7a5ef271fb7986a92107f41ecdff68..dbb4a96a6951b2d9db67f51d77076fa03f438ad0 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2018-03-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/84841
+       * gcc.dg/pr84841.c: New test.
+
        PR c++/84874
        * g++.dg/cpp1z/desig7.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr84841.c b/gcc/testsuite/gcc.dg/pr84841.c
new file mode 100644 (file)
index 0000000..4f7422a
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR tree-optimization/84841 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fassociative-math -frounding-math -fno-signed-zeros -fno-trapping-math -fno-tree-forwprop" } */
+
+double
+foo (double x)
+{
+  return -x * 0.1 * 0.1;
+}
index e57a343c532b3d8557635fa212e0accfdd4e85fb..d3014e410b15ddbb4da463f42fa00a664db44fee 100644 (file)
@@ -470,7 +470,8 @@ get_rank (tree e)
 
 /* We want integer ones to end up last no matter what, since they are
    the ones we can do the most with.  */
-#define INTEGER_CONST_TYPE 1 << 3
+#define INTEGER_CONST_TYPE 1 << 4
+#define FLOAT_ONE_CONST_TYPE 1 << 3
 #define FLOAT_CONST_TYPE 1 << 2
 #define OTHER_CONST_TYPE 1 << 1
 
@@ -482,7 +483,14 @@ constant_type (tree t)
   if (INTEGRAL_TYPE_P (TREE_TYPE (t)))
     return INTEGER_CONST_TYPE;
   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t)))
-    return FLOAT_CONST_TYPE;
+    {
+      /* Sort -1.0 and 1.0 constants last, while in some cases
+        const_binop can't optimize some inexact operations, multiplication
+        by -1.0 or 1.0 can be always merged with others.  */
+      if (real_onep (t) || real_minus_onep (t))
+       return FLOAT_ONE_CONST_TYPE;
+      return FLOAT_CONST_TYPE;
+    }
   else
     return OTHER_CONST_TYPE;
 }
@@ -501,7 +509,7 @@ sort_by_operand_rank (const void *pa, const void *pb)
   if (oeb->rank == 0 && oea->rank == 0)
     {
       if (constant_type (oeb->op) != constant_type (oea->op))
-       return constant_type (oeb->op) - constant_type (oea->op);
+       return constant_type (oea->op) - constant_type (oeb->op);
       else
        /* To make sorting result stable, we use unique IDs to determine
           order.  */