re PR tree-optimization/85284 (Loop miscompilation starting with r238367)
authorRichard Biener <rguenther@suse.de>
Mon, 9 Apr 2018 13:27:33 +0000 (13:27 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 9 Apr 2018 13:27:33 +0000 (13:27 +0000)
2018-04-09  Richard Biener  <rguenther@suse.de>

PR tree-optimization/85284
* tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions):
Only use the niter constraining form of simple_iv when the exit
is always executed.

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

From-SVN: r259234

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr85284.c [new file with mode: 0644]
gcc/tree-ssa-loop-niter.c

index 165b968b0626777fcc08d3bb6328fd0635de8748..6d0a2692beff329a49e6df3a4566bac369a24a98 100644 (file)
@@ -1,3 +1,10 @@
+2018-04-09  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/85284
+       * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions):
+       Only use the niter constraining form of simple_iv when the exit
+       is always executed.
+
 2018-04-09  Tom de Vries  <tom@codesourcery.com>
 
        PR target/84041
index f89ddfe7e9ab6ec2f0b5a3e63b700a1662e31569..6798e3b4b87b95551bcf15acd11b08279da82b28 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-09  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/85284
+       * gcc.dg/torture/pr85284.c: New testcase.
+
 2018-04-09  Andrey Belevantsev  <abel@ispras.ru>
 
        PR rtl-optimization/80463
diff --git a/gcc/testsuite/gcc.dg/torture/pr85284.c b/gcc/testsuite/gcc.dg/torture/pr85284.c
new file mode 100644 (file)
index 0000000..80e2c5b
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+
+static int p[48], v;
+
+int
+main ()
+{
+  p[32] = 1;
+  for (int i = 48; i--;)
+    {
+      if (!p[i])
+       continue;
+      if ((i & 7) > 2)
+       break;
+      v = i & 1;
+    }
+  if (v != 0)
+    __builtin_abort ();
+  return 0;
+}
index fa49abf8d3bed9f1d959ccf7da7e95c013a35274..7a54c5f1e62f538129e96b1c50313d1b0daf08e9 100644 (file)
@@ -2356,11 +2356,11 @@ number_of_iterations_exit_assumptions (struct loop *loop, edge exit,
 
   tree iv0_niters = NULL_TREE;
   if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt),
-                             op0, &iv0, &iv0_niters, false))
+                             op0, &iv0, safe ? &iv0_niters : NULL, false))
     return false;
   tree iv1_niters = NULL_TREE;
   if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt),
-                             op1, &iv1, &iv1_niters, false))
+                             op1, &iv1, safe ? &iv1_niters : NULL, false))
     return false;
   /* Give up on complicated case.  */
   if (iv0_niters && iv1_niters)