+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.
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,
}
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;
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);
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;
}
+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,
--- /dev/null
+/* { 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" } } */
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);
|| 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);
}
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. */
}
-/* 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
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));
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);