This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Remove expr_computes_nonzero


 Hi,

  This patch removes expr_computes_nonzero by moving the only bit in
expr_computes_nonzero that isn't in tree_expr_nonzero_p and then exporting
tree_expr_nonzero_p from fold-const.c.  Bootstrapped and regtested on
ia64-linux, ok for mainline?  The testcase checks that we actually do return
true for tree_expr_nonzero_p for alloca calls.

-- 
Thanks,
Jim

http://www.csclub.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

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.

Index: fold-const.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.605
diff -u -p -r1.605 fold-const.c
--- fold-const.c	20 Jul 2005 03:30:47 -0000	1.605
+++ fold-const.c	20 Jul 2005 17:46:00 -0000
@@ -132,7 +132,6 @@ static bool reorder_operands_p (tree, tr
 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 +9695,12 @@ fold_binary (enum tree_code code, tree t
 	}
 
       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 +10803,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);
@@ -10903,6 +10909,9 @@ tree_expr_nonzero_p (tree t)
     case BIT_IOR_EXPR:
       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;
Index: tree-flow.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.127
diff -u -p -r2.127 tree-flow.h
--- tree-flow.h	19 Jul 2005 03:36:13 -0000	2.127
+++ tree-flow.h	20 Jul 2005 17:46:00 -0000
@@ -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);
 
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.123
diff -u -p -r2.123 tree-ssa-dom.c
--- tree-ssa-dom.c	13 Jul 2005 15:21:05 -0000	2.123
+++ tree-ssa-dom.c	20 Jul 2005 17:46:00 -0000
@@ -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);
     }
 
Index: tree-vrp.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.41
diff -u -p -r2.41 tree-vrp.c
--- tree-vrp.c	14 Jul 2005 22:54:28 -0000	2.41
+++ tree-vrp.c	20 Jul 2005 17:46:00 -0000
@@ -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_ran
      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));
Index: tree.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree.h,v
retrieving revision 1.747
diff -u -p -r1.747 tree.h
--- tree.h	20 Jul 2005 01:18:33 -0000	1.747
+++ tree.h	20 Jul 2005 17:46:00 -0000
@@ -3851,6 +3851,8 @@ extern enum tree_code swap_tree_comparis
 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);
/* { 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" } } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]