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]

[RFC] Nonnegative improvements


 Hi,

  I'm looking for comments about hooking value range data into the
simplification code, starting with a nonnegative property.  The attached
patch has seen some light testing, but I'm looking for comments about the
approach.

-- 
Thanks,
Jim

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

Index: fold-const.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.597
diff -u -p -r1.597 fold-const.c
--- fold-const.c	18 Jun 2005 19:57:02 -0000	1.597
+++ fold-const.c	19 Jun 2005 11:24:39 -0000
 int
 tree_expr_nonnegative_p (tree t)
 {
+  if (TYPE_UNSIGNED (TREE_TYPE (t)))
+    return 1;
+
   switch (TREE_CODE (t))
     {
     case ABS_EXPR:
@@ -10480,6 +10539,9 @@ tree_expr_nonnegative_p (tree t)
     case REAL_CST:
       return ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
 
+    case SSA_NAME:
+      return vrp_nonnegative_p (t);
+
     case PLUS_EXPR:
       if (FLOAT_TYPE_P (TREE_TYPE (t)))
 	return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
Index: tree-vrp.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.30
diff -u -p -r2.30 tree-vrp.c
--- tree-vrp.c	16 Jun 2005 21:25:00 -0000	2.30
+++ tree-vrp.c	19 Jun 2005 11:24:39 -0000
@@ -3443,12 +3443,28 @@ simplify_using_ranges (void)
       for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
 	{
 	  tree stmt = bsi_stmt (bsi);
+	  tree result;
 
 	  if (TREE_CODE (stmt) == MODIFY_EXPR)
 	    {
 	      tree rhs = TREE_OPERAND (stmt, 1);
 	      enum tree_code rhs_code = TREE_CODE (rhs);
 
+	      if (rhs_code == ASSERT_EXPR)
+		continue;
+
+	      result = fold (rhs);
+
+	      /* Strip away useless type conversions.  Both the
+		 NON_LVALUE_EXPR that may have been added by fold, and
+		 "useless" type conversions that might now be apparent due to
+		 propagation.  */
+	      STRIP_USELESS_TYPE_CONVERSION (result);
+
+	      if (result != rhs && set_rhs (&stmt, result))
+		continue;
+
+
 	      /* Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR
 		 and BIT_AND_EXPR respectively if the first operand is greater
 		 than zero and the second operand is an exact power of two.  */
@@ -3608,6 +3624,7 @@ vrp_finalize (void)
 
   free (single_val_range);
   free (vr_value);
+  vr_value = NULL;
 }
 
 
@@ -3704,3 +3721,25 @@ struct tree_opt_pass pass_vrp =
     | TODO_update_ssa,			/* todo_flags_finish */
   0					/* letter */
 };
+
+/* If it can be determined if T is nonnegative using VRP data, then return 1,
+   otherwise return 0.
+ */
+
+int
+vrp_nonnegative_p (tree t)
+{
+  tree val;
+  value_range_t *vr;
+  
+  if (!vr_value)
+    return 0;
+
+  vr = get_value_range (t);
+  if (TYPE_UNSIGNED (TREE_TYPE (t)))
+    val = integer_one_node;
+  else
+    val = compare_range_with_value (GE_EXPR, vr, integer_zero_node);
+
+  return val && integer_onep (val);
+}
Index: tree.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree.h,v
retrieving revision 1.737
diff -u -p -r1.737 tree.h
--- tree.h	16 Jun 2005 18:09:34 -0000	1.737
+++ tree.h	19 Jun 2005 11:24:39 -0000
@@ -3618,6 +3618,9 @@ 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);
 
+/* In tree-vrp.c */
+extern int vrp_nonnegative_p (tree);
+
 /* In builtins.c */
 extern tree fold_builtin (tree, tree, bool);
 extern tree fold_builtin_fputs (tree, bool, bool, tree);

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