re PR tree-optimization/82381 (internal compiler error: qsort checking failed)
authorJakub Jelinek <jakub@redhat.com>
Tue, 3 Oct 2017 11:24:39 +0000 (13:24 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Oct 2017 11:24:39 +0000 (13:24 +0200)
PR tree-optimization/82381
* tree-ssa-reassoc.c (sort_by_operand_rank): Don't check
stmt_to_insert nor wheather SSA_NAMEs are default defs.
Return 1 or -1 if one of bba and bbb is NULL. If bb_rank is equal,
fallthrough into reassoc_stmt_dominates_stmt_p.

* gcc.c-torture/compile/pr82381.c: New test.

From-SVN: r253379

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr82381.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

index 934dd76fa8593c33f635bb8a11c60a93b149f958..25dcf02d04ab232412f42d3fd5797e08512e3a56 100644 (file)
@@ -1,5 +1,11 @@
 2017-10-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/82381
+       * tree-ssa-reassoc.c (sort_by_operand_rank): Don't check
+       stmt_to_insert nor wheather SSA_NAMEs are default defs.
+       Return 1 or -1 if one of bba and bbb is NULL. If bb_rank is equal,
+       fallthrough into reassoc_stmt_dominates_stmt_p.
+
        PR target/82386
        * combine.c (combine_instructions): Don't combine in unreachable
        basic blocks.
index 74023abc015ae1c35e6394b680b09d365c8f9e39..70fde548d1c62dda990ebd9284929edb4dadb751 100644 (file)
@@ -1,5 +1,8 @@
 2017-10-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/82381
+       * gcc.c-torture/compile/pr82381.c: New test.
+
        PR target/82386
        * gcc.dg/pr82386.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82381.c b/gcc/testsuite/gcc.c-torture/compile/pr82381.c
new file mode 100644 (file)
index 0000000..3ff2c3a
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR tree-optimization/82381 */
+/* { dg-do compile } */
+
+signed char b, h;
+unsigned short c, e;
+short int d, f, g;
+
+void
+foo ()
+{
+  if (h)
+    {
+      short a = -(d + c - b);
+      f = e - a - -d;
+    }
+  if (c)
+    g = 0;
+}
index b2d0f57e644927c98085751ac9791ee66e8630d5..eff76d1c6c2be977d698029c8fa82a031c3c334a 100644 (file)
@@ -514,36 +514,37 @@ sort_by_operand_rank (const void *pa, const void *pb)
       && TREE_CODE (oea->op) == SSA_NAME
       && TREE_CODE (oeb->op) == SSA_NAME)
     {
-      /* As SSA_NAME_VERSION is assigned pretty randomly, because we reuse
-        versions of removed SSA_NAMEs, so if possible, prefer to sort
-        based on basic block and gimple_uid of the SSA_NAME_DEF_STMT.
-        See PR60418.  */
-      if (!SSA_NAME_IS_DEFAULT_DEF (oea->op)
-         && !SSA_NAME_IS_DEFAULT_DEF (oeb->op)
-         && !oea->stmt_to_insert
-         && !oeb->stmt_to_insert
-         && SSA_NAME_VERSION (oeb->op) != SSA_NAME_VERSION (oea->op))
+      if (SSA_NAME_VERSION (oeb->op) != SSA_NAME_VERSION (oea->op))
        {
+         /* As SSA_NAME_VERSION is assigned pretty randomly, because we reuse
+            versions of removed SSA_NAMEs, so if possible, prefer to sort
+            based on basic block and gimple_uid of the SSA_NAME_DEF_STMT.
+            See PR60418.  */
          gimple *stmta = SSA_NAME_DEF_STMT (oea->op);
          gimple *stmtb = SSA_NAME_DEF_STMT (oeb->op);
          basic_block bba = gimple_bb (stmta);
          basic_block bbb = gimple_bb (stmtb);
          if (bbb != bba)
            {
+             /* One of the SSA_NAMEs can be defined in oeN->stmt_to_insert
+                but the other might not.  */
+             if (!bba)
+               return 1;
+             if (!bbb)
+               return -1;
+             /* If neither is, compare bb_rank.  */
              if (bb_rank[bbb->index] != bb_rank[bba->index])
                return bb_rank[bbb->index] - bb_rank[bba->index];
            }
-         else
-           {
-             bool da = reassoc_stmt_dominates_stmt_p (stmta, stmtb);
-             bool db = reassoc_stmt_dominates_stmt_p (stmtb, stmta);
-             if (da != db)
-               return da ? 1 : -1;
-           }
-       }
 
-      if (SSA_NAME_VERSION (oeb->op) != SSA_NAME_VERSION (oea->op))
-       return SSA_NAME_VERSION (oeb->op) > SSA_NAME_VERSION (oea->op) ? 1 : -1;
+         bool da = reassoc_stmt_dominates_stmt_p (stmta, stmtb);
+         bool db = reassoc_stmt_dominates_stmt_p (stmtb, stmta);
+         if (da != db)
+           return da ? 1 : -1;
+
+         return (SSA_NAME_VERSION (oeb->op) > SSA_NAME_VERSION (oea->op)
+                 ? 1 : -1);
+       }
       else
        return oeb->id > oea->id ? 1 : -1;
     }