]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/80747 (gcc.dg/tree-ssa/tailrecursion-4.c fails with...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:05:01 +0000 (19:05 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:05:01 +0000 (19:05 +0200)
Backported from mainline
2017-12-21  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/80747
PR rtl-optimization/83512
* cfgrtl.c (force_nonfallthru_and_redirect): When splitting
succ edge from ENTRY, copy partition from e->dest to the newly
created bb.
* bb-reorder.c (reorder_basic_blocks_simple): If last_tail is
ENTRY, use BB_PARTITION of its successor block as current_partition.
Don't copy partition when splitting succ edge from ENTRY.

* gcc.dg/pr80747.c: New test.
* gcc.dg/pr83512.c: New test.

From-SVN: r262049

gcc/ChangeLog
gcc/bb-reorder.c
gcc/cfgrtl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr80747.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr83512.c [new file with mode: 0644]

index 6b73af2cb423f40b601006dc9fe34d91324012f5..072aa51bc4b3417b1de7d4e769f410e5f7ea5c11 100644 (file)
@@ -3,6 +3,15 @@
        Backported from mainline
        2017-12-21  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/80747
+       PR rtl-optimization/83512
+       * cfgrtl.c (force_nonfallthru_and_redirect): When splitting
+       succ edge from ENTRY, copy partition from e->dest to the newly
+       created bb.
+       * bb-reorder.c (reorder_basic_blocks_simple): If last_tail is
+       ENTRY, use BB_PARTITION of its successor block as current_partition.
+       Don't copy partition when splitting succ edge from ENTRY.
+
        PR tree-optimization/83523
        * tree-ssa-math-opts.c (is_widening_mult_p): Return false if
        for INTEGER_TYPE TYPE_OVERFLOW_TRAPS.
index 4eb68930bec08f315a3990093ac0011155da2754..25f8f6a3e98f8f05777f57e18604bdccf0b5b483 100644 (file)
@@ -2402,7 +2402,10 @@ reorder_basic_blocks_simple (void)
 
   basic_block last_tail = (basic_block) ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux;
 
-  int current_partition = BB_PARTITION (last_tail);
+  int current_partition
+    = BB_PARTITION (last_tail == ENTRY_BLOCK_PTR_FOR_FN (cfun)
+                   ? EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0)->dest
+                   : last_tail);
   bool need_another_pass = true;
 
   for (int pass = 0; pass < 2 && need_another_pass; pass++)
@@ -2443,7 +2446,6 @@ reorder_basic_blocks_simple (void)
     {
       force_nonfallthru (e);
       e->src->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux;
-      BB_COPY_PARTITION (e->src, e->dest);
     }
 }
 
index 3a4afcaf8ba419e327715ce4a4775aceb46a9e47..00a5dff4fe8d5f4759d47b321dbea42582236228 100644 (file)
@@ -1541,6 +1541,9 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label)
          basic_block bb = create_basic_block (BB_HEAD (e->dest), NULL,
                                               ENTRY_BLOCK_PTR_FOR_FN (cfun));
 
+         /* Make sure new block ends up in correct hot/cold section.  */
+         BB_COPY_PARTITION (bb, e->dest);
+
          /* Change the existing edge's source to be the new block, and add
             a new edge from the entry block to the new block.  */
          e->src = bb;
index f8138962f2720ee2b7ae60ba94ddb847d843adc3..7b170172259db8a1d18ad544059faac1365a49fc 100644 (file)
@@ -3,6 +3,11 @@
        Backported from mainline
        2017-12-21  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/80747
+       PR rtl-optimization/83512
+       * gcc.dg/pr80747.c: New test.
+       * gcc.dg/pr83512.c: New test.
+
        PR tree-optimization/83523
        * g++.dg/tree-ssa/pr83523.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr80747.c b/gcc/testsuite/gcc.dg/pr80747.c
new file mode 100644 (file)
index 0000000..ea9dd3c
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR rtl-optimization/80747 */
+/* { dg-do compile } */
+/* { dg-options "-fprofile-use -freorder-blocks-and-partition -O1 -foptimize-sibling-calls" } */
+
+int
+foo (int a)
+{
+  int r;
+  if (a & 1)
+    r = foo (a - 1);
+  else if (a)
+    r = foo (a - 2);
+  else
+    return 0;
+  if (r)
+    r = r;
+  return r;
+}
diff --git a/gcc/testsuite/gcc.dg/pr83512.c b/gcc/testsuite/gcc.dg/pr83512.c
new file mode 100644 (file)
index 0000000..d86e57b
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR rtl-optimization/83512 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -freorder-blocks-algorithm=simple" } */
+
+int a;
+
+void
+foo (int *x)
+{
+  for (;;)
+    {
+      for (*x = 0; *x < 1; *x++)
+       ;
+      ++a;
+    }
+}