From f31276858a7182663abc0f91fd8961231191b9ed Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Thu, 6 Oct 2016 10:23:22 -0600 Subject: [PATCH] re PR tree-optimization/71661 (wrong code at -O3) PR tree-optimization/71661 * tree-cfgcleanup.c (remove_forwarder_block_with_phi): Handle case when removal of a forwarder exposes a new natural loop. PR tree-optimization/71661 * gcc.dg/tree-ssa/pr71661.c: New test. From-SVN: r240836 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/tree-ssa/pr71661.c | 31 +++++++++++++++++++++++++ gcc/tree-cfgcleanup.c | 5 ++++ 4 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr71661.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b8acef79bc..0092be861e8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-10-05 Jeff Law + + PR tree-optimization/71661 + * tree-cfgcleanup.c (remove_forwarder_block_with_phi): Handle case when + removal of a forwarder exposes a new natural loop. + 2016-10-06 Uros Bizjak * config/i386/sse.md (andnot3): Add FALLTHRU comments. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e180375cd7c..56f1c8dbd40 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-06 Jeff Law + + PR tree-optimization/71661 + * gcc.dg/tree-ssa/pr71661.c: New test. + 2016-10-06 Richard Biener PR tree-optimization/77855 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c new file mode 100644 index 00000000000..c273ea1afd6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -fdisable-tree-ethread" } */ + +extern void exit (int); + +int a, b; + +void +fn1 () +{ + unsigned c = 0; + int d; + b = a; + if (a < 0) + goto L1; + for (; a < 1; a++) + d = 0; + for (; d < 2; d++) + { + for (c = 0; c < 3; c++) + L1: + a = 2; + } +} + +int +main () +{ + fn1 (); + exit (0); +} diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 6052872cb57..21873f8d516 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -840,6 +840,11 @@ remove_forwarder_block_with_phi (basic_block bb) if (dest == bb) return false; + /* Removal of forwarders may expose new natural loops and thus + a block may turn into a loop header. */ + if (current_loops && bb_loop_header_p (bb)) + return false; + /* If the destination block consists of a nonlocal label, do not merge it. */ label = first_stmt (dest); -- 2.30.2