re PR tree-optimization/63168 (loop header copying fails - not vectorized: latch...
authorRichard Biener <rguenther@suse.de>
Thu, 16 Oct 2014 10:13:52 +0000 (10:13 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 16 Oct 2014 10:13:52 +0000 (10:13 +0000)
2014-10-16  Richard Biener  <rguenther@suse.de>

PR tree-optimization/63168
* tree-cfg.c (gimple_can_merge_blocks_p): Only protect
latches if after merging they are no longer simple.
* cfghooks.c (merge_blocks): Handle merging a latch block
into another block.

* gcc.dg/tree-ssa/loop-40.c: New testcase.

From-SVN: r216304

gcc/ChangeLog
gcc/cfghooks.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/loop-40.c [new file with mode: 0644]
gcc/tree-cfg.c

index 349b3037d0d4871b1a9260d8a09ba52bb4afde41..d38d62ae405764a7a33cc7a7e6a5b8aaa9a0ec3f 100644 (file)
@@ -1,3 +1,11 @@
+2014-10-16  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/63168
+       * tree-cfg.c (gimple_can_merge_blocks_p): Only protect
+       latches if after merging they are no longer simple.
+       * cfghooks.c (merge_blocks): Handle merging a latch block
+       into another block.
+
 2014-10-16  Alexander Ivchenko  <alexander.ivchenko@intel.com>
            Maxim Kuznetsov  <maxim.kuznetsov@intel.com>
            Anna Tikhonova  <anna.tikhonova@intel.com>
index fa18214e1ff4a6a9fbd3f29aaf28271c9d599c6f..09c7f6d6fe296ad38e1c870edc686927b27de405 100644 (file)
@@ -766,6 +766,11 @@ merge_blocks (basic_block a, basic_block b)
          add_bb_to_loop  (a, b->loop_father);
          a->loop_father->header = a;
        }
+      /* If we merge a loop latch into its predecessor, update the loop
+         structure.  */
+      if (b->loop_father->latch
+         && b->loop_father->latch == b)
+       b->loop_father->latch = a;
       remove_bb_from_loops (b);
     }
 
index b283b9462fe04ea441dd48f2449ebb4b6ad40144..e281e8c9bb9e3f99a6aed7e76bff2d2883540b6c 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-16  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/63168
+       * gcc.dg/tree-ssa/loop-40.c: New testcase.
+
 2014-10-16  Andreas Schwab  <schwab@suse.de>
 
        * gcc.target/m68k/crash1.c: Fix implicit declaration.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-40.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-40.c
new file mode 100644 (file)
index 0000000..803e5b6
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ch-details" } */
+
+int mymax2(int *it, int *end)
+{
+  int max = *it;
+  while (++it != end)
+    if (*it > max)
+      max = *it;
+  return max;
+}
+
+/* { dg-final { scan-tree-dump "Duplicating header" "ch" } } */
+/* { dg-final { cleanup-tree-dump "ch" } } */
index cdab6391bd32df5ba65625fd73482484985f5bda..ff72601b244a24236b1c6b2ea73ac435ca4c1d89 100644 (file)
@@ -1674,8 +1674,12 @@ gimple_can_merge_blocks_p (basic_block a, basic_block b)
        return false;
     }
 
-  /* Protect the loop latches.  */
-  if (current_loops && b->loop_father->latch == b)
+  /* Protect simple loop latches.  We only want to avoid merging
+     the latch with the loop header in this case.  */
+  if (current_loops
+      && b->loop_father->latch == b
+      && loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES)
+      && b->loop_father->header == a)
     return false;
 
   /* It must be possible to eliminate all phi nodes in B.  If ssa form