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][trunk] refactoring in tree-vrp.c


This patch removes the special treatment of "comparisons" with only
one variable by handling them as "foo == true". It also changes some
functions to receive the code and arguments instead of the comparison
tree.

This has been extracted from my patch enabling vrp on tuples (should
follow soon). Tested with a bootstrap and regression tests.

* tree-flow.h (vrp_evaluate_conditional): Change signature.
* tree-ssa-propagate.c (fold_predicate_in): Update call to
vrp_evaluate_conditional.
* tree-vrp.c (vrp_evaluate_conditional_warnv): Remove.
             (vrp_evaluate_conditional): Split the cond argument.
             (vrp_visit_cond_stmt): Use vrp_evaluate_conditional_warnv_with_ops.
             (simplify_stmt_for_jump_threading): Update call to
vrp_evaluate_conditional.

Cheers,
-- 
Rafael Avila de Espindola

Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland

Registered in Dublin, Ireland
Registration Number: 368047
diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h
index 03d1ba5..f26181f 100644
--- a/gcc/tree-flow.h
+++ b/gcc/tree-flow.h
@@ -944,7 +944,7 @@ tree get_symbol_constant_value (tree);
 tree fold_const_aggregate_ref (tree);
 
 /* In tree-vrp.c  */
-tree vrp_evaluate_conditional (tree, tree);
+tree vrp_evaluate_conditional (enum tree_code, tree, tree, tree);
 void simplify_stmt_using_ranges (tree);
 
 /* In tree-ssa-dom.c  */
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index c37cfa5..6423ec6 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1148,7 +1148,17 @@ fold_predicate_in (tree stmt)
   else
     return false;
 
-  val = vrp_evaluate_conditional (*pred_p, stmt);
+  if (TREE_CODE (*pred_p) == SSA_NAME)
+    val = vrp_evaluate_conditional (EQ_EXPR,
+				    *pred_p,
+				    boolean_true_node,
+				    stmt);
+  else
+    val = vrp_evaluate_conditional (TREE_CODE (*pred_p),
+				    TREE_OPERAND (*pred_p, 0),
+				    TREE_OPERAND (*pred_p, 1),
+				    stmt);
+
   if (val)
     {
       if (modify_stmt_p)
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index e9106c4..0b6fb33 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -46,7 +46,6 @@ static sbitmap found_in_subgraph;
 static int compare_values (tree val1, tree val2);
 static int compare_values_warnv (tree val1, tree val2, bool *);
 static void vrp_meet (value_range_t *, value_range_t *);
-static tree vrp_evaluate_conditional_warnv (tree, bool, bool *);
 static tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code,
 						     tree, tree, bool, bool *);
 
@@ -5274,64 +5273,7 @@ vrp_evaluate_conditional_warnv_with_ops (enum tree_code code, tree op0,
   return NULL_TREE;
 }
 
-/* Given a conditional predicate COND, try to determine if COND yields
-   true or false based on the value ranges of its operands.  Return
-   BOOLEAN_TRUE_NODE if the conditional always evaluates to true,
-   BOOLEAN_FALSE_NODE if the conditional always evaluates to false, and,
-   NULL if the conditional cannot be evaluated at compile time.
-
-   If USE_EQUIV_P is true, the ranges of all the names equivalent with
-   the operands in COND are used when trying to compute its value.
-   This is only used during final substitution.  During propagation,
-   we only check the range of each variable and not its equivalents.
-
-   Set *STRICT_OVERFLOW_P to indicate whether we relied on an overflow
-   infinity to produce the result.  */
-
-static tree
-vrp_evaluate_conditional_warnv (tree cond, bool use_equiv_p,
-				bool *strict_overflow_p)
-{
-  gcc_assert (TREE_CODE (cond) == SSA_NAME
-              || TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison);
-
-  if (TREE_CODE (cond) == SSA_NAME)
-    {
-      value_range_t *vr;
-      tree retval;
-
-      if (use_equiv_p)
-	retval = compare_name_with_value (NE_EXPR, cond, boolean_false_node,
-					  strict_overflow_p);
-      else
-	{
-	  value_range_t *vr = get_value_range (cond);
-	  retval = compare_range_with_value (NE_EXPR, vr, boolean_false_node,
-					     strict_overflow_p);
-	}
-
-      /* If COND has a known boolean range, return it.  */
-      if (retval)
-	return retval;
-
-      /* Otherwise, if COND has a symbolic range of exactly one value,
-	 return it.  */
-      vr = get_value_range (cond);
-      if (vr->type == VR_RANGE && vr->min == vr->max)
-	return vr->min;
-    }
-  else
-    return vrp_evaluate_conditional_warnv_with_ops (TREE_CODE (cond),
-						    TREE_OPERAND (cond, 0),
-						    TREE_OPERAND (cond, 1),
-						    use_equiv_p,
-						    strict_overflow_p);
-
-  /* Anything else cannot be computed statically.  */
-  return NULL_TREE;
-}
-
-/* Given COND within STMT, try to simplify it based on value range
+/* Given (CODE OP0 OP1) within STMT, try to simplify it based on value range
    information.  Return NULL if the conditional can not be evaluated.
    The ranges of all the names equivalent with the operands in COND
    will be used when trying to compute the value.  If the result is
@@ -5339,13 +5281,17 @@ vrp_evaluate_conditional_warnv (tree cond, bool use_equiv_p,
    appropriate.  */
 
 tree
