public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Remove ASSERT_EXPR.
@ 2022-11-22 13:57 Aldy Hernandez
  2022-11-22 13:58 ` [PATCH] Remove follow_assert_exprs from overflow_comparison Aldy Hernandez
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Aldy Hernandez @ 2022-11-22 13:57 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC patches, Andrew MacLeod, Aldy Hernandez

This removes all uses of ASSERT_EXPR except the internal one in ipa-*.

OK pending tests?

gcc/ChangeLog:

	* doc/gimple.texi: Remove ASSERT_EXPR references.
	* fold-const.cc (tree_expr_nonzero_warnv_p): Same.
	(fold_binary_loc): Same.
	(tree_expr_nonnegative_warnv_p): Same.
	* gimple-array-bounds.cc (get_base_decl): Same.
	* gimple-pretty-print.cc (dump_unary_rhs): Same.
	* gimple.cc (get_gimple_rhs_num_ops): Same.
	* pointer-query.cc (handle_ssa_name): Same.
	* tree-cfg.cc (verify_gimple_assign_single): Same.
	* tree-pretty-print.cc (dump_generic_node): Same.
	* tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):Same.
	(interpret_rhs_expr): Same.
	* tree-ssa-operands.cc (operands_scanner::get_expr_operands): Same.
	* tree-ssa-propagate.cc
	(substitute_and_fold_dom_walker::before_dom_children): Same.
	* tree-ssa-threadedge.cc: Same.
	* tree-vrp.cc (overflow_comparison_p): Same.
	* tree.def (ASSERT_EXPR): Add note.
	* tree.h (ASSERT_EXPR_VAR): Remove.
	(ASSERT_EXPR_COND): Remove.
	* vr-values.cc (simplify_using_ranges::vrp_visit_cond_stmt):
	Remove comment.
---
 gcc/doc/gimple.texi          |  3 +--
 gcc/fold-const.cc            |  6 -----
 gcc/gimple-array-bounds.cc   |  9 +-------
 gcc/gimple-pretty-print.cc   |  1 -
 gcc/gimple.cc                |  1 -
 gcc/pointer-query.cc         |  6 -----
 gcc/tree-cfg.cc              | 11 ---------
 gcc/tree-pretty-print.cc     |  8 -------
 gcc/tree-scalar-evolution.cc | 15 -------------
 gcc/tree-ssa-operands.cc     |  1 -
 gcc/tree-ssa-propagate.cc    |  5 +----
 gcc/tree-ssa-threadedge.cc   |  6 ++---
 gcc/tree-vrp.cc              |  7 +++---
 gcc/tree.def                 |  5 ++++-
 gcc/tree.h                   |  4 ----
 gcc/vr-values.cc             | 43 ------------------------------------
 16 files changed, 13 insertions(+), 118 deletions(-)

diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
index 7832fa6ff90..a4263922887 100644
--- a/gcc/doc/gimple.texi
+++ b/gcc/doc/gimple.texi
@@ -682,8 +682,7 @@ more than two slots on the RHS.  For instance, a @code{COND_EXPR}
 expression of the form @code{(a op b) ? x : y} could be flattened
 out on the operand vector using 4 slots, but it would also
 require additional processing to distinguish @code{c = a op b}
-from @code{c = a op b ? x : y}.  Something similar occurs with
-@code{ASSERT_EXPR}.   In time, these special case tree
+from @code{c = a op b ? x : y}.  In time, these special case tree
 expressions should be flattened into the operand vector.
 @end itemize
 
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index b89cac91cae..114258fa182 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -10751,7 +10751,6 @@ tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
     case COND_EXPR:
     case CONSTRUCTOR:
     case OBJ_TYPE_REF:
-    case ASSERT_EXPR:
     case ADDR_EXPR:
     case WITH_SIZE_EXPR:
     case SSA_NAME:
@@ -12618,10 +12617,6 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 				 : fold_convert_loc (loc, type, arg1);
       return tem;
 
-    case ASSERT_EXPR:
-      /* An ASSERT_EXPR should never be passed to fold_binary.  */
-      gcc_unreachable ();
-
     default:
       return NULL_TREE;
     } /* switch (code) */
@@ -15117,7 +15112,6 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
     case COND_EXPR:
     case CONSTRUCTOR:
     case OBJ_TYPE_REF:
-    case ASSERT_EXPR:
     case ADDR_EXPR:
     case WITH_SIZE_EXPR:
     case SSA_NAME:
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 1eafd3fd3e1..eae49ab3910 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -75,14 +75,7 @@ get_base_decl (tree ref)
       if (gimple_assign_single_p (def))
 	{
 	  base = gimple_assign_rhs1 (def);
-	  if (TREE_CODE (base) != ASSERT_EXPR)
-	    return base;
-
-	  base = TREE_OPERAND (base, 0);
-	  if (TREE_CODE (base) != SSA_NAME)
-	    return base;
-
-	  continue;
+	  return base;
 	}
 
       if (!gimple_nop_p (def))
diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 7ec079f15c6..af704257633 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -339,7 +339,6 @@ dump_unary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
   switch (rhs_code)
     {
     case VIEW_CONVERT_EXPR:
-    case ASSERT_EXPR:
       dump_generic_node (buffer, rhs, spc, flags, false);
       break;
 
diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index 6c23dd77609..dd054e16453 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -2408,7 +2408,6 @@ get_gimple_rhs_num_ops (enum tree_code code)
       || (SYM) == BIT_INSERT_EXPR) ? GIMPLE_TERNARY_RHS			    \
    : ((SYM) == CONSTRUCTOR						    \
       || (SYM) == OBJ_TYPE_REF						    \
-      || (SYM) == ASSERT_EXPR						    \
       || (SYM) == ADDR_EXPR						    \
       || (SYM) == WITH_SIZE_EXPR					    \
       || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS				    \
diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
index 0f0100233c1..95565fd6005 100644
--- a/gcc/pointer-query.cc
+++ b/gcc/pointer-query.cc
@@ -2144,12 +2144,6 @@ handle_ssa_name (tree ptr, bool addr, int ostype,
 
   tree rhs = gimple_assign_rhs1 (stmt);
 
-  if (code == ASSERT_EXPR)
-    {
-      rhs = TREE_OPERAND (rhs, 0);
-      return compute_objsize_r (rhs, stmt, addr, ostype, pref, snlim, qry);
-    }
-
   if (code == POINTER_PLUS_EXPR
       && TREE_CODE (TREE_TYPE (rhs)) == POINTER_TYPE)
     {
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index d982988048f..28175312afc 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -4795,17 +4795,6 @@ verify_gimple_assign_single (gassign *stmt)
 	}
       return res;
 
-    case ASSERT_EXPR:
-      /* FIXME.  */
-      rhs1 = fold (ASSERT_EXPR_COND (rhs1));
-      if (rhs1 == boolean_false_node)
-	{
-	  error ("%qs with an always-false condition", code_name);
-	  debug_generic_stmt (rhs1);
-	  return true;
-	}
-      break;
-
     case WITH_SIZE_EXPR:
       error ("%qs RHS in assignment statement",
 	     get_tree_code_name (rhs_code));
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index e7a8c9481a6..cb2a88cbdc5 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -3416,14 +3416,6 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
       pp_greater (pp);
       break;
 
-    case ASSERT_EXPR:
-      pp_string (pp, "ASSERT_EXPR <");
-      dump_generic_node (pp, ASSERT_EXPR_VAR (node), spc, flags, false);
-      pp_string (pp, ", ");
-      dump_generic_node (pp, ASSERT_EXPR_COND (node), spc, flags, false);
-      pp_greater (pp);
-      break;
-
     case SCEV_KNOWN:
       pp_string (pp, "scev_known");
       break;
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 7e2a3e98661..60060337804 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -1122,13 +1122,11 @@ scev_dfs::follow_ssa_edge_expr (gimple *at_stmt, tree expr,
      - a PLUS_EXPR,
      - a POINTER_PLUS_EXPR,
      - a MINUS_EXPR,
-     - an ASSERT_EXPR,
      - other cases are not yet handled.  */
 
   /* For SSA_NAME look at the definition statement, handling
      PHI nodes and otherwise expand appropriately for the expression
      handling below.  */
-tail_recurse:
   if (TREE_CODE (expr) == SSA_NAME)
     {
       gimple *def = SSA_NAME_DEF_STMT (expr);
@@ -1272,12 +1270,6 @@ tail_recurse:
       return follow_ssa_edge_binary (at_stmt, type, rhs0, code, rhs1,
 				     evolution_of_loop, limit);
 
-    case ASSERT_EXPR:
-      /* This assignment is of the form: "a_1 = ASSERT_EXPR <a_2, ...>"
-	 It must be handled as a copy assignment of the form a_1 = a_2.  */
-      expr = ASSERT_EXPR_VAR (rhs0);
-      goto tail_recurse;
-
     default:
       return t_false;
     }
@@ -1640,13 +1632,6 @@ interpret_rhs_expr (class loop *loop, gimple *at_stmt,
       if (code == SSA_NAME)
 	return chrec_convert (type, analyze_scalar_evolution (loop, rhs1),
 			      at_stmt);
-
-      if (code == ASSERT_EXPR)
-	{
-	  rhs1 = ASSERT_EXPR_VAR (rhs1);
-	  return chrec_convert (type, analyze_scalar_evolution (loop, rhs1),
-				at_stmt);
-	}
     }
 
   switch (code)
diff --git a/gcc/tree-ssa-operands.cc b/gcc/tree-ssa-operands.cc
index 9e85998b75e..4c90197860c 100644
--- a/gcc/tree-ssa-operands.cc
+++ b/gcc/tree-ssa-operands.cc
@@ -897,7 +897,6 @@ operands_scanner::get_expr_operands (tree *expr_p, int flags)
     case BIT_INSERT_EXPR:
     case COMPOUND_EXPR:
     case OBJ_TYPE_REF:
-    case ASSERT_EXPR:
     do_binary:
       {
 	get_expr_operands (&TREE_OPERAND (expr, 0), flags);
diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc
index 9dc4bfd85bf..6660d4f7cf1 100644
--- a/gcc/tree-ssa-propagate.cc
+++ b/gcc/tree-ssa-propagate.cc
@@ -818,10 +818,7 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
 	      && sprime != lhs
 	      && may_propagate_copy (lhs, sprime)
 	      && !stmt_could_throw_p (cfun, stmt)
-	      && !gimple_has_side_effects (stmt)
-	      /* We have to leave ASSERT_EXPRs around for jump-threading.  */
-	      && (!is_gimple_assign (stmt)
-		  || gimple_assign_rhs_code (stmt) != ASSERT_EXPR))
+	      && !gimple_has_side_effects (stmt))
 	    {
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		{
diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc
index 905a98c8c68..cc7020ddbb3 100644
--- a/gcc/tree-ssa-threadedge.cc
+++ b/gcc/tree-ssa-threadedge.cc
@@ -497,9 +497,9 @@ jump_threader::simplify_control_stmt_condition_1
     }
 
   /* If the condition has the form (A & B) CMP 0 or (A | B) CMP 0 then
-     recurse into the LHS to see if there is a dominating ASSERT_EXPR
-     of A or of B that makes this condition always true or always false
-     along the edge E.  */
+     recurse into the LHS to see if there is a simplification that
+     makes this condition always true or always false along the edge
+     E.  */
   if ((cond_code == EQ_EXPR || cond_code == NE_EXPR)
       && TREE_CODE (op0) == SSA_NAME
       && integer_zerop (op1))
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index df2f1eae203..d29941d0f2d 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -782,10 +782,9 @@ overflow_comparison_p (tree_code code, tree name, tree val,
    <bb 6>:
    __builtin_unreachable ();
    <bb 7>:
-   x_5 = ASSERT_EXPR <x_3, ...>;
-   If x_3 has no other immediate uses (checked by caller),
-   var is the x_3 var from ASSERT_EXPR, we can clear low 5 bits
-   from the non-zero bitmask.  */
+
+   If x_3 has no other immediate uses (checked by caller), var is the
+   x_3 var, we can clear low 5 bits from the non-zero bitmask.  */
 
 void
 maybe_set_nonzero_bits (edge e, tree var)
diff --git a/gcc/tree.def b/gcc/tree.def
index 62650b6934b..69783bd44fc 100644
--- a/gcc/tree.def
+++ b/gcc/tree.def
@@ -1025,7 +1025,10 @@ DEFTREECODE (POLYNOMIAL_CHREC, "polynomial_chrec", tcc_expression, 2)
    Use the interface in tree-iterator.h to access this node.  */
 DEFTREECODE (STATEMENT_LIST, "statement_list", tcc_exceptional, 0)
 
-/* Predicate assertion.  Artificial expression generated by the optimizers
+/* NOTE: This code is deprecated and should only be used internally by ipa* as
+   temporary construct.
+
+   Predicate assertion.  Artificial expression generated by the optimizers
    to keep track of predicate values.  This expression may only appear on
    the RHS of assignments.
 
diff --git a/gcc/tree.h b/gcc/tree.h
index a863d2e50e5..4a19de1c94d 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1406,10 +1406,6 @@ class auto_suppress_location_wrappers
 #define OBJ_TYPE_REF_OBJECT(NODE) TREE_OPERAND (OBJ_TYPE_REF_CHECK (NODE), 1)
 #define OBJ_TYPE_REF_TOKEN(NODE)  TREE_OPERAND (OBJ_TYPE_REF_CHECK (NODE), 2)
 
-/* ASSERT_EXPR accessors.  */
-#define ASSERT_EXPR_VAR(NODE)	TREE_OPERAND (ASSERT_EXPR_CHECK (NODE), 0)
-#define ASSERT_EXPR_COND(NODE)	TREE_OPERAND (ASSERT_EXPR_CHECK (NODE), 1)
-
 /* CALL_EXPR accessors.  */
 #define CALL_EXPR_FN(NODE) TREE_OPERAND (CALL_EXPR_CHECK (NODE), 1)
 #define CALL_EXPR_STATIC_CHAIN(NODE) TREE_OPERAND (CALL_EXPR_CHECK (NODE), 2)
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 798bfdc904a..0347c29b216 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -944,49 +944,6 @@ simplify_using_ranges::vrp_visit_cond_stmt (gcond *stmt, edge *taken_edge_p)
       fprintf (dump_file, "\n");
     }
 
-  /* Compute the value of the predicate COND by checking the known
-     ranges of each of its operands.
-
-     Note that we cannot evaluate all the equivalent ranges here
-     because those ranges may not yet be final and with the current
-     propagation strategy, we cannot determine when the value ranges
-     of the names in the equivalence set have changed.
-
-     For instance, given the following code fragment
-
-        i_5 = PHI <8, i_13>
-	...
-     	i_14 = ASSERT_EXPR <i_5, i_5 != 0>
-	if (i_14 == 1)
-	  ...
-
-     Assume that on the first visit to i_14, i_5 has the temporary
-     range [8, 8] because the second argument to the PHI function is
-     not yet executable.  We derive the range ~[0, 0] for i_14 and the
-     equivalence set { i_5 }.  So, when we visit 'if (i_14 == 1)' for
-     the first time, since i_14 is equivalent to the range [8, 8], we
-     determine that the predicate is always false.
-
-     On the next round of propagation, i_13 is determined to be
-     VARYING, which causes i_5 to drop down to VARYING.  So, another
-     visit to i_14 is scheduled.  In this second visit, we compute the
-     exact same range and equivalence set for i_14, namely ~[0, 0] and
-     { i_5 }.  But we did not have the previous range for i_5
-     registered, so vrp_visit_assignment thinks that the range for
-     i_14 has not changed.  Therefore, the predicate 'if (i_14 == 1)'
-     is not visited again, which stops propagation from visiting
-     statements in the THEN clause of that if().
-
-     To properly fix this we would need to keep the previous range
-     value for the names in the equivalence set.  This way we would've
-     discovered that from one visit to the other i_5 changed from
-     range [8, 8] to VR_VARYING.
-
-     However, fixing this apparent limitation may not be worth the
-     additional checking.  Testing on several code bases (GCC, DLV,
-     MICO, TRAMP3D and SPEC2000) showed that doing this results in
-     4 more predicates folded in SPEC.  */
-
   bool sop;
   val = vrp_evaluate_conditional_warnv_with_ops (stmt,
 						 gimple_cond_code (stmt),
-- 
2.38.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Remove follow_assert_exprs from overflow_comparison.
  2022-11-22 13:57 [PATCH] Remove ASSERT_EXPR Aldy Hernandez
@ 2022-11-22 13:58 ` Aldy Hernandez
  2022-11-23 20:28   ` Richard Biener
  2022-11-22 13:58 ` [PATCH] Remove use_equiv_p in vr-values.cc Aldy Hernandez
  2022-11-23 20:27 ` [PATCH] Remove ASSERT_EXPR Richard Biener
  2 siblings, 1 reply; 6+ messages in thread
From: Aldy Hernandez @ 2022-11-22 13:58 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC patches, Andrew MacLeod, Aldy Hernandez

OK pending tests?

gcc/ChangeLog:

	* tree-vrp.cc (overflow_comparison_p_1): Remove follow_assert_exprs.
	(overflow_comparison_p): Remove use_equiv_p.
	* tree-vrp.h (overflow_comparison_p): Same.
	* vr-values.cc (vrp_evaluate_conditional_warnv_with_ops): Remove
	use_equiv_p argument to overflow_comparison_p.
---
 gcc/tree-vrp.cc  | 40 ++++------------------------------------
 gcc/tree-vrp.h   |  2 +-
 gcc/vr-values.cc |  2 +-
 3 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index d29941d0f2d..3846dc1d849 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -679,7 +679,7 @@ range_fold_unary_expr (value_range *vr,
 
 static bool
 overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
-			 bool follow_assert_exprs, bool reversed, tree *new_cst)
+			 bool reversed, tree *new_cst)
 {
   /* See if this is a relational operation between two SSA_NAMES with
      unsigned, overflow wrapping values.  If so, check it more deeply.  */
@@ -693,19 +693,6 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
     {
       gimple *op1_def = SSA_NAME_DEF_STMT (op1);
 
-      /* If requested, follow any ASSERT_EXPRs backwards for OP1.  */
-      if (follow_assert_exprs)
-	{
-	  while (gimple_assign_single_p (op1_def)
-		 && TREE_CODE (gimple_assign_rhs1 (op1_def)) == ASSERT_EXPR)
-	    {
-	      op1 = TREE_OPERAND (gimple_assign_rhs1 (op1_def), 0);
-	      if (TREE_CODE (op1) != SSA_NAME)
-		break;
-	      op1_def = SSA_NAME_DEF_STMT (op1);
-	    }
-	}
-
       /* Now look at the defining statement of OP1 to see if it adds
 	 or subtracts a nonzero constant from another operand.  */
       if (op1_def
@@ -716,24 +703,6 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
 	{
 	  tree target = gimple_assign_rhs1 (op1_def);
 
-	  /* If requested, follow ASSERT_EXPRs backwards for op0 looking
-	     for one where TARGET appears on the RHS.  */
-	  if (follow_assert_exprs)
-	    {
-	      /* Now see if that "other operand" is op0, following the chain
-		 of ASSERT_EXPRs if necessary.  */
-	      gimple *op0_def = SSA_NAME_DEF_STMT (op0);
-	      while (op0 != target
-		     && gimple_assign_single_p (op0_def)
-		     && TREE_CODE (gimple_assign_rhs1 (op0_def)) == ASSERT_EXPR)
-		{
-		  op0 = TREE_OPERAND (gimple_assign_rhs1 (op0_def), 0);
-		  if (TREE_CODE (op0) != SSA_NAME)
-		    break;
-		  op0_def = SSA_NAME_DEF_STMT (op0);
-		}
-	    }
-
 	  /* If we did not find our target SSA_NAME, then this is not
 	     an overflow test.  */
 	  if (op0 != target)
@@ -764,13 +733,12 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
    the alternate range representation is often useful within VRP.  */
 
 bool
-overflow_comparison_p (tree_code code, tree name, tree val,
-		       bool use_equiv_p, tree *new_cst)
+overflow_comparison_p (tree_code code, tree name, tree val, tree *new_cst)
 {
-  if (overflow_comparison_p_1 (code, name, val, use_equiv_p, false, new_cst))
+  if (overflow_comparison_p_1 (code, name, val, false, new_cst))
     return true;
   return overflow_comparison_p_1 (swap_tree_comparison (code), val, name,
-				  use_equiv_p, true, new_cst);
+				  true, new_cst);
 }
 
 /* Handle
diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
index 07630b5b1ca..127909604f0 100644
--- a/gcc/tree-vrp.h
+++ b/gcc/tree-vrp.h
@@ -39,7 +39,7 @@ extern enum value_range_kind intersect_range_with_nonzero_bits
 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
 extern tree find_case_label_range (gswitch *, const irange *vr);
 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
-extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
+extern bool overflow_comparison_p (tree_code, tree, tree, tree *);
 extern void maybe_set_nonzero_bits (edge, tree);
 
 #endif /* GCC_TREE_VRP_H */
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 0347c29b216..b0dd30260ae 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -837,7 +837,7 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
      occurs when the chosen argument is zero and does not occur if the
      chosen argument is not zero.  */
   tree x;
-  if (overflow_comparison_p (code, op0, op1, use_equiv_p, &x))
+  if (overflow_comparison_p (code, op0, op1, &x))
     {
       wide_int max = wi::max_value (TYPE_PRECISION (TREE_TYPE (op0)), UNSIGNED);
       /* B = A - 1; if (A < B) -> B = A - 1; if (A == 0)
-- 
2.38.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Remove use_equiv_p in vr-values.cc
  2022-11-22 13:57 [PATCH] Remove ASSERT_EXPR Aldy Hernandez
  2022-11-22 13:58 ` [PATCH] Remove follow_assert_exprs from overflow_comparison Aldy Hernandez
