re PR tree-optimization/78482 (wrong code at -O3 in both 32-bit and 64-bit modes...
authorRichard Biener <rguenther@suse.de>
Wed, 23 Nov 2016 14:25:48 +0000 (14:25 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 23 Nov 2016 14:25:48 +0000 (14:25 +0000)
2016-11-23  Richard Biener  <rguenther@suse.de>

PR tree-optimization/78482
* tree-cfgcleanup.c: Include tree-ssa-loop-niter.h.
(remove_forwarder_block_with_phi): When merging with a loop
header creates a new latch reset number of iteration information
of the loop.

* gcc.dg/torture/pr78482.c: New testcase.

From-SVN: r242754

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr78482.c [new file with mode: 0644]
gcc/tree-cfgcleanup.c

index 09724e306ef7d22b4898f8dd8550326959cf7741..bafdafbbbbc589b6a197fc36095ef56aa484fcd2 100644 (file)
@@ -1,3 +1,11 @@
+2016-11-23  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78482
+       * tree-cfgcleanup.c: Include tree-ssa-loop-niter.h.
+       (remove_forwarder_block_with_phi): When merging with a loop
+       header creates a new latch reset number of iteration information
+       of the loop.
+
 2016-11-23  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/sparc/sparc.md (*ashrsi3_extend): Rename to...
index 604c5918c3bf753003ec9574165adcdfbf9020fe..db8b8974947e32ee0a26191be0bcbf17cb4a5183 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-23  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78482
+       * gcc.dg/torture/pr78482.c: New testcase.
+
 2016-11-23  Bin Cheng  <bin.cheng@arm.com>
 
        * gcc.dg/fold-cond_expr-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr78482.c b/gcc/testsuite/gcc.dg/torture/pr78482.c
new file mode 100644 (file)
index 0000000..ef68bdf
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do run } */
+
+int printf(const char*, ...);
+short a = 65531;
+int b = 3, f;
+char c, d;
+static void fn1(int p1)
+{
+  short e;
+  b = f;
+  if (f > p1 && p1)
+    L:
+       for (e = 0; 0;)
+         ;
+  else if (d) b = 0 >= b;
+  for (; e <= 3; e++)
+    {
+      if (b)
+       continue;
+      b = 3;
+      goto L;
+    }
+}
+
+int main()
+{
+  for (; c >= 0; c--)
+    {
+      if (!b)
+       {
+         printf("%d\n", 2);
+         continue;
+       }
+      fn1(a);
+    }
+  return 0;
+}
index fe22ed309e4a6c7b029660e0b6bfc907fd62b175..1f17d9a7f33dbbece34f057a269cdeaa160d6890 100644 (file)
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-scalar-evolution.h"
 #include "gimple-match.h"
 #include "gimple-fold.h"
+#include "tree-ssa-loop-niter.h"
 
 
 /* The set of blocks in that at least one of the following changes happened:
@@ -885,6 +886,19 @@ remove_forwarder_block_with_phi (basic_block bb)
             DEST.  */
          e = single_succ_edge (split_edge (e));
        }
+      else
+       {
+         /* If we merge the forwarder into a loop header verify if we
+            are creating another loop latch edge.  If so, reset
+            number of iteration information of the loop.  */
+         if (dest->loop_father->header == dest
+             && dominated_by_p (CDI_DOMINATORS, e->src, dest))
+           {
+             dest->loop_father->any_upper_bound = false;
+             dest->loop_father->any_likely_upper_bound = false;
+             free_numbers_of_iterations_estimates_loop (dest->loop_father);
+           }
+       }
 
       s = redirect_edge_and_branch (e, dest);