re PR tree-optimization/83255 ([graphite] Wrong code w/ -O1 -floop-nest-optimize)
authorRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2017 14:04:36 +0000 (14:04 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 4 Dec 2017 14:04:36 +0000 (14:04 +0000)
2017-12-04  Richard Biener  <rguenther@suse.de>

PR tree-optimization/83255
* graphite-isl-ast-to-gimple.c (translate_isl_ast_node_for):
Re-add zero-iteration check.

* gcc.dg/graphite/pr83255.c: New testcase.

From-SVN: r255382

gcc/ChangeLog
gcc/graphite-isl-ast-to-gimple.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/graphite/pr83255.c [new file with mode: 0644]

index 3b0f55ffe26ecc37ec466989732996269afdf32a..c73452a5f09ed22343e978671358ba544acc1135 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-04  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83255
+       * graphite-isl-ast-to-gimple.c (translate_isl_ast_node_for):
+       Re-add zero-iteration check.
+
 2017-12-04  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR rtl-optimization/83245
index 16570e16855725f0b0280fa6a730997e0f10f75a..c565cf003794b61b82ccc3e22d869d316321bafc 100644 (file)
@@ -720,6 +720,32 @@ translate_isl_ast_node_for (loop_p context_loop, __isl_keep isl_ast_node *node,
     ub = integer_zero_node;
 
   edge last_e = single_succ_edge (split_edge (next_e));
+
+  /* Compensate for the fact that we emit a do { } while loop from
+     a for ISL AST.
+     ???  We often miss constraints on niter because the SESE region
+     doesn't cover loop header copies.  Ideally we'd add constraints
+     for all relevant dominating conditions.  */
+  if (TREE_CODE (lb) == INTEGER_CST && TREE_CODE (ub) == INTEGER_CST
+      && tree_int_cst_compare (lb, ub) <= 0)
+    ;
+  else
+    {
+      tree one = build_one_cst (POINTER_TYPE_P (type) ? sizetype : type);
+      /* Adding +1 and using LT_EXPR helps with loop latches that have a
+        loop iteration count of "PARAMETER - 1".  For PARAMETER == 0 this
+        becomes 2^k-1 due to integer overflow, and the condition lb <= ub
+        is true, even if we do not want this.  However lb < ub + 1 is false,
+        as expected.  */
+      tree ub_one = fold_build2 (POINTER_TYPE_P (type)
+                                ? POINTER_PLUS_EXPR : PLUS_EXPR,
+                                type, ub, one);
+      create_empty_if_region_on_edge (next_e,
+                                     fold_build2 (LT_EXPR, boolean_type_node,
+                                                  lb, ub_one));
+      next_e = get_true_edge_from_guard_bb (next_e->dest);
+    }
+
   translate_isl_ast_for_loop (context_loop, node, next_e,
                              type, lb, ub, ip);
   return last_e;
index d49bbe483c12ee9bef9523e1a401db1c5e8247bc..4d02ff726fbc590c45c8fe4061d6a856a32b4ca4 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-04  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83255
+       * gcc.dg/graphite/pr83255.c: New testcase.
+
 2017-12-04  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/83238
diff --git a/gcc/testsuite/gcc.dg/graphite/pr83255.c b/gcc/testsuite/gcc.dg/graphite/pr83255.c
new file mode 100644 (file)
index 0000000..cb376fa
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+/* { dg-options "-O -floop-nest-optimize -fdump-tree-graphite-details" } */
+
+int rx, in;
+
+int
+main (void)
+{
+  const int tj = 3;
+  int as[tj];
+  static int l4;
+
+  while (l4 < 1)
+    {
+      for (rx = 0; rx < tj; ++rx)
+       {
+         for (in = 0; in < tj; ++in)
+           as[in] = 1;
+         as[rx] = 0;
+       }
+      ++l4;
+    }
+
+  if (as[tj - 1] != 0)
+    __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump "loop nest optimized" "graphite" } } */