summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>2005-07-20 20:26:11 +0000
committerphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>2005-07-20 20:26:11 +0000
commitde4528367818c560d1b1ac6c607dec6cbc21cfcb (patch)
tree7f921cc272661cbe1016b176fa359221ff219a4f
parentb90ce3c3209f7c3d8c939bb687ad22f3c97b36c7 (diff)
downloadgcc-de4528367818c560d1b1ac6c607dec6cbc21cfcb.tar.gz
2005-07-20 James A. Morrison <phython@gcc.gnu.org>
* tree.h (tree_expr_nonzero_p): Export. * fold-const.c (tree_expr_nonzero_p): Likewise. Return true for CALL_EXPRs that are alloca calls. (fold_binary): Use omit_one_operand when checking EQ_EXPRs or NE_EXPRs against zero. * tree-flow.h (expr_computes_nonzero): Remove. * tree-vrp.c (expr_computes_nonzero): Remove. (vrp_expr_computes_nonzero): Use tree_expr_nonzero_p. (extract_range_from_unary_expr): Likewise. * tree-ssa-dom.c (record_equivalences_from_stmt): Use tree_expr_nonzero_p. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102201 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/fold-const.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/fold-alloca-1.c14
-rw-r--r--gcc/tree-flow.h1
-rw-r--r--gcc/tree-ssa-dom.c2
-rw-r--r--gcc/tree-vrp.c36
-rw-r--r--gcc/tree.h2
8 files changed, 46 insertions, 39 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index da0313f1915..ba47d056cbf 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,17 @@
+2005-07-20 James A. Morrison <phython@gcc.gnu.org>
+
+ * tree.h (tree_expr_nonzero_p): Export.
+ * fold-const.c (tree_expr_nonzero_p): Likewise.
+ Return true for CALL_EXPRs that are alloca calls.
+ (fold_binary): Use omit_one_operand when checking EQ_EXPRs or NE_EXPRs
+ against zero.
+ * tree-flow.h (expr_computes_nonzero): Remove.
+ * tree-vrp.c (expr_computes_nonzero): Remove.
+ (vrp_expr_computes_nonzero): Use tree_expr_nonzero_p.
+ (extract_range_from_unary_expr): Likewise.
+ * tree-ssa-dom.c (record_equivalences_from_stmt): Use
+ tree_expr_nonzero_p.
+
2005-07-20 Bernd Schmidt <bernd.schmidt@analog.com>
* config/bfin/bfin-protos.h (legitimize_pic_address): Don't declare.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e9d88d1e6c3..7b83eb3ef5f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -132,7 +132,6 @@ static bool reorder_operands_p (tree, tree);
static tree fold_negate_const (tree, tree);
static tree fold_not_const (tree, tree);
static tree fold_relational_const (enum tree_code, tree, tree, tree);
-static bool tree_expr_nonzero_p (tree);
/* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring
overflow. Suppose A, B and SUM have the same respective signs as A1, B1,
@@ -9694,10 +9693,12 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
}
if ((code == EQ_EXPR || code == NE_EXPR)
- && !TREE_SIDE_EFFECTS (arg0)
&& integer_zerop (arg1)
&& tree_expr_nonzero_p (arg0))
- return constant_boolean_node (code==NE_EXPR, type);
+ {
+ tree res = constant_boolean_node (code==NE_EXPR, type);
+ return omit_one_operand (type, res, arg0);
+ }
t1 = fold_relational_const (code, type, arg0, arg1);
return t1 == NULL_TREE ? NULL_TREE : t1;
@@ -10797,7 +10798,7 @@ tree_expr_nonnegative_p (tree t)
For floating point we further ensure that T is not denormal.
Similar logic is present in nonzero_address in rtlanal.h. */
-static bool
+bool
tree_expr_nonzero_p (tree t)
{
tree type = TREE_TYPE (t);
@@ -10904,6 +10905,9 @@ tree_expr_nonzero_p (tree t)
return tree_expr_nonzero_p (TREE_OPERAND (t, 1))
|| tree_expr_nonzero_p (TREE_OPERAND (t, 0));
+ case CALL_EXPR:
+ return alloca_call_p (t);
+
default:
break;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ab5287beb73..acbc2d6bc0a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-07-20 James A. Morrison <phython@gcc.gnu.org>
+
+ * gcc.dg/fold-alloc-1.c: New test.
+
2005-07-20 Kazu Hirata <kazu@codesourcery.com>
* gcc.dg/20020312-2.c, gcc.dg/sibcall-3.c, gcc.dg/sibcall-4.c,
diff --git a/gcc/testsuite/gcc.dg/fold-alloca-1.c b/gcc/testsuite/gcc.dg/fold-alloca-1.c
new file mode 100644
index 00000000000..735a22f3a7e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-alloca-1.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-useless" } */
+
+void *alloca (__SIZE_TYPE__);
+void link_error ();
+
+int main (int argc, char *argv[]) {
+ char *foo;
+ if ((foo = alloca(argc)) == 0)
+ link_error ();
+ return 0;
+}
+/* { dg-final { scan-tree-dump-times "link_error" 0 "useless" } } */
+/* { dg-final { cleanup-tree-dump "useless" } } */
diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h
index da49ed199e9..16bcb803c3e 100644
--- a/gcc/tree-flow.h
+++ b/gcc/tree-flow.h
@@ -659,7 +659,6 @@ bool fold_stmt_inplace (tree);
tree widen_bitfield (tree, tree, tree);
/* In tree-vrp.c */
-bool expr_computes_nonzero (tree);
tree vrp_evaluate_conditional (tree, bool);
void simplify_stmt_using_ranges (tree);
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 2514a49fc5d..7b79c79caa3 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -2633,7 +2633,7 @@ record_equivalences_from_stmt (tree stmt,
|| is_gimple_min_invariant (rhs)))
SSA_NAME_VALUE (lhs) = rhs;
- if (expr_computes_nonzero (rhs))
+ if (tree_expr_nonzero_p (rhs))
record_var_is_nonzero (lhs);
}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index a42a21a882e..e7d877d7d58 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -95,36 +95,6 @@ static sbitmap blocks_visited;
static value_range_t **vr_value;
-/* Return true if EXPR computes a non-zero value. */
-
-bool
-expr_computes_nonzero (tree expr)
-{
- /* Type casts won't change anything, so just strip them. */
- STRIP_NOPS (expr);
-
- /* Calling alloca, guarantees that the value is non-NULL. */
- if (alloca_call_p (expr))
- return true;
-
- /* The address of a non-weak symbol is never NULL, unless the user
- has requested not to remove NULL pointer checks. */
- if (flag_delete_null_pointer_checks
- && TREE_CODE (expr) == ADDR_EXPR
- && VAR_OR_FUNCTION_DECL_P (TREE_OPERAND (expr, 0))
- && !DECL_WEAK (TREE_OPERAND (expr, 0)))
- return true;
-
- /* IOR of any value with a nonzero value will result in a nonzero
- value. */
- if (TREE_CODE (expr) == BIT_IOR_EXPR
- && integer_nonzerop (TREE_OPERAND (expr, 1)))
- return true;
-
- return false;
-}
-
-
/* Return true if ARG is marked with the nonnull attribute in the
current function signature. */
@@ -393,13 +363,13 @@ symbolic_range_p (value_range_t *vr)
}
-/* Like expr_computes_nonzero, but this function uses value ranges
+/* Like tree_expr_nonzero_p, but this function uses value ranges
obtained so far. */
static bool
vrp_expr_computes_nonzero (tree expr)
{
- if (expr_computes_nonzero (expr))
+ if (tree_expr_nonzero_p (expr))
return true;
/* If we have an expression of the form &X->a, then the expression
@@ -1319,7 +1289,7 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
determining if it evaluates to NULL [0, 0] or non-NULL (~[0, 0]). */
if (POINTER_TYPE_P (TREE_TYPE (expr)) || POINTER_TYPE_P (TREE_TYPE (op0)))
{
- if (range_is_nonnull (&vr0) || expr_computes_nonzero (expr))
+ if (range_is_nonnull (&vr0) || tree_expr_nonzero_p (expr))
set_value_range_to_nonnull (vr, TREE_TYPE (expr));
else if (range_is_null (&vr0))
set_value_range_to_null (vr, TREE_TYPE (expr));
diff --git a/gcc/tree.h b/gcc/tree.h
index b9cd508edd0..10472fe839b 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3851,6 +3851,8 @@ extern enum tree_code swap_tree_comparison (enum tree_code);
extern bool ptr_difference_const (tree, tree, HOST_WIDE_INT *);
extern enum tree_code invert_tree_comparison (enum tree_code, bool);
+extern bool tree_expr_nonzero_p (tree);
+
/* In builtins.c */
extern tree fold_builtin (tree, tree, bool);
extern tree fold_builtin_fputs (tree, bool, bool, tree);