aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2016-02-02 15:19:32 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2016-02-02 15:19:32 +0000
commitf9ec342f9f7214a641b9b89412c927bac61aeead (patch)
tree0fb720ef1b494a46acb199b90cbc2d028079a1e1
parent2bf3f448431be10baa9755df5faeed6b2f6508f8 (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233076 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Warray-bounds-17.c13
4 files changed, 41 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9a2cec89cbe..3b548f56a9d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/match.pd b/gcc/match.pd
index 491f769c1dd..6c8ebd5e090 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9d89eee0ebb..9ed6c54535b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
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
* gcc.dg/torture/pr69606.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-17.c b/gcc/testsuite/gcc.dg/Warray-bounds-17.c
new file mode 100644
index 00000000000..e790037feb1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-17.c
@@ -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" } */
+}