+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>
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);
}
+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.
--- /dev/null
+/* { 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" } } */
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