re PR tree-optimization/71433 (-Warray-bounds false positive with -O2)
authorRichard Biener <rguenther@suse.de>
Tue, 17 Jan 2017 08:38:59 +0000 (08:38 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 17 Jan 2017 08:38:59 +0000 (08:38 +0000)
2017-01-17  Richard Biener  <rguenther@suse.de>

PR tree-optimization/71433
* tree-vrp.c (register_new_assert_for): Merge same asserts
on all incoming edges.
(process_assert_insertions_for): Handle insertions at the
beginning of BBs.

* gcc.dg/Warray-bounds-20.c: New testcase.

From-SVN: r244520

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-20.c [new file with mode: 0644]
gcc/tree-vrp.c

index bb2fc9f..6d443fc 100644 (file)
@@ -1,3 +1,11 @@
+2017-01-17  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71433
+       * tree-vrp.c (register_new_assert_for): Merge same asserts
+       on all incoming edges.
+       (process_assert_insertions_for): Handle insertions at the
+       beginning of BBs.
+
 2017-01-17  Gerald Pfeifer  <gerald@pfeifer.com>
 
        * config/i386/cygwin.h (LIBGCJ_SONAME): Remove.
index add78e2..4bc9f27 100644 (file)
@@ -1,5 +1,10 @@
 2017-01-17  Richard Biener  <rguenther@suse.de>
 
+       PR tree-optimization/71433
+       * gcc.dg/Warray-bounds-20.c: New testcase.
+
+2017-01-17  Richard Biener  <rguenther@suse.de>
+
        PR testsuite/52563
        PR testsuite/71237
        PR testsuite/77737
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-20.c b/gcc/testsuite/gcc.dg/Warray-bounds-20.c
new file mode 100644 (file)
index 0000000..727b799
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Warray-bounds" } */
+
+int t[1];
+int fct (int r, long e)
+{
+  int d = 0;
+  if (r == 4)
+    r = 1;
+  if (e < -52)
+    d = r == 0 ? 1 : 2;
+  else
+    {
+      int i, n = 53;
+      if (__builtin_expect (e < 0, 0))
+       n += e;
+      for (i = 1 ; i < n / 64 + 1 ; i++)
+       t[i] = 0; /* { dg-bogus "array bounds" } */
+    }
+  return d;
+}
index 4cfdd0a..ac37d3f 100644 (file)
@@ -5032,6 +5032,17 @@ register_new_assert_for (tree name, tree expr,
              loc->si = si;
              return;
            }
+         /* If we have the same assertion on all incoming edges of a BB
+            instead insert it at the beginning of it.  */
+         if (e && loc->e
+             && dest_bb == loc->e->dest
+             && EDGE_COUNT (dest_bb->preds) == 2)
+           {
+             loc->bb = dest_bb;
+             loc->e = NULL;
+             loc->si = gsi_none ();
+             return;
+           }
        }
 
       /* Update the last node of the list and move to the next one.  */
@@ -6429,6 +6440,15 @@ process_assert_insertions_for (tree name, assert_locus *loc)
       return true;
     }
 
+  /* If the stmt iterator points at the end then this is an insertion
+     at the beginning of a block.  */
+  if (gsi_end_p (loc->si))
+    {
+      gimple_stmt_iterator si = gsi_after_labels (loc->bb);
+      gsi_insert_before (&si, assert_stmt, GSI_SAME_STMT);
+      return false;
+
+    }
   /* Otherwise, we can insert right after LOC->SI iff the
      statement must not be the last statement in the block.  */
   stmt = gsi_stmt (loc->si);