diff mbox series

[1/3] Remove gimple_expr_type uses from value-range code

Message ID 8rssr9p2-9o4n-oqor-6o65-7no6r55pr9p@fhfr.qr
State New
Headers show
Series [1/3] Remove gimple_expr_type uses from value-range code | expand

Commit Message

Richard Biener July 16, 2021, 1:02 p.m. UTC
This removes the last uses from value-range code.

Bootstrap & regtest running on x86_64-unknown-linux-gnu, OK?

Thanks,
Richard.

2021-07-16  Richard Biener  <rguenther@suse.de>

	* tree-vrp.c (register_edge_assert_for_2): Use the
	type from the LHS.
	(vrp_folder::fold_predicate_in): Likewise.
	* vr-values.c (gimple_assign_nonzero_p): Likewise.
	(vr_values::extract_range_from_comparison): Likewise.
	(vr_values::extract_range_from_ubsan_builtin): Use the
	type of the first operand.
	(vr_values::extract_range_basic): Push down type
	computation, use the appropriate LHS.
	(vr_values::extract_range_from_assignment): Use the
	type of the LHS.
---
 gcc/tree-vrp.c  | 14 +++++++-------
 gcc/vr-values.c | 28 ++++++++++++++++------------
 2 files changed, 23 insertions(+), 19 deletions(-)

Comments

Andrew MacLeod July 16, 2021, 2 p.m. UTC | #1
On 7/16/21 9:02 AM, Richard Biener wrote:
> This removes the last uses from value-range code.
>
> Bootstrap & regtest running on x86_64-unknown-linux-gnu, OK?

absolutely.
diff mbox series

Patch

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 0565c9b5073..a9c31bcedb5 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -1484,13 +1484,13 @@  register_edge_assert_for_2 (tree name, edge e,
 	}
 
       /* Extract NAME2 from the (optional) sign-changing cast.  */
-      if (gimple_assign_cast_p (def_stmt))
+      if (gassign *ass = dyn_cast <gassign *> (def_stmt))
 	{
-	  if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))
-	      && ! TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))
-	      && (TYPE_PRECISION (gimple_expr_type (def_stmt))
-		  == TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))))
-	    name3 = gimple_assign_rhs1 (def_stmt);
+	  if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (ass))
+	      && ! TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (ass)))
+	      && (TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (ass)))
+		  == TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (ass)))))
+	    name3 = gimple_assign_rhs1 (ass);
 	}
 
       /* If name3 is used later, create an ASSERT_EXPR for it.  */