@ 2022-11-22 13:58 ` Aldy Hernandez
  2022-11-23 20:29   ` Richard Biener
  2022-11-23 20:27 ` [PATCH] Remove ASSERT_EXPR Richard Biener
  2 siblings, 1 reply; 6+ messages in thread
From: Aldy Hernandez @ 2022-11-22 13:58 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC patches, Andrew MacLeod, Aldy Hernandez

With no equivalences, the use_equiv_p argument in various methods in
simplify_using_ranges is always false.  This means we can remove all
calls to compare_names, along with the function.

OK pending tests?

gcc/ChangeLog:

	* vr-values.cc (simplify_using_ranges::compare_names): Remove.
	(vrp_evaluate_conditional_warnv_with_ops): Remove call to
	compare_names.
	(simplify_using_ranges::vrp_visit_cond_stmt): Remove use_equiv_p
	argument to vrp_evaluate_conditional_warnv_with_ops.
	* vr-values.h (class simplify_using_ranges): Remove
	compare_names.
	Remove use_equiv_p to vrp_evaluate_conditional_warnv_with_ops.
---
 gcc/vr-values.cc | 127 +----------------------------------------------
 gcc/vr-values.h  |   4 +-
 2 files changed, 3 insertions(+), 128 deletions(-)

diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index b0dd30260ae..1dbd9e47085 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -667,124 +667,6 @@ simplify_using_ranges::compare_name_with_value
   return retval;
 }
 
-/* Given a comparison code COMP and names N1 and N2, compare all the
-   ranges equivalent to N1 against all the ranges equivalent to N2
-   to determine the value of N1 COMP N2.  Return the same value
-   returned by compare_ranges.  Set *STRICT_OVERFLOW_P to indicate
-   whether we relied on undefined signed overflow in the comparison.  */
-
-
-tree
-simplify_using_ranges::compare_names (enum tree_code comp, tree n1, tree n2,
-				      bool *strict_overflow_p, gimple *s)
-{
-  /* ?? These bitmaps are NULL as there are no longer any equivalences
-     available in the value_range*.  */
-  bitmap e1 = NULL;
-  bitmap e2 = NULL;
-
-  /* Use the fake bitmaps if e1 or e2 are not available.  */
-  static bitmap s_e1 = NULL, s_e2 = NULL;
-  static bitmap_obstack *s_obstack = NULL;
-  if (s_obstack == NULL)
-    {
-      s_obstack = XNEW (bitmap_obstack);
-      bitmap_obstack_initialize (s_obstack);
-      s_e1 = BITMAP_ALLOC (s_obstack);
-      s_e2 = BITMAP_ALLOC (s_obstack);
-    }
-  if (e1 == NULL)
-    e1 = s_e1;
-  if (e2 == NULL)
-    e2 = s_e2;
-
-  /* Add N1 and N2 to their own set of equivalences to avoid
-     duplicating the body of the loop just to check N1 and N2
-     ranges.  */
-  bitmap_set_bit (e1, SSA_NAME_VERSION (n1));
-  bitmap_set_bit (e2, SSA_NAME_VERSION (n2));
-
-  /* If the equivalence sets have a common intersection, then the two
-     names can be compared without checking their ranges.  */
-  if (bitmap_intersect_p (e1, e2))
-    {
-      bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
-      bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
-
-      return (comp == EQ_EXPR || comp == GE_EXPR || comp == LE_EXPR)
-	     ? boolean_true_node
-	     : boolean_false_node;
-    }
-
-  /* Start at -1.  Set it to 0 if we do a comparison without relying
-     on overflow, or 1 if all comparisons rely on overflow.  */
-  int used_strict_overflow = -1;
-
-  /* Otherwise, compare all the equivalent ranges.  First, add N1 and
-     N2 to their own set of equivalences to avoid duplicating the body
-     of the loop just to check N1 and N2 ranges.  */
-  bitmap_iterator bi1;
-  unsigned i1;
-  EXECUTE_IF_SET_IN_BITMAP (e1, 0, i1, bi1)
-    {
-      if (!ssa_name (i1))
-	continue;
-
-      value_range tem_vr1;
-      const value_range *vr1 = get_vr_for_comparison (i1, &tem_vr1, s);
-
-      tree t = NULL_TREE, retval = NULL_TREE;
-      bitmap_iterator bi2;
-      unsigned i2;
-      EXECUTE_IF_SET_IN_BITMAP (e2, 0, i2, bi2)
-	{
-	  if (!ssa_name (i2))
-	    continue;
-
-	  bool sop = false;
-
-	  value_range tem_vr2;
-	  const value_range *vr2 = get_vr_for_comparison (i2, &tem_vr2, s);
-
-	  t = compare_ranges (comp, vr1, vr2, &sop);
-	  if (t)
-	    {
-	      /* If we get different answers from different members
-		 of the equivalence set this check must be in a dead
-		 code region.  Folding it to a trap representation
-		 would be correct here.  For now just return don't-know.  */
-	      if (retval != NULL && t != retval)
-		{
-		  bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
-		  bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
-		  return NULL_TREE;
-		}
-	      retval = t;
-
-	      if (!sop)
-		used_strict_overflow = 0;
-	      else if (used_strict_overflow < 0)
-		used_strict_overflow = 1;
-	    }
-	}
-
-      if (retval)
-	{
-	  bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
-	  bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
-	  if (used_strict_overflow > 0)
-	    *strict_overflow_p = true;
-	  return retval;
-	}
-    }
-
-  /* None of the equivalent ranges are useful in computing this
-     comparison.  */
-  bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
-  bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
-  return NULL_TREE;
-}
-
 /* Helper function for vrp_evaluate_conditional_warnv & other
    optimizers.  */
 
@@ -815,7 +697,6 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
 						(gimple *stmt,
 						 enum tree_code code,
 						 tree op0, tree op1,
-						 bool use_equiv_p,
 						 bool *strict_overflow_p,
 						 bool *only_ranges)
 {
@@ -899,11 +780,7 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
     return ret;
   if (only_ranges)
     *only_ranges = false;
-  /* Do not use compare_names during propagation, it's quadratic.  */
-  if (TREE_CODE (op0) == SSA_NAME && TREE_CODE (op1) == SSA_NAME
-      && use_equiv_p)
-    return compare_names (code, op0, op1, strict_overflow_p, stmt);
-  else if (TREE_CODE (op0) == SSA_NAME)
+  if (TREE_CODE (op0) == SSA_NAME)
     return compare_name_with_value (code, op0, op1, strict_overflow_p, stmt);
   else if (TREE_CODE (op1) == SSA_NAME)
     return compare_name_with_value (swap_tree_comparison (code), op1, op0,
@@ -949,7 +826,7 @@ simplify_using_ranges::vrp_visit_cond_stmt (gcond *stmt, edge *taken_edge_p)
 						 gimple_cond_code (stmt),
 						 gimple_cond_lhs (stmt),
 						 gimple_cond_rhs (stmt),
-						 false, &sop, NULL);
+						 &sop, NULL);
   if (val)
     *taken_edge_p = find_taken_edge (gimple_bb (stmt), val);
 
diff --git a/gcc/vr-values.h b/gcc/vr-values.h
index 9804aaf83d1..6ad9fb2b81d 100644
--- a/gcc/vr-values.h
+++ b/gcc/vr-values.h
@@ -37,8 +37,7 @@ public:
 private:
   void vrp_visit_cond_stmt (gcond *, edge *);
   tree vrp_evaluate_conditional_warnv_with_ops (gimple *stmt, enum tree_code,
-						tree, tree, bool,
-						bool *, bool *);
+						tree, tree, bool *, bool *);
   bool simplify_casted_cond (gcond *);
   bool simplify_truth_ops_using_ranges (gimple_stmt_iterator *, gimple *);
   bool simplify_div_or_mod_using_ranges (gimple_stmt_iterator *, gimple *);
@@ -54,7 +53,6 @@ private:
   bool two_valued_val_range_p (tree, tree *, tree *, gimple *);
   bool op_with_boolean_value_range_p (tree, gimple *);
   tree compare_name_with_value (enum tree_code, tree, tree, bool *, gimple *);
-  tree compare_names (enum tree_code, tree, tree, bool *, gimple *s);
   const value_range *get_vr_for_comparison (int, value_range *, gimple *s);
   tree vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code,
 							     tree, tree,
-- 
2.38.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove ASSERT_EXPR.
  2022-11-22 13:57 [PATCH] Remove ASSERT_EXPR Aldy Hernandez
  2022-11-22 13:58 ` [PATCH] Remove follow_assert_exprs from overflow_comparison Aldy Hernandez
  2022-11-22 13:58 ` [PATCH] Remove use_equiv_p in vr-values.cc Aldy Hernandez
@ 2022-11-23 20:27 ` Richard Biener
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2022-11-23 20:27 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches, Andrew MacLeod

