From 93a95abe925edc98131056a6b716e7a9e15f72cc Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 16 Oct 2014 10:13:52 +0000 Subject: [PATCH] re PR tree-optimization/63168 (loop header copying fails - not vectorized: latch block not empty) 2014-10-16 Richard Biener 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 | 8 ++++++++ gcc/cfghooks.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/loop-40.c | 14 ++++++++++++++ gcc/tree-cfg.c | 8 ++++++-- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/loop-40.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 349b3037d0d..d38d62ae405 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-10-16 Richard Biener + + 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 Maxim Kuznetsov Anna Tikhonova diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c index fa18214e1ff..09c7f6d6fe2 100644 --- a/gcc/cfghooks.c +++ b/gcc/cfghooks.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b283b9462fe..e281e8c9bb9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-16 Richard Biener + + PR tree-optimization/63168 + * gcc.dg/tree-ssa/loop-40.c: New testcase. + 2014-10-16 Andreas Schwab * 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 index 00000000000..803e5b61e79 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-40.c @@ -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" } } */ diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index cdab6391bd3..ff72601b244 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -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 -- 2.30.2