Prefer global range info setters that take a range.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 7 Mar 2022 13:56:34 +0000 (14:56 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 29 Apr 2022 08:43:36 +0000 (10:43 +0200)
This patch consolidates the multiple ways we have of storing global
ranges into one accepting a range.

In an upcoming patch series later this cycle we will be providing a
way to store iranges globally, as opposed to the mechanism we have now
which squishes wider ranges into value_range's.  This is preparation
for such work.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

* gimple-ssa-evrp-analyze.cc
(evrp_range_analyzer::set_ssa_range_info): Use *range_info methods
that take a range.
* gimple-ssa-sprintf.cc (try_substitute_return_value): Same.
* ipa-prop.cc (ipcp_update_vr): Same.
* tree-inline.cc (remap_ssa_name): Same.
* tree-ssa-copy.cc (fini_copy_prop): Same.
* tree-ssa-math-opts.cc (optimize_spaceship): Same.
* tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Same.
* tree-ssa-pre.cc (insert_into_preds_of_block): Same.
* tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt): Same.
* tree-ssa-strlen.cc (set_strlen_range): Same.
(strlen_pass::handle_builtin_string_cmp): Same.
* tree-ssanames.cc (set_range_info): Make static.
(duplicate_ssa_name_range_info): Make static and add a new variant
calling the static.
* tree-ssanames.h (set_range_info): Remove version taking wide ints.
(duplicate_ssa_name_range_info): Remove version taking a
range_info_def and replace with a version taking SSA names.
* tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Use *range_info methods
that take a range.
(vect_do_peeling): Same.
* tree-vrp.cc (vrp_asserts::remove_range_assertions): Same.
* vr-values.cc (simplify_truth_ops_using_ranges): Same.

15 files changed:
gcc/gimple-ssa-evrp-analyze.cc
gcc/gimple-ssa-sprintf.cc
gcc/ipa-prop.cc
gcc/tree-inline.cc
gcc/tree-ssa-copy.cc
gcc/tree-ssa-math-opts.cc
gcc/tree-ssa-phiopt.cc
gcc/tree-ssa-pre.cc
gcc/tree-ssa-sccvn.cc
gcc/tree-ssa-strlen.cc
gcc/tree-ssanames.cc
gcc/tree-ssanames.h
gcc/tree-vect-loop-manip.cc
gcc/tree-vrp.cc
gcc/vr-values.cc

index bed6dc2..5b6c9f8 100644 (file)
@@ -110,9 +110,7 @@ evrp_range_analyzer::set_ssa_range_info (tree lhs, value_range_equiv *vr)
   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
     {
       if (!vr->varying_p () && vr->constant_p ())
-       set_range_info (lhs, vr->kind (),
-                       wi::to_wide (vr->min ()),
-                       wi::to_wide (vr->max ()));
+       set_range_info (lhs, *vr);
     }
   else if (POINTER_TYPE_P (TREE_TYPE (lhs))
           && range_includes_zero_p (vr) == 0)
index c93f12f..9a84fff 100644 (file)
@@ -4231,7 +4231,8 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
 
          wide_int min = wi::shwi (retval[0], prec);
          wide_int max = wi::shwi (retval[1], prec);
-         set_range_info (lhs, VR_RANGE, min, max);
+         value_range r (TREE_TYPE (lhs), min, max);
+         set_range_info (lhs, r);
 
          setrange = true;
        }
index 0e59663..80e67e9 100644 (file)
@@ -5987,11 +5987,13 @@ ipcp_update_vr (struct cgraph_node *node)
                  print_decs (vr[i].max, dump_file);
                  fprintf (dump_file, "]\n");
                }
-             set_range_info (ddef, vr[i].type,
-                             wide_int_storage::from (vr[i].min, prec,
-                                                     TYPE_SIGN (type)),
-                             wide_int_storage::from (vr[i].max, prec,
-                                                     TYPE_SIGN (type)));
+             value_range v (type,
+                            wide_int_storage::from (vr[i].min, prec,
+                                                    TYPE_SIGN (type)),
+                            wide_int_storage::from (vr[i].max, prec,
+                                                    TYPE_SIGN (type)),
+                            vr[i].type);
+             set_range_info (ddef, v);
            }
          else if (POINTER_TYPE_P (TREE_TYPE (ddef))
                   && vr[i].nonzero_p (TREE_TYPE (ddef)))