On Tue, Nov 22, 2022 at 2:58 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> This removes all uses of ASSERT_EXPR except the internal one in ipa-*.
>
> OK pending tests?

OK.

> gcc/ChangeLog:
>
>         * doc/gimple.texi: Remove ASSERT_EXPR references.
>         * fold-const.cc (tree_expr_nonzero_warnv_p): Same.
>         (fold_binary_loc): Same.
>         (tree_expr_nonnegative_warnv_p): Same.
>         * gimple-array-bounds.cc (get_base_decl): Same.
>         * gimple-pretty-print.cc (dump_unary_rhs): Same.
>         * gimple.cc (get_gimple_rhs_num_ops): Same.
>         * pointer-query.cc (handle_ssa_name): Same.
>         * tree-cfg.cc (verify_gimple_assign_single): Same.
>         * tree-pretty-print.cc (dump_generic_node): Same.
>         * tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):Same.
>         (interpret_rhs_expr): Same.
>         * tree-ssa-operands.cc (operands_scanner::get_expr_operands): Same.
>         * tree-ssa-propagate.cc
>         (substitute_and_fold_dom_walker::before_dom_children): Same.
>         * tree-ssa-threadedge.cc: Same.
>         * tree-vrp.cc (overflow_comparison_p): Same.
>         * tree.def (ASSERT_EXPR): Add note.
>         * tree.h (ASSERT_EXPR_VAR): Remove.
>         (ASSERT_EXPR_COND): Remove.
>         * vr-values.cc (simplify_using_ranges::vrp_visit_cond_stmt):
>         Remove comment.
> ---
>  gcc/doc/gimple.texi          |  3 +--
>  gcc/fold-const.cc            |  6 -----
>  gcc/gimple-array-bounds.cc   |  9 +-------
>  gcc/gimple-pretty-print.cc   |  1 -
>  gcc/gimple.cc                |  1 -
>  gcc/pointer-query.cc         |  6 -----
>  gcc/tree-cfg.cc              | 11 ---------
>  gcc/tree-pretty-print.cc     |  8 -------
>  gcc/tree-scalar-evolution.cc | 15 -------------
>  gcc/tree-ssa-operands.cc     |  1 -
>  gcc/tree-ssa-propagate.cc    |  5 +----
>  gcc/tree-ssa-threadedge.cc   |  6 ++---
>  gcc/tree-vrp.cc              |  7 +++---
>  gcc/tree.def                 |  5 ++++-
>  gcc/tree.h                   |  4 ----
>  gcc/vr-values.cc             | 43 ------------------------------------
>  16 files changed, 13 insertions(+), 118 deletions(-)
>
> diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
> index 7832fa6ff90..a4263922887 100644
> --- a/gcc/doc/gimple.texi
> +++ b/gcc/doc/gimple.texi
> @@ -682,8 +682,7 @@ more than two slots on the RHS.  For instance, a @code{COND_EXPR}
>  expression of the form @code{(a op b) ? x : y} could be flattened
>  out on the operand vector using 4 slots, but it would also
>  require additional processing to distinguish @code{c = a op b}
> -from @code{c = a op b ? x : y}.  Something similar occurs with
> -@code{ASSERT_EXPR}.   In time, these special case tree
> +from @code{c = a op b ? x : y}.  In time, these special case tree
>  expressions should be flattened into the operand vector.
>  @end itemize
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index b89cac91cae..114258fa182 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -10751,7 +10751,6 @@ tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
>      case COND_EXPR:
>      case CONSTRUCTOR:
>      case OBJ_TYPE_REF:
> -    case ASSERT_EXPR:
>      case ADDR_EXPR:
>      case WITH_SIZE_EXPR:
>      case SSA_NAME:
> @@ -12618,10 +12617,6 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
>                                  : fold_convert_loc (loc, type, arg1);
>        return tem;
>
> -    case ASSERT_EXPR:
> -      /* An ASSERT_EXPR should never be passed to fold_binary.  */
> -      gcc_unreachable ();
> -
>      default:
>        return NULL_TREE;
>      } /* switch (code) */
> @@ -15117,7 +15112,6 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
>      case COND_EXPR:
>      case CONSTRUCTOR:
>      case OBJ_TYPE_REF:
> -    case ASSERT_EXPR:
>      case ADDR_EXPR:
>      case WITH_SIZE_EXPR:
>      case SSA_NAME:
> diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
> index 1eafd3fd3e1..eae49ab3910 100644
> --- a/gcc/gimple-array-bounds.cc
> +++ b/gcc/gimple-array-bounds.cc
> @@ -75,14 +75,7 @@ get_base_decl (tree ref)
>        if (gimple_assign_single_p (def))
>         {
>           base = gimple_assign_rhs1 (def);
> -         if (TREE_CODE (base) != ASSERT_EXPR)
> -           return base;
> -
> -         base = TREE_OPERAND (base, 0);
> -         if (TREE_CODE (base) != SSA_NAME)
> -           return base;
> -
> -         continue;
> +         return base;
>         }
>
>        if (!gimple_nop_p (def))
> diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
> index 7ec079f15c6..af704257633 100644
> --- a/gcc/gimple-pretty-print.cc
> +++ b/gcc/gimple-pretty-print.cc
> @@ -339,7 +339,6 @@ dump_unary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
>    switch (rhs_code)
>      {
>      case VIEW_CONVERT_EXPR:
> -    case ASSERT_EXPR:
>        dump_generic_node (buffer, rhs, spc, flags, false);
>        break;
>
> diff --git a/gcc/gimple.cc b/gcc/gimple.cc
> index 6c23dd77609..dd054e16453 100644
> --- a/gcc/gimple.cc
> +++ b/gcc/gimple.cc
> @@ -2408,7 +2408,6 @@ get_gimple_rhs_num_ops (enum tree_code code)
>        || (SYM) == BIT_INSERT_EXPR) ? GIMPLE_TERNARY_RHS                            \
>     : ((SYM) == CONSTRUCTOR                                                 \
>        || (SYM) == OBJ_TYPE_REF                                             \
> -      || (SYM) == ASSERT_EXPR                                              \
>        || (SYM) == ADDR_EXPR                                                \
>        || (SYM) == WITH_SIZE_EXPR                                           \
>        || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS                                    \
> diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
> index 0f0100233c1..95565fd6005 100644
> --- a/gcc/pointer-query.cc
> +++ b/gcc/pointer-query.cc
> @@ -2144,12 +2144,6 @@ handle_ssa_name (tree ptr, bool addr, int ostype,
>
>    tree rhs = gimple_assign_rhs1 (stmt);
>
> -  if (code == ASSERT_EXPR)
> -    {
> -      rhs = TREE_OPERAND (rhs, 0);
> -      return compute_objsize_r (rhs, stmt, addr, ostype, pref, snlim, qry);
> -    }
> -
>    if (code == POINTER_PLUS_EXPR
>        && TREE_CODE (TREE_TYPE (rhs)) == POINTER_TYPE)
>      {
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
> index d982988048f..28175312afc 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -4795,17 +4795,6 @@ verify_gimple_assign_single (gassign *stmt)
>         }
>        return res;
>
> -    case ASSERT_EXPR:
> -      /* FIXME.  */
> -      rhs1 = fold (ASSERT_EXPR_COND (rhs1));
> -      if (rhs1 == boolean_false_node)
> -       {
> -         error ("%qs with an always-false condition", code_name);
> -         debug_generic_stmt (rhs1);
> -         return true;
> -       }
> -      break;
> -
>      case WITH_SIZE_EXPR:
>        error ("%qs RHS in assignment statement",
>              get_tree_code_name (rhs_code));
> diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
> index e7a8c9481a6..cb2a88cbdc5 100644
> --- a/gcc/tree-pretty-print.cc
> +++ b/gcc/tree-pretty-print.cc
> @@ -3416,14 +3416,6 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
>        pp_greater (pp);
>        break;
>
> -    case ASSERT_EXPR:
> -      pp_string (pp, "ASSERT_EXPR <");
> -      dump_generic_node (pp, ASSERT_EXPR_VAR (node), spc, flags, false);
> -      pp_string (pp, ", ");
> -      dump_generic_node (pp, ASSERT_EXPR_COND (node), spc, flags, false);
> -      pp_greater (pp);
> -      break;
> -
>      case SCEV_KNOWN:
>        pp_string (pp, "scev_known");
>        break;
> diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
> index 7e2a3e98661..60060337804 100644
> --- a/gcc/tree-scalar-evolution.cc
> +++ b/gcc/tree-scalar-evolution.cc
> @@ -1122,13 +1122,11 @@ scev_dfs::follow_ssa_edge_expr (gimple *at_stmt, tree expr,
>       - a PLUS_EXPR,
>       - a POINTER_PLUS_EXPR,
>       - a MINUS_EXPR,
> -     - an ASSERT_EXPR,
>       - other cases are not yet handled.  */
>
>    /* For SSA_NAME look at the definition statement, handling
>       PHI nodes and otherwise expand appropriately for the expression
>       handling below.  */
> -tail_recurse:
>    if (TREE_CODE (expr) == SSA_NAME)
>      {
>        gimple *def = SSA_NAME_DEF_STMT (expr);
> @@ -1272,12 +1270,6 @@ tail_recurse:
>        return follow_ssa_edge_binary (at_stmt, type, rhs0, code, rhs1,
>                                      evolution_of_loop, limit);
>
> -    case ASSERT_EXPR:
> -      /* This assignment is of the form: "a_1 = ASSERT_EXPR <a_2, ...>"
> -        It must be handled as a copy assignment of the form a_1 = a_2.  */
> -      expr = ASSERT_EXPR_VAR (rhs0);
> -      goto tail_recurse;
> -
>      default:
>        return t_false;
>      }
> @@ -1640,13 +1632,6 @@ interpret_rhs_expr (class loop *loop, gimple *at_stmt,
>        if (code == SSA_NAME)
>         return chrec_convert (type, analyze_scalar_evolution (loop, rhs1),
>                               at_stmt);
> -
> -      if (code == ASSERT_EXPR)
> -       {
> -         rhs1 = ASSERT_EXPR_VAR (rhs1);
> -         return chrec_convert (type, analyze_scalar_evolution (loop, rhs1),
> -                               at_stmt);
> -       }
>      }
>
>    switch (code)
> diff --git a/gcc/tree-ssa-operands.cc b/gcc/tree-ssa-operands.cc
> index 9e85998b75e..4c90197860c 100644
> --- a/gcc/tree-ssa-operands.cc
> +++ b/gcc/tree-ssa-operands.cc
> @@ -897,7 +897,6 @@ operands_scanner::get_expr_operands (tree *expr_p, int flags)
>      case BIT_INSERT_EXPR:
>      case COMPOUND_EXPR:
>      case OBJ_TYPE_REF:
> -    case ASSERT_EXPR:
>      do_binary:
>        {
>         get_expr_operands (&TREE_OPERAND (expr, 0), flags);
> diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc
> index 9dc4bfd85bf..6660d4f7cf1 100644
> --- a/gcc/tree-ssa-propagate.cc
> +++ b/gcc/tree-ssa-propagate.cc
> @@ -818,10 +818,7 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
>               && sprime != lhs
>               && may_propagate_copy (lhs, sprime)
>               && !stmt_could_throw_p (cfun, stmt)
> -             && !gimple_has_side_effects (stmt)
> -             /* We have to leave ASSERT_EXPRs around for jump-threading.  */
> -             && (!is_gimple_assign (stmt)
> -                 || gimple_assign_rhs_code (stmt) != ASSERT_EXPR))
> +             && !gimple_has_side_effects (stmt))
>             {
>               if (dump_file && (dump_flags & TDF_DETAILS))
>                 {
> diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc
> index 905a98c8c68..cc7020ddbb3 100644
> --- a/gcc/tree-ssa-threadedge.cc
> +++ b/gcc/tree-ssa-threadedge.cc
> @@ -497,9 +497,9 @@ jump_threader::simplify_control_stmt_condition_1
>      }
>
>    /* If the condition has the form (A & B) CMP 0 or (A | B) CMP 0 then
> -     recurse into the LHS to see if there is a dominating ASSERT_EXPR
> -     of A or of B that makes this condition always true or always false
> -     along the edge E.  */
> +     recurse into the LHS to see if there is a simplification that
> +     makes this condition always true or always false along the edge
> +     E.  */
>    if ((cond_code == EQ_EXPR || cond_code == NE_EXPR)
>        && TREE_CODE (op0) == SSA_NAME
>        && integer_zerop (op1))
> diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
> index df2f1eae203..d29941d0f2d 100644
> --- a/gcc/tree-vrp.cc
> +++ b/gcc/tree-vrp.cc
> @@ -782,10 +782,9 @@ overflow_comparison_p (tree_code code, tree name, tree val,
>     <bb 6>:
>     __builtin_unreachable ();
>     <bb 7>:
> -   x_5 = ASSERT_EXPR <x_3, ...>;
> -   If x_3 has no other immediate uses (checked by caller),
> -   var is the x_3 var from ASSERT_EXPR, we can clear low 5 bits
> -   from the non-zero bitmask.  */
> +
> +   If x_3 has no other immediate uses (checked by caller), var is the
> +   x_3 var, we can clear low 5 bits from the non-zero bitmask.  */
>
>  void
>  maybe_set_nonzero_bits (edge e, tree var)
> diff --git a/gcc/tree.def b/gcc/tree.def
> index 62650b6934b..69783bd44fc 100644
> --- a/gcc/tree.def
> +++ b/gcc/tree.def
> @@ -1025,7 +1025,10 @@ DEFTREECODE (POLYNOMIAL_CHREC, "polynomial_chrec", tcc_expression, 2)
>     Use the interface in tree-iterator.h to access this node.  */
>  DEFTREECODE (STATEMENT_LIST, "statement_list", tcc_exceptional, 0)
>
> -/* Predicate assertion.  Artificial expression generated by the optimizers
> +/* NOTE: This code is deprecated and should only be used internally by ipa* as
> +   temporary construct.
> +
> +   Predicate assertion.  Artificial expression generated by the optimizers
>     to keep track of predicate values.  This expression may only appear on
>     the RHS of assignments.
>
> diff --git a/gcc/tree.h b/gcc/tree.h
> index a863d2e50e5..4a19de1c94d 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -1406,10 +1406,6 @@ class auto_suppress_location_wrappers
>  #define OBJ_TYPE_REF_OBJECT(NODE) TREE_OPERAND (OBJ_TYPE_REF_CHECK (NODE), 1)
>  #define OBJ_TYPE_REF_TOKEN(NODE)  TREE_OPERAND (OBJ_TYPE_REF_CHECK (NODE), 2)
>
> -/* ASSERT_EXPR accessors.  */
> -#define ASSERT_EXPR_VAR(NODE)  TREE_OPERAND (ASSERT_EXPR_CHECK (NODE), 0)
> -#define ASSERT_EXPR_COND(NODE) TREE_OPERAND (ASSERT_EXPR_CHECK (NODE), 1)
> -
>  /* CALL_EXPR accessors.  */
>  #define CALL_EXPR_FN(NODE) TREE_OPERAND (CALL_EXPR_CHECK (NODE), 1)
>  #define CALL_EXPR_STATIC_CHAIN(NODE) TREE_OPERAND (CALL_EXPR_CHECK (NODE), 2)
> diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
> index 798bfdc904a..0347c29b216 100644
> --- a/gcc/vr-values.cc
> +++ b/gcc/vr-values.cc
> @@ -944,49 +944,6 @@ simplify_using_ranges::vrp_visit_cond_stmt (gcond *stmt, edge *taken_edge_p)
>        fprintf (dump_file, "\n");
>      }
>
> -  /* Compute the value of the predicate COND by checking the known
> -     ranges of each of its operands.
> -
> -     Note that we cannot evaluate all the equivalent ranges here
> -     because those ranges may not yet be final and with the current
> -     propagation strategy, we cannot determine when the value ranges
> -     of the names in the equivalence set have changed.
> -
> -     For instance, given the following code fragment
> -
> -        i_5 = PHI <8, i_13>
> -       ...
> -       i_14 = ASSERT_EXPR <i_5, i_5 != 0>
> -       if (i_14 == 1)
> -         ...
> -
> -     Assume that on the first visit to i_14, i_5 has the temporary
> -     range [8, 8] because the second argument to the PHI function is
> -     not yet executable.  We derive the range ~[0, 0] for i_14 and the
> -     equivalence set { i_5 }.  So, when we visit 'if (i_14 == 1)' for
> -     the first time, since i_14 is equivalent to the range [8, 8], we
> -     determine that the predicate is always false.
> -
> -     On the next round of propagation, i_13 is determined to be
> -     VARYING, which causes i_5 to drop down to VARYING.  So, another
> -     visit to i_14 is scheduled.  In this second visit, we compute the
> -     exact same range and equivalence set for i_14, namely ~[0, 0] and
> -     { i_5 }.  But we did not have the previous range for i_5
> -     registered, so vrp_visit_assignment thinks that the range for
> -     i_14 has not changed.  Therefore, the predicate 'if (i_14 == 1)'
> -     is not visited again, which stops propagation from visiting
> -     statements in the THEN clause of that if().
> -
> -     To properly fix this we would need to keep the previous range
> -     value for the names in the equivalence set.  This way we would've
> -     discovered that from one visit to the other i_5 changed from
> -     range [8, 8] to VR_VARYING.
> -
> -     However, fixing this apparent limitation may not be worth the
> -     additional checking.  Testing on several code bases (GCC, DLV,
> -     MICO, TRAMP3D and SPEC2000) showed that doing this results in
> -     4 more predicates folded in SPEC.  */
> -
>    bool sop;
>    val = vrp_evaluate_conditional_warnv_with_ops (stmt,
>                                                  gimple_cond_code (stmt),
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove follow_assert_exprs from overflow_comparison.
  2022-11-22 13:58 ` [PATCH] Remove follow_assert_exprs from overflow_comparison Aldy Hernandez
@ 2022-11-23 20:28   ` Richard Biener
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2022-11-23 20:28 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches, Andrew MacLeod

On Tue, Nov 22, 2022 at 2:58 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> OK pending tests?

OK

> gcc/ChangeLog:
>
>         * tree-vrp.cc (overflow_comparison_p_1): Remove follow_assert_exprs.
>         (overflow_comparison_p): Remove use_equiv_p.
>         * tree-vrp.h (overflow_comparison_p): Same.
>         * vr-values.cc (vrp_evaluate_conditional_warnv_with_ops): Remove
>         use_equiv_p argument to overflow_comparison_p.
> ---
>  gcc/tree-vrp.cc  | 40 ++++------------------------------------
>  gcc/tree-vrp.h   |  2 +-
>  gcc/vr-values.cc |  2 +-
>  3 files changed, 6 insertions(+), 38 deletions(-)
>
> diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
> index d29941d0f2d..3846dc1d849 100644
> --- a/gcc/tree-vrp.cc
> +++ b/gcc/tree-vrp.cc
> @@ -679,7 +679,7 @@ range_fold_unary_expr (value_range *vr,
>
>  static bool
>  overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
> -                        bool follow_assert_exprs, bool reversed, tree *new_cst)
> +                        bool reversed, tree *new_cst)
>  {
>    /* See if this is a relational operation between two SSA_NAMES with
>       unsigned, overflow wrapping values.  If so, check it more deeply.  */
> @@ -693,19 +693,6 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
>      {
>        gimple *op1_def = SSA_NAME_DEF_STMT (op1);
>
> -      /* If requested, follow any ASSERT_EXPRs backwards for OP1.  */
> -      if (follow_assert_exprs)
> -       {
> -         while (gimple_assign_single_p (op1_def)
> -                && TREE_CODE (gimple_assign_rhs1 (op1_def)) == ASSERT_EXPR)
> -           {
> -             op1 = TREE_OPERAND (gimple_assign_rhs1 (op1_def), 0);
> -             if (TREE_CODE (op1) != SSA_NAME)
> -               break;
> -             op1_def = SSA_NAME_DEF_STMT (op1);
> -           }
> -       }
> -
>        /* Now look at the defining statement of OP1 to see if it adds
>          or subtracts a nonzero constant from another operand.  */
>        if (op1_def
> @@ -716,24 +703,6 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
>         {
>           tree target = gimple_assign_rhs1 (op1_def);
>
> -         /* If requested, follow ASSERT_EXPRs backwards for op0 looking
> -            for one where TARGET appears on the RHS.  */
> -         if (follow_assert_exprs)
> -           {
> -             /* Now see if that "other operand" is op0, following the chain
> -                of ASSERT_EXPRs if necessary.  */
> -             gimple *op0_def = SSA_NAME_DEF_STMT (op0);
> -             while (op0 != target
> -                    && gimple_assign_single_p (op0_def)
> -                    && TREE_CODE (gimple_assign_rhs1 (op0_def)) == ASSERT_EXPR)
> -               {
> -                 op0 = TREE_OPERAND (gimple_assign_rhs1 (op0_def), 0);
> -                 if (TREE_CODE (op0) != SSA_NAME)
> -                   break;
> -                 op0_def = SSA_NAME_DEF_STMT (op0);
> -               }
> -           }
> -
>           /* If we did not find our target SSA_NAME, then this is not
>              an overflow test.  */
>           if (op0 != target)
> @@ -764,13 +733,12 @@ overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
>     the alternate range representation is often useful within VRP.  */
>
>  bool
> -overflow_comparison_p (tree_code code, tree name, tree val,
> -                      bool use_equiv_p, tree *new_cst)
> +overflow_comparison_p (tree_code code, tree name, tree val, tree *new_cst)
>  {
> -  if (overflow_comparison_p_1 (code, name, val, use_equiv_p, false, new_cst))
> +  if (overflow_comparison_p_1 (code, name, val, false, new_cst))
>      return true;
>    return overflow_comparison_p_1 (swap_tree_comparison (code), val, name,
> -                                 use_equiv_p, true, new_cst);
> +                                 true, new_cst);
>  }
>
>  /* Handle
> diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
> index 07630b5b1ca..127909604f0 100644
> --- a/gcc/tree-vrp.h
> +++ b/gcc/tree-vrp.h
> @@ -39,7 +39,7 @@ extern enum value_range_kind intersect_range_with_nonzero_bits
>  extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
>  extern tree find_case_label_range (gswitch *, const irange *vr);
>  extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
> -extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
> +extern bool overflow_comparison_p (tree_code, tree, tree, tree *);
>  extern void maybe_set_nonzero_bits (edge, tree);
>
>  #endif /* GCC_TREE_VRP_H */
> diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
> index 0347c29b216..b0dd30260ae 100644
> --- a/gcc/vr-values.cc
> +++ b/gcc/vr-values.cc
> @@ -837,7 +837,7 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
>       occurs when the chosen argument is zero and does not occur if the
>       chosen argument is not zero.  */
>    tree x;
> -  if (overflow_comparison_p (code, op0, op1, use_equiv_p, &x))
> +  if (overflow_comparison_p (code, op0, op1, &x))
>      {
>        wide_int max = wi::max_value (TYPE_PRECISION (TREE_TYPE (op0)), UNSIGNED);
>        /* B = A - 1; if (A < B) -> B = A - 1; if (A == 0)
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove use_equiv_p in vr-values.cc
  2022-11-22 13:58 ` [PATCH] Remove use_equiv_p in vr-values.cc Aldy Hernandez
@ 2022-11-23 20:29   ` Richard Biener
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2022-11-23 20:29 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches, Andrew MacLeod

On Tue, Nov 22, 2022 at 2:58 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> With no equivalences, the use_equiv_p argument in various methods in
> simplify_using_ranges is always false.  This means we can remove all
> calls to compare_names, along with the function.
>
> OK pending tests?

OK

> gcc/ChangeLog:
>
>         * vr-values.cc (simplify_using_ranges::compare_names): Remove.
>         (vrp_evaluate_conditional_warnv_with_ops): Remove call to
>         compare_names.
>         (simplify_using_ranges::vrp_visit_cond_stmt): Remove use_equiv_p
>         argument to vrp_evaluate_conditional_warnv_with_ops.
>         * vr-values.h (class simplify_using_ranges): Remove
>         compare_names.
>         Remove use_equiv_p to vrp_evaluate_conditional_warnv_with_ops.
> ---
>  gcc/vr-values.cc | 127 +----------------------------------------------
>  gcc/vr-values.h  |   4 +-
>  2 files changed, 3 insertions(+), 128 deletions(-)
>
> diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
> index b0dd30260ae..1dbd9e47085 100644
> --- a/gcc/vr-values.cc
> +++ b/gcc/vr-values.cc
> @@ -667,124 +667,6 @@ simplify_using_ranges::compare_name_with_value
>    return retval;
>  }
>
> -/* Given a comparison code COMP and names N1 and N2, compare all the
> -   ranges equivalent to N1 against all the ranges equivalent to N2
> -   to determine the value of N1 COMP N2.  Return the same value
> -   returned by compare_ranges.  Set *STRICT_OVERFLOW_P to indicate
> -   whether we relied on undefined signed overflow in the comparison.  */
> -
> -
> -tree
> -simplify_using_ranges::compare_names (enum tree_code comp, tree n1, tree n2,
> -                                     bool *strict_overflow_p, gimple *s)
> -{
> -  /* ?? These bitmaps are NULL as there are no longer any equivalences
> -     available in the value_range*.  */
> -  bitmap e1 = NULL;
> -  bitmap e2 = NULL;
> -
> -  /* Use the fake bitmaps if e1 or e2 are not available.  */
> -  static bitmap s_e1 = NULL, s_e2 = NULL;
> -  static bitmap_obstack *s_obstack = NULL;
> -  if (s_obstack == NULL)
> -    {
> -      s_obstack = XNEW (bitmap_obstack);
> -      bitmap_obstack_initialize (s_obstack);
> -      s_e1 = BITMAP_ALLOC (s_obstack);
> -      s_e2 = BITMAP_ALLOC (s_obstack);
> -    }
> -  if (e1 == NULL)
> -    e1 = s_e1;
> -  if (e2 == NULL)
> -    e2 = s_e2;
> -
> -  /* Add N1 and N2 to their own set of equivalences to avoid
> -     duplicating the body of the loop just to check N1 and N2
> -     ranges.  */
> -  bitmap_set_bit (e1, SSA_NAME_VERSION (n1));
> -  bitmap_set_bit (e2, SSA_NAME_VERSION (n2));
> -
> -  /* If the equivalence sets have a common intersection, then the two
> -     names can be compared without checking their ranges.  */
> -  if (bitmap_intersect_p (e1, e2))
> -    {
> -      bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
> -      bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
> -
> -      return (comp == EQ_EXPR || comp == GE_EXPR || comp == LE_EXPR)
> -            ? boolean_true_node
> -            : boolean_false_node;
> -    }
> -
> -  /* Start at -1.  Set it to 0 if we do a comparison without relying
> -     on overflow, or 1 if all comparisons rely on overflow.  */
> -  int used_strict_overflow = -1;
> -
> -  /* Otherwise, compare all the equivalent ranges.  First, add N1 and
> -     N2 to their own set of equivalences to avoid duplicating the body
> -     of the loop just to check N1 and N2 ranges.  */
> -  bitmap_iterator bi1;
> -  unsigned i1;
> -  EXECUTE_IF_SET_IN_BITMAP (e1, 0, i1, bi1)
> -    {
> -      if (!ssa_name (i1))
> -       continue;
> -
> -      value_range tem_vr1;
> -      const value_range *vr1 = get_vr_for_comparison (i1, &tem_vr1, s);
> -
> -      tree t = NULL_TREE, retval = NULL_TREE;
> -      bitmap_iterator bi2;
> -      unsigned i2;
> -      EXECUTE_IF_SET_IN_BITMAP (e2, 0, i2, bi2)
> -       {
> -         if (!ssa_name (i2))
> -           continue;
> -
> -         bool sop = false;
> -
> -         value_range tem_vr2;
> -         const value_range *vr2 = get_vr_for_comparison (i2, &tem_vr2, s);
> -
> -         t = compare_ranges (comp, vr1, vr2, &sop);
> -         if (t)
> -           {
> -             /* If we get different answers from different members
> -                of the equivalence set this check must be in a dead
> -                code region.  Folding it to a trap representation
> -                would be correct here.  For now just return don't-know.  */
> -             if (retval != NULL && t != retval)
> -               {
> -                 bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
> -                 bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
> -                 return NULL_TREE;
> -               }
> -             retval = t;
> -
> -             if (!sop)
> -               used_strict_overflow = 0;
> -             else if (used_strict_overflow < 0)
> -               used_strict_overflow = 1;
> -           }
> -       }
> -
> -      if (retval)
> -       {
> -         bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
> -         bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
> -         if (used_strict_overflow > 0)
> -           *strict_overflow_p = true;
> -         return retval;
> -       }
> -    }
> -
> -  /* None of the equivalent ranges are useful in computing this
> -     comparison.  */
> -  bitmap_clear_bit (e1, SSA_NAME_VERSION (n1));
> -  bitmap_clear_bit (e2, SSA_NAME_VERSION (n2));
> -  return NULL_TREE;
> -}
> -
>  /* Helper function for vrp_evaluate_conditional_warnv & other
>     optimizers.  */
>
> @@ -815,7 +697,6 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
>                                                 (gimple *stmt,
>                                                  enum tree_code code,
>                                                  tree op0, tree op1,
> -                                                bool use_equiv_p,
>                                                  bool *strict_overflow_p,
>                                                  bool *only_ranges)
>  {
> @@ -899,11 +780,7 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
>      return ret;
>    if (only_ranges)
>      *only_ranges = false;
> -  /* Do not use compare_names during propagation, it's quadratic.  */
> -  if (TREE_CODE (op0) == SSA_NAME && TREE_CODE (op1) == SSA_NAME
> -      && use_equiv_p)
> -    return compare_names (code, op0, op1, strict_overflow_p, stmt);
> -  else if (TREE_CODE (op0) == SSA_NAME)
> +  if (TREE_CODE (op0) == SSA_NAME)
>      return compare_name_with_value (code, op0, op1, strict_overflow_p, stmt);
>    else if (TREE_CODE (op1) == SSA_NAME)
>      return compare_name_with_value (swap_tree_comparison (code), op1, op0,
> @@ -949,7 +826,7 @@ simplify_using_ranges::vrp_visit_cond_stmt (gcond *stmt, edge *taken_edge_p)
>                                                  gimple_cond_code (stmt),
>                                                  gimple_cond_lhs (stmt),
>                                                  gimple_cond_rhs (stmt),
> -                                                false, &sop, NULL);
> +                                                &sop, NULL);
>    if (val)
>      *taken_edge_p = find_taken_edge (gimple_bb (stmt), val);
>
> diff --git a/gcc/vr-values.h b/gcc/vr-values.h
> index 9804aaf83d1..6ad9fb2b81d 100644
> --- a/gcc/vr-values.h
> +++ b/gcc/vr-values.h
> @@ -37,8 +37,7 @@ public:
>  private:
>    void vrp_visit_cond_stmt (gcond *, edge *);
>    tree vrp_evaluate_conditional_warnv_with_ops (gimple *stmt, enum tree_code,
> -                                               tree, tree, bool,
> -                                               bool *, bool *);
> +                                               tree, tree, bool *, bool *);
>    bool simplify_casted_cond (gcond *);
>    bool simplify_truth_ops_using_ranges (gimple_stmt_iterator *, gimple *);
>    bool simplify_div_or_mod_using_ranges (gimple_stmt_iterator *, gimple *);
> @@ -54,7 +53,6 @@ private:
>    bool two_valued_val_range_p (tree, tree *, tree *, gimple *);
>    bool op_with_boolean_value_range_p (tree, gimple *);
>    tree compare_name_with_value (enum tree_code, tree, tree, bool *, gimple *);
> -  tree compare_names (enum tree_code, tree, tree, bool *, gimple *s);
>    const value_range *get_vr_for_comparison (int, value_range *, gimple *s);
>    tree vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code,
>                                                              tree, tree,
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-23 20:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 13:57 [PATCH] Remove ASSERT_EXPR Aldy Hernandez
2022-11-22 13:58 ` [PATCH] Remove follow_assert_exprs from overflow_comparison Aldy Hernandez
2022-11-23 20:28   ` Richard Biener
2022-11-22 13:58 ` [PATCH] Remove use_equiv_p in vr-values.cc Aldy Hernandez
2022-11-23 20:29   ` Richard Biener
2022-11-23 20:27 ` [PATCH] Remove ASSERT_EXPR Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).