@@ -4119,7 +4119,7 @@  vrp_folder::fold_predicate_in (gimple_stmt_iterator *si)
   if (val)
     {
       if (assignment_p)
-        val = fold_convert (gimple_expr_type (stmt), val);
+	val = fold_convert (TREE_TYPE (gimple_assign_lhs (stmt)), val);
 
       if (dump_file)
 	{
diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index 190676de2c0..1b3ec38d288 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -338,16 +338,17 @@  gimple_assign_nonzero_p (gimple *stmt)
 {
   enum tree_code code = gimple_assign_rhs_code (stmt);
   bool strict_overflow_p;
+  tree type = TREE_TYPE (gimple_assign_lhs (stmt));
   switch (get_gimple_rhs_class (code))
     {
     case GIMPLE_UNARY_RHS:
       return tree_unary_nonzero_warnv_p (gimple_assign_rhs_code (stmt),
-					 gimple_expr_type (stmt),
+					 type,
 					 gimple_assign_rhs1 (stmt),
 					 &strict_overflow_p);
     case GIMPLE_BINARY_RHS:
       return tree_binary_nonzero_warnv_p (gimple_assign_rhs_code (stmt),
-					  gimple_expr_type (stmt),
+					  type,
 					  gimple_assign_rhs1 (stmt),
 					  gimple_assign_rhs2 (stmt),
 					  &strict_overflow_p);
@@ -1025,7 +1026,7 @@  vr_values::extract_range_from_comparison (value_range_equiv *vr,
 					  gimple *stmt)
 {
   enum tree_code code = gimple_assign_rhs_code (stmt);
-  tree type = gimple_expr_type (stmt);
+  tree type = TREE_TYPE (gimple_assign_lhs (stmt));
   tree op0 = gimple_assign_rhs1 (stmt);
   tree op1 = gimple_assign_rhs2 (stmt);
   bool sop;
@@ -1164,7 +1165,6 @@  bool
 vr_values::extract_range_from_ubsan_builtin (value_range_equiv *vr, gimple *stmt)
 {
   gcc_assert (is_gimple_call (stmt));
-  tree type = gimple_expr_type (stmt);
   enum tree_code subcode = ERROR_MARK;
   combined_fn cfn = gimple_call_combined_fn (stmt);
   scalar_int_mode mode;
@@ -1190,7 +1190,8 @@  vr_values::extract_range_from_ubsan_builtin (value_range_equiv *vr, gimple *stmt
 	 any overflow, we'll complain, but will actually do
 	 wrapping operation.  */
       flag_wrapv = 1;
-      extract_range_from_binary_expr (vr, subcode, type,
+      extract_range_from_binary_expr (vr, subcode,
+				      TREE_TYPE (gimple_call_arg (stmt, 0)),
 				      gimple_call_arg (stmt, 0),
 				      gimple_call_arg (stmt, 1));
       flag_wrapv = saved_flag_wrapv;
@@ -1217,7 +1218,6 @@  void
 vr_values::extract_range_basic (value_range_equiv *vr, gimple *stmt)
 {
   bool sop;
-  tree type = gimple_expr_type (stmt);
 
   if (is_gimple_call (stmt))
     {
@@ -1244,13 +1244,14 @@  vr_values::extract_range_basic (value_range_equiv *vr, gimple *stmt)
   /* Handle extraction of the two results (result of arithmetics and
      a flag whether arithmetics overflowed) from {ADD,SUB,MUL}_OVERFLOW
      internal function.  Similarly from ATOMIC_COMPARE_EXCHANGE.  */
-  else if (is_gimple_assign (stmt)
-	   && (gimple_assign_rhs_code (stmt) == REALPART_EXPR
-	       || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
-	   && INTEGRAL_TYPE_P (type))
+  if (is_gimple_assign (stmt)
+      && (gimple_assign_rhs_code (stmt) == REALPART_EXPR
+	  || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
+      && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
     {
       enum tree_code code = gimple_assign_rhs_code (stmt);
       tree op = gimple_assign_rhs1 (stmt);
+      tree type = TREE_TYPE (gimple_assign_lhs (stmt));
       if (TREE_CODE (op) == code && TREE_CODE (TREE_OPERAND (op, 0)) == SSA_NAME)
 	{
 	  gimple *g = SSA_NAME_DEF_STMT (TREE_OPERAND (op, 0));
@@ -1328,6 +1329,9 @@  vr_values::extract_range_basic (value_range_equiv *vr, gimple *stmt)
 	    }
 	}
     }
+  /* None of the below should need a 'type', but we are only called
+     for assignments and calls with a LHS.  */
+  tree type = TREE_TYPE (gimple_get_lhs (stmt));
   if (INTEGRAL_TYPE_P (type)
       && gimple_stmt_nonnegative_warnv_p (stmt, &sop))
     set_value_range_to_nonnegative (vr, type);
@@ -1355,12 +1359,12 @@  vr_values::extract_range_from_assignment (value_range_equiv *vr, gassign *stmt)
     extract_range_from_ssa_name (vr, gimple_assign_rhs1 (stmt));
   else if (TREE_CODE_CLASS (code) == tcc_binary)
     extract_range_from_binary_expr (vr, gimple_assign_rhs_code (stmt),
-				    gimple_expr_type (stmt),
+				    TREE_TYPE (gimple_assign_lhs (stmt)),
 				    gimple_assign_rhs1 (stmt),
 				    gimple_assign_rhs2 (stmt));
   else if (TREE_CODE_CLASS (code) == tcc_unary)
     extract_range_from_unary_expr (vr, gimple_assign_rhs_code (stmt),
-				   gimple_expr_type (stmt),
+				   TREE_TYPE (gimple_assign_lhs (stmt)),
 				   gimple_assign_rhs1 (stmt));
   else if (code == COND_EXPR)
     extract_range_from_cond_expr (vr, stmt);