index ca66a82..29bb758 100644 (file)
@@ -253,8 +253,7 @@ remap_ssa_name (tree name, copy_body_data *id)
       /* So can range-info.  */
       if (!POINTER_TYPE_P (TREE_TYPE (name))
          && SSA_NAME_RANGE_INFO (name))
-       duplicate_ssa_name_range_info (new_tree, SSA_NAME_RANGE_TYPE (name),
-                                      SSA_NAME_RANGE_INFO (name));
+       duplicate_ssa_name_range_info (new_tree, name);
       return new_tree;
     }
 
@@ -291,8 +290,7 @@ remap_ssa_name (tree name, copy_body_data *id)
       /* So can range-info.  */
       if (!POINTER_TYPE_P (TREE_TYPE (name))
          && SSA_NAME_RANGE_INFO (name))
-       duplicate_ssa_name_range_info (new_tree, SSA_NAME_RANGE_TYPE (name),
-                                      SSA_NAME_RANGE_INFO (name));
+       duplicate_ssa_name_range_info (new_tree, name);
       if (SSA_NAME_IS_DEFAULT_DEF (name))
        {
          /* By inlining function having uninitialized variable, we might
index 7651352..7d636ec 100644 (file)
@@ -556,9 +556,7 @@ fini_copy_prop (void)
                   && SSA_NAME_RANGE_INFO (var)
                   && !SSA_NAME_RANGE_INFO (copy_of[i].value)
                   && var_bb == copy_of_bb)
-           duplicate_ssa_name_range_info (copy_of[i].value,
-                                          SSA_NAME_RANGE_TYPE (var),
-                                          SSA_NAME_RANGE_INFO (var));
+           duplicate_ssa_name_range_info (copy_of[i].value, var);
        }
     }
 
index 7555793..b528b05 100644 (file)
@@ -4862,7 +4862,8 @@ optimize_spaceship (gimple *stmt)
 
   wide_int wm1 = wi::minus_one (TYPE_PRECISION (integer_type_node));
   wide_int w2 = wi::two (TYPE_PRECISION (integer_type_node));
-  set_range_info (lhs, VR_RANGE, wm1, w2);
+  value_range vr (TREE_TYPE (lhs), wm1, w2);
+  set_range_info (lhs, vr);
 }
 
 
index 3eda825..8c9c46d 100644 (file)
@@ -416,9 +416,7 @@ replace_phi_edge_with_variable (basic_block cond_block,
       && SSA_NAME_RANGE_INFO (phi_result)
       && gimple_bb (SSA_NAME_DEF_STMT (new_tree)) == cond_block
       && dbg_cnt (phiopt_edge_range))
-    duplicate_ssa_name_range_info (new_tree,
-                                  SSA_NAME_RANGE_TYPE (phi_result),
-                                  SSA_NAME_RANGE_INFO (phi_result));
+    duplicate_ssa_name_range_info (new_tree, phi_result);
 
   /* Change the PHI argument to new.  */
   SET_USE (PHI_ARG_DEF_PTR (phi, e->dest_idx), new_tree);
index 47d70c8..a578ce6 100644 (file)
@@ -3246,14 +3246,11 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
          && r.kind () == VR_RANGE
          && !wi::neg_p (r.lower_bound (), SIGNED)
          && !wi::neg_p (r.upper_bound (), SIGNED))
-       /* Just handle extension and sign-changes of all-positive ranges.  */
-       set_range_info (temp, VR_RANGE,
-                       wide_int_storage::from (r.lower_bound (),
-                                               TYPE_PRECISION (type),
-                                               TYPE_SIGN (type)),
-                       wide_int_storage::from (r.upper_bound (),
-                                               TYPE_PRECISION (type),
-                                               TYPE_SIGN (type)));
+       {
+         /* Just handle extension and sign-changes of all-positive ranges.  */
+         range_cast (r, type);
+         set_range_info (temp, r);
+       }
     }
 
   if (dump_file && (dump_flags & TDF_DETAILS))