-vrp_evaluate_conditional (tree cond, tree stmt)
+vrp_evaluate_conditional (enum tree_code code, tree op0, tree op1, tree stmt)
 {
   bool sop;
   tree ret;
 
   sop = false;
-  ret = vrp_evaluate_conditional_warnv (cond, true, &sop);
+  ret = vrp_evaluate_conditional_warnv_with_ops (code,
+						 op0,
+						 op1,
+						 true,
+						 &sop);
 
   if (ret && sop)
     {
@@ -5379,8 +5325,8 @@ vrp_evaluate_conditional (tree cond, tree stmt)
 
   if (warn_type_limits
       && ret
-      && TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
-      && TREE_CODE (TREE_OPERAND (cond, 0)) == SSA_NAME)
+      && TREE_CODE_CLASS (code) == tcc_comparison
+      && TREE_CODE (op0) == SSA_NAME)
     {
       /* If the comparison is being folded and the operand on the LHS
 	 is being compared against a constant value that is outside of
@@ -5388,8 +5334,6 @@ vrp_evaluate_conditional (tree cond, tree stmt)
 	 always fold regardless of the value of OP0.  If -Wtype-limits
 	 was specified, emit a warning.  */
       const char *warnmsg = NULL;
-      tree op0 = TREE_OPERAND (cond, 0);
-      tree op1 = TREE_OPERAND (cond, 1);
       tree type = TREE_TYPE (op0);
       value_range_t *vr0 = get_value_range (op0);
 
@@ -5501,7 +5445,19 @@ vrp_visit_cond_stmt (tree stmt, edge *taken_edge_p)
      MICO, TRAMP3D and SPEC2000) showed that doing this results in
      4 more predicates folded in SPEC.  */
   sop = false;
-  val = vrp_evaluate_conditional_warnv (cond, false, &sop);
+
+  if (TREE_CODE (cond) == SSA_NAME)
+    val = vrp_evaluate_conditional_warnv_with_ops (EQ_EXPR,
+						   cond,
+						   boolean_true_node,
+						   false,
+						   &sop);
+  else
+    val = vrp_evaluate_conditional_warnv_with_ops (TREE_CODE (cond),
+						   TREE_OPERAND (cond, 0),
+						   TREE_OPERAND (cond, 1),
+						   false,
+						   &sop);
   if (val)
     {
       if (!sop)
@@ -6472,13 +6428,24 @@ static VEC(tree,heap) *stack;
 static tree
 simplify_stmt_for_jump_threading (tree stmt, tree within_stmt)
 {
+  tree conditional;
   /* We only use VRP information to simplify conditionals.  This is
      overly conservative, but it's unclear if doing more would be
      worth the compile time cost.  */
   if (TREE_CODE (stmt) != COND_EXPR)
     return NULL;
 
-  return vrp_evaluate_conditional (COND_EXPR_COND (stmt), within_stmt);
+  conditional = COND_EXPR_COND (stmt);
+  if (TREE_CODE (conditional) == SSA_NAME)
+    return vrp_evaluate_conditional (EQ_EXPR,
+				     conditional,
+				     boolean_true_node,
+				     within_stmt);
+  else
+    return vrp_evaluate_conditional (TREE_CODE (conditional),
+				     TREE_OPERAND (conditional, 0),
+				     TREE_OPERAND (conditional, 1),
+				     within_stmt);
 }
 
 /* Blocks which have more than one predecessor and more than

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