re PR tree-optimization/86232 (ICE in record_estimate, at tree-ssa-loop-niter.c:3258)
authorRichard Biener <rguenther@suse.de>
Thu, 21 Jun 2018 11:22:12 +0000 (11:22 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 21 Jun 2018 11:22:12 +0000 (11:22 +0000)
2018-06-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/86232
* tree-ssa-loop-niter.c (number_of_iterations_popcount): Adjust
max for constant niter.

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

From-SVN: r261843

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

index 1e851db45c6a4a65e38604580c981a2a581fcadf..09af13477587ac14361f995b6083fc54542b813d 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86232
+       * tree-ssa-loop-niter.c (number_of_iterations_popcount): Adjust
+       max for constant niter.
+
 2018-06-21  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        * config/aarch64/aarch64-simd.md
index e32abfaeb0eeba7cf61b9cd94bdf827721f85046..3d53dd41937cbd52b012802200ff1cde296f0bb2 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86232
+       * gcc.dg/torture/pr86232.c: New testcase.
+
 2018-06-21  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        * gcc/gcc.target/aarch64/aes_xor_combine.c: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr86232.c b/gcc/testsuite/gcc.dg/torture/pr86232.c
new file mode 100644 (file)
index 0000000..f5b61d3
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+enum { a = 1 } b;
+int c()
+{
+  int d = a;
+  for (; d;)
+    d &= d - 1;
+  return b;
+}
index 936591502d0b3f7232f9500175e8311a61895c59..f5ffc0f19ad4b3889d92b8cc4ee7f86f781fe6fe 100644 (file)
@@ -2575,9 +2575,6 @@ number_of_iterations_popcount (loop_p loop, edge exit,
     return false;
 
   /* Update NITER params accordingly  */
-  max = TYPE_PRECISION (TREE_TYPE (src));
-  if (adjust)
-    max = max - 1;
   tree utype = unsigned_type_for (TREE_TYPE (src));
   src = fold_convert (utype, src);
   tree call = fold_convert (utype, build_call_expr (fn, 1, src));
@@ -2588,6 +2585,15 @@ number_of_iterations_popcount (loop_p loop, edge exit,
   else
     iter = call;
 
+  if (TREE_CODE (call) == INTEGER_CST)
+    max = tree_to_uhwi (call);
+  else
+    {
+      max = TYPE_PRECISION (TREE_TYPE (src));
+      if (adjust)
+       max = max - 1;
+    }
+
   niter->niter = iter;
   niter->assumptions = boolean_true_node;
   if (adjust)