re PR tree-optimization/21294 (Missed removal of null pointer check)
authorKazu Hirata <kazu@cs.umass.edu>
Mon, 2 May 2005 18:06:27 +0000 (18:06 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Mon, 2 May 2005 18:06:27 +0000 (18:06 +0000)
gcc/
PR tree-optimization/21294
* tree-vrp.c (vrp_expr_computes_nonzero): New.
(extract_range_from_expr): Call vrp_expr_computes_nonzero.

testsuite/
PR tree-optimization/21294
* gcc.dg/tree-ssa/pr21294.c: New.

From-SVN: r99111

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

index d3d7f07ea1288d591d32bf081f40f602fdd8af6c..20bf784b637da4f40e0a664754d125253e8fb986 100644 (file)
@@ -1,3 +1,9 @@
+2005-05-02  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR tree-optimization/21294
+       * tree-vrp.c (vrp_expr_computes_nonzero): New.
+       (extract_range_from_expr): Call vrp_expr_computes_nonzero.
+
 2005-05-02  Janis Johnson  <janis187@us.ibm.com>
 
        PR 19985
index 7c5caab0e0587b79f5a7f5637078c9c7d2f9a04b..46c9e1db3ee31eda4f005c14da141eb4b888da41 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-02  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR tree-optimization/21294
+       * gcc.dg/tree-ssa/pr21294.c: New.
+
 2005-05-02  Paolo Bonzini  <bonzini@gnu.org>
 
         * gcc.dg/altivec-3.c (vec_store): Do not use the old
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21294.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21294.c
new file mode 100644 (file)
index 0000000..dc90dbd
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/21294
+   VRP did not notice that an address of the form &p->i is nonnull
+   when p is known to be nonnull.  In this testcase, noticing that
+   allows us to eliminate the second "if" statement.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-vrp-details" } */
+
+struct f {
+  int i;
+};
+
+int
+foo (struct f *p)
+{
+  if (p != 0)
+    if (&p->i != 0)
+      return 123;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate" 1 "vrp"} } */
+/* { dg-final { cleanup-tree-dump "vrp" } } */
index 0fe5c7bcbbbdaec452840a1d4a9ff6db2c14e6b9..e6cb017bba07993884ab08f40a59ef194bb5d5a2 100644 (file)
@@ -717,6 +717,35 @@ extract_range_from_binary_expr (value_range *vr, tree expr)
 }
 
 
+/* Like expr_computes_nonzero, but this function uses value ranges
+   obtained so far.  */
+
+static bool
+vrp_expr_computes_nonzero (tree expr)
+{
+  if (expr_computes_nonzero (expr))
+    return true;
+
+  /* If we have an expression of the form &X->a, then the expression
+     is nonnull if X is nonnull.  */
+  if (TREE_CODE (expr) == ADDR_EXPR)
+    {
+      tree base = get_base_address (TREE_OPERAND (expr, 0));
+
+      if (base != NULL_TREE
+         && TREE_CODE (base) == INDIRECT_REF
+         && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
+       {
+         value_range *vr = get_value_range (TREE_OPERAND (base, 0));
+         if (range_is_nonnull (vr))
+           return true;
+       }
+    }
+
+  return false;
+}
+
+
 /* Extract range information from a unary expression EXPR based on
    the range of its operand and the expression code.  */
 
@@ -833,7 +862,7 @@ extract_range_from_expr (value_range *vr, tree expr)
     extract_range_from_binary_expr (vr, expr);
   else if (TREE_CODE_CLASS (code) == tcc_unary)
     extract_range_from_unary_expr (vr, expr);
-  else if (expr_computes_nonzero (expr))
+  else if (vrp_expr_computes_nonzero (expr))
     set_value_range_to_nonnull (vr, TREE_TYPE (expr));
   else if (TREE_CODE (expr) == INTEGER_CST)
     set_value_range (vr, VR_RANGE, expr, expr);