OSDN Git Service

2005-07-29 James A. Morrison <phython@gcc.gnu.org>
authorphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Jul 2005 15:22:07 +0000 (15:22 +0000)
committerphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Jul 2005 15:22:07 +0000 (15:22 +0000)
        * tree-vrp.c (compare_range_with_value): Return true or false
        for ~[VAL_1, VAL_2] OP VAL if VAL_1 <= VAL <= VAL_2 for NE_EXPR and
        EQ_EXPR respectively.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102558 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/vrp19.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/vrp20.c [new file with mode: 0644]
gcc/tree-vrp.c

index ef9d11e..6ddd432 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-29  James A. Morrison  <phython@gcc.gnu.org>
+
+       * tree-vrp.c (compare_range_with_value): Return true or false
+       for ~[VAL_1, VAL_2] OP VAL if VAL_1 <= VAL <= VAL_2 for NE_EXPR and
+       EQ_EXPR respectively.
+
 2005-07-29  Kazu Hirata  <kazu@codesourcery.com>
 
        * cfg.c, tree-complex.c, config/frv/frv.c, config/i386/i386.c:
index acb1606..cf45c8a 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-29  James A. Morrison  <phython@gcc.gnu.org>
+
+       * gcc.dg/tree-ssa/vrp19.c: New test.
+       * gcc.dg/tree-ssa-vrp20.c: New test.
+
 2005-07-29  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR c/22240
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp19.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp19.c
new file mode 100644 (file)
index 0000000..45a85fa
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-fwrapv -O1 -ftree-vrp -fdump-tree-vrp" } */
+
+#include <limits.h>
+extern void abort ();
+extern void exit (int);
+
+int f (int a) {
+       if (a != INT_MIN) {
+               a = a > 0 ? a : -a;
+               if (a < 0)
+                 return 1;
+       }
+       return 0;
+}
+
+int g (int b) {
+       if (b != INT_MIN) {
+               b = b > 0 ? b : -b;
+               if (b >= 0)
+                 return 0;
+       }
+       return 1;
+}
+/* { dg-final { scan-tree-dump "Folding predicate a_. < 0 to 0" "vrp" } } */
+/* { dg-final { scan-tree-dump "Folding predicate b_. >= 0 to 1" "vrp" } } */
+/* { dg-final { cleanup-tree-dump "vrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp20.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp20.c
new file mode 100644 (file)
index 0000000..91c195b
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-fwrapv -O1 -ftree-vrp -fdump-tree-vrp" } */
+
+extern void abort ();
+extern void exit (int);
+
+int f (int a) {
+       if (a != 0) {
+               a = a > 0 ? a : -a;
+               if (a == 0)
+                 return 1;
+               return 0;
+       }
+       return 0;
+}
+
+int g (int b) {
+       if (b != 0) {
+               b = b > 0 ? b : -b;
+               if (b != 0)
+                 return 0;
+       }
+       return 1;
+}
+
+/* { dg-final { scan-tree-dump "Folding predicate a_. == 0 to 0" "vrp" } } */
+/* { dg-final { scan-tree-dump "Folding predicate b_. != 0 to 1" "vrp" } } */
+/* { dg-final { cleanup-tree-dump "vrp" } } */
index 4afe415..68960e5 100644 (file)
@@ -1753,9 +1753,8 @@ compare_range_with_value (enum tree_code comp, value_range_t *vr, tree val)
          || comp == LE_EXPR)
        return NULL_TREE;
 
-      /* ~[VAL, VAL] == VAL is always false.  */
-      if (compare_values (vr->min, val) == 0
-         && compare_values (vr->max, val) == 0)
+      /* ~[VAL_1, VAL_2] OP VAL is known if VAL_1 <= VAL <= VAL_2.  */
+      if (value_inside_range (val, vr) == 1)
        return (comp == NE_EXPR) ? boolean_true_node : boolean_false_node;
 
       return NULL_TREE;