re PR tree-optimization/69595 (Bogus -Warray-bound warning due to missed optimization)
authorRichard Biener <rguenther@suse.de>
Tue, 2 Feb 2016 15:19:32 +0000 (15:19 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Feb 2016 15:19:32 +0000 (15:19 +0000)
2016-02-02  Richard Biener  <rguenther@suse.de>

PR tree-optimization/69595
* match.pd: Add range test simplifications to true/false.

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

From-SVN: r233076

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-17.c [new file with mode: 0644]

index 9a2cec89cbe6a2af69f2790fa1f72dc73c7db6a1..3b548f56a9d07c4edf4614d1cd3f0b67d80657b9 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-02  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/69595
+       * match.pd: Add range test simplifications to true/false.
+
 2016-02-02  Thomas Schwinge  <thomas@codesourcery.com>
 
        * omp-builtins.def (BUILT_IN_GOACC_HOST_DATA): Remove.
index 491f769c1ddb44aaa2605248a26329df6b9f4b09..6c8ebd5e0906fc8700961723cf08c969fc58534e 100644 (file)
@@ -2094,6 +2094,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_and:c (ordered @0 @0) (ordered:c@2 @0 @1))
  @2)
 
+/* Simple range test simplifications.  */
+/* A < B || A >= B -> true.  */
+(for test1 (lt le ne)
+     test2 (ge gt eq)
+ (simplify
+  (bit_ior:c (test1 @0 @1) (test2 @0 @1))
+  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+       || VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)))
+   { constant_boolean_node (true, type); })))
+/* A < B && A >= B -> false.  */
+(for test1 (lt lt lt le ne eq)
+     test2 (ge gt eq gt eq gt)
+ (simplify
+  (bit_and:c (test1 @0 @1) (test2 @0 @1))
+  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+       || VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)))
+   { constant_boolean_node (false, type); })))
+
 /* -A CMP -B -> B CMP A.  */
 (for cmp (tcc_comparison)
      scmp (swapped_tcc_comparison)
index 9d89eee0ebba40e20765c5a06e3eea2130ca8fcd..9ed6c54535bdc024e7e0363f00eea32ac9616f85 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-02  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/69595
+       * gcc.dg/Warray-bounds-17.c: New testcase.
+
 2016-02-02  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/69606
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-17.c b/gcc/testsuite/gcc.dg/Warray-bounds-17.c
new file mode 100644 (file)
index 0000000..e790037
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Warray-bounds" } */
+
+char *y;
+void foo (int sysnum)
+{
+  static char *x[] = {};
+  int nsyscalls = sizeof x / sizeof x[0];
+  if (sysnum < 0 || sysnum >= nsyscalls)
+    return;
+  else
+    y = x[sysnum]; /* { dg-bogus "above array bounds" } */
+}