index d4d0aba..3c90c1e 100644 (file)
@@ -6304,9 +6304,7 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
                   && SSA_NAME_RANGE_INFO (lhs)
                   && ! SSA_NAME_RANGE_INFO (sprime)
                   && b == sprime_b)
-           duplicate_ssa_name_range_info (sprime,
-                                          SSA_NAME_RANGE_TYPE (lhs),
-                                          SSA_NAME_RANGE_INFO (lhs));
+           duplicate_ssa_name_range_info (sprime, lhs);
        }
 
       /* Inhibit the use of an inserted PHI on a loop header when
index 9ae25d1..1e5f911 100644 (file)
@@ -1951,7 +1951,8 @@ set_strlen_range (tree lhs, wide_int min, wide_int max,
   if (min == max)
     return wide_int_to_tree (size_type_node, min);
 
-  set_range_info (lhs, VR_RANGE, min, max);
+  value_range vr (TREE_TYPE (lhs), min, max);
+  set_range_info (lhs, vr);
   return lhs;
 }
 
@@ -4343,8 +4344,9 @@ strlen_pass::handle_builtin_string_cmp ()
               known to be unequal set the range of the result to non-zero.
               This allows the call to be eliminated if its result is only
               used in tests for equality to zero.  */
-           wide_int zero = wi::zero (TYPE_PRECISION (TREE_TYPE (lhs)));
-           set_range_info (lhs, VR_ANTI_RANGE, zero, zero);
+           value_range nz;
+           nz.set_nonzero (TREE_TYPE (lhs));
+           set_range_info (lhs, nz);
            return false;
          }
        /* When the two strings are definitely equal (such as when they
index e0a6884..c957597 100644 (file)
@@ -389,7 +389,7 @@ set_range_info_raw (tree name, enum value_range_kind range_type,
 /* Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name
    NAME while making sure we don't store useless range info.  */
 
-void
+static void
 set_range_info (tree name, enum value_range_kind range_type,
                const wide_int_ref &min, const wide_int_ref &max)
 {
@@ -720,7 +720,7 @@ duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
 
 /* Creates a duplicate of the range_info_def at RANGE_INFO of type
    RANGE_TYPE for use by the SSA name NAME.  */
-void
+static void
 duplicate_ssa_name_range_info (tree name, enum value_range_kind range_type,
                               struct range_info_def *range_info)
 {
@@ -743,6 +743,14 @@ duplicate_ssa_name_range_info (tree name, enum value_range_kind range_type,
   SSA_NAME_RANGE_INFO (name) = new_range_info;
 }
 
+void
+duplicate_ssa_name_range_info (tree name, tree src)
+{
+  gcc_checking_assert (!POINTER_TYPE_P (TREE_TYPE (src)));
+  duplicate_ssa_name_range_info (name,
+                                SSA_NAME_RANGE_TYPE (src),
+                                SSA_NAME_RANGE_INFO (src));
+}
 
 
 /* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
index 7538ba9..8c419b1 100644 (file)
@@ -67,8 +67,6 @@ struct GTY ((variable_size)) range_info_def {
     if (VAR)
 
 /* Sets the value range to SSA.  */
-extern void set_range_info (tree, enum value_range_kind, const wide_int_ref &,
-                           const wide_int_ref &);
 extern void set_range_info (tree, const value_range &);
 extern void set_nonzero_bits (tree, const wide_int_ref &);
 extern wide_int get_nonzero_bits (const_tree);
@@ -92,8 +90,7 @@ extern void set_ptr_nonnull (tree);
 extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
 extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *);
-extern void duplicate_ssa_name_range_info (tree, enum value_range_kind,
-                                          struct range_info_def *);
+extern void duplicate_ssa_name_range_info (tree dest, tree src);
 extern void reset_flow_sensitive_info (tree);
 extern void reset_flow_sensitive_info_in_bb (basic_block);
 extern void release_defs (gimple *);
index e4381eb..3eddda6 100644 (file)
@@ -2056,22 +2056,28 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters,
       if (stmts != NULL && log_vf)
        {
          if (niters_no_overflow)
-           set_range_info (niters_vector, VR_RANGE,
-                           wi::one (TYPE_PRECISION (type)),
-                           wi::rshift (wi::max_value (TYPE_PRECISION (type),
-                                                      TYPE_SIGN (type)),
-                                       exact_log2 (const_vf),
-                                       TYPE_SIGN (type)));
+           {
+             value_range vr (type,
+                             wi::one (TYPE_PRECISION (type)),
+                             wi::rshift (wi::max_value (TYPE_PRECISION (type),
+                                                        TYPE_SIGN (type)),
+                                         exact_log2 (const_vf),
+                                         TYPE_SIGN (type)));
+             set_range_info (niters_vector, vr);
+           }
          /* For VF == 1 the vector IV might also overflow so we cannot
             assert a minimum value of 1.  */
          else if (const_vf > 1)
-           set_range_info (niters_vector, VR_RANGE,
-                           wi::one (TYPE_PRECISION (type)),
-                           wi::rshift (wi::max_value (TYPE_PRECISION (type),
-                                                      TYPE_SIGN (type))
-                                       - (const_vf - 1),
-                                       exact_log2 (const_vf), TYPE_SIGN (type))
-                           + 1);
+           {
+             value_range vr (type,
+                             wi::one (TYPE_PRECISION (type)),
+                             wi::rshift (wi::max_value (TYPE_PRECISION (type),
+                                                        TYPE_SIGN (type))
+                                         - (const_vf - 1),
+                                         exact_log2 (const_vf), TYPE_SIGN (type))
+                             + 1);
+             set_range_info (niters_vector, vr);
+           }
        }
     }
   *niters_vector_ptr = niters_vector;
@@ -2888,9 +2894,12 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
       /* It's guaranteed that vector loop bound before vectorization is at
         least VF, so set range information for newly generated var.  */
       if (new_var_p)
-       set_range_info (niters, VR_RANGE,
-                       wi::to_wide (build_int_cst (type, vf)),
-                       wi::to_wide (TYPE_MAX_VALUE (type)));
+       {
+         value_range vr (type,
+                         wi::to_wide (build_int_cst (type, vf)),
+                         wi::to_wide (TYPE_MAX_VALUE (type)));
+         set_range_info (niters, vr);
+       }
 
       /* Prolog iterates at most bound_prolog times, latch iterates at
         most bound_prolog - 1 times.  */
index e9f19d0..ab6aa11 100644 (file)
@@ -3742,9 +3742,16 @@ vrp_asserts::remove_range_assertions ()
                    && all_imm_uses_in_stmt_or_feed_cond (var, stmt,
                                                          single_pred (bb)))
                  {
-                   set_range_info (var, SSA_NAME_RANGE_TYPE (lhs),
-                                   SSA_NAME_RANGE_INFO (lhs)->get_min (),
-                                   SSA_NAME_RANGE_INFO (lhs)->get_max ());
+                   /* We could use duplicate_ssa_name_range_info here
+                      instead of peeking inside SSA_NAME_RANGE_INFO,
+                      but the aforementioned asserts that the
+                      destination has no global range.  This is
+                      slated for removal anyhow.  */
+                   value_range r (TREE_TYPE (lhs),
+                                  SSA_NAME_RANGE_INFO (lhs)->get_min (),
+                                  SSA_NAME_RANGE_INFO (lhs)->get_max (),
+                                  SSA_NAME_RANGE_TYPE (lhs));
+                   set_range_info (var, r);
                    maybe_set_nonzero_bits (single_pred_edge (bb), var);
                  }
              }
index f94da31..122586f 100644 (file)
@@ -2980,9 +2980,12 @@ simplify_using_ranges::simplify_truth_ops_using_ranges
       gsi_insert_before (gsi, newop, GSI_SAME_STMT);
       if (INTEGRAL_TYPE_P (TREE_TYPE (tem))
          && TYPE_PRECISION (TREE_TYPE (tem)) > 1)
-       set_range_info (tem, VR_RANGE,
-                       wi::zero (TYPE_PRECISION (TREE_TYPE (tem))),
-                       wi::one (TYPE_PRECISION (TREE_TYPE (tem))));
+       {
+         value_range vr (TREE_TYPE (tem),
+                         wi::zero (TYPE_PRECISION (TREE_TYPE (tem))),
+                         wi::one (TYPE_PRECISION (TREE_TYPE (tem))));
+         set_range_info (tem, vr);
+       }
       gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, tem);
     }
   /* Or without.  */