https://gcc.gnu.org/g:63091f28c166ba783f20f017c9b9349345990e9b
commit r17-6118-g63091f28c166ba783f20f017c9b9349345990e9b Author: Andrew MacLeod <[email protected]> Date: Fri Nov 6 10:26:46 2026 -0500 Inline pointer ranges Inlining previously ignored pointer ranges. This patch allows them to be inlined just like a normal range. Any function local address referred to in the range will be removed making it safe. This restores any information that was lost when it was carried in a ptr_info_def. This includes the alignment (now from the bitmask) and the non-null property (now carried by the range). * tree-inline.cc (remap_ssa_name): Drop local addresses from a prange, and inline pointers. * tree-ssanames.cc (duplicate_ssa_name_range_info): Remove function local addresses if requested. * tree-ssanames.h (duplicate_ssa_name_range_info): Adjust prototype. * value-range.cc (prange::clear_function_local_addr): Remove LABEL_DECLs as well. Diff: --- gcc/tree-inline.cc | 33 +++++++++++++++++---------------- gcc/tree-ssanames.cc | 12 ++++++++++-- gcc/tree-ssanames.h | 3 ++- gcc/value-range.cc | 8 +++++++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc index 7d73d5959073..6a3ba7b84839 100644 --- a/gcc/tree-inline.cc +++ b/gcc/tree-inline.cc @@ -241,6 +241,9 @@ remap_ssa_name (tree name, copy_body_data *id) insert_decl_map (id, name, new_tree); SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree) = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name); + /* Range info can be transferred, if local addresses are removed. */ + if (SSA_NAME_RANGE_INFO (name)) + duplicate_ssa_name_range_info (new_tree, name, true); /* At least IPA points-to info can be directly transferred. */ if (id->src_cfun->gimple_df && id->src_cfun->gimple_df->ipa_pta @@ -248,10 +251,6 @@ remap_ssa_name (tree name, copy_body_data *id) && (pt = ssa_name_pt_solution (name)) && !pt->anything) set_ssa_name_pt_solution (new_tree, *pt); - /* So can range-info. */ - if (!POINTER_TYPE_P (TREE_TYPE (name)) - && SSA_NAME_RANGE_INFO (name)) - duplicate_ssa_name_range_info (new_tree, name); return new_tree; } @@ -275,17 +274,8 @@ remap_ssa_name (tree name, copy_body_data *id) insert_decl_map (id, name, new_tree); SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree) = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name); - /* At least IPA points-to info can be directly transferred. */ - if (id->src_cfun->gimple_df - && id->src_cfun->gimple_df->ipa_pta - && POINTER_TYPE_P (TREE_TYPE (name)) - && (pt = ssa_name_pt_solution (name)) - && !pt->anything) - set_ssa_name_pt_solution (new_tree, *pt); - /* So can range-info. */ - if (!POINTER_TYPE_P (TREE_TYPE (name)) - && SSA_NAME_RANGE_INFO (name)) - duplicate_ssa_name_range_info (new_tree, name); + + tree zero = NULL_TREE; if (SSA_NAME_IS_DEFAULT_DEF (name)) { /* By inlining function having uninitialized variable, we might @@ -307,7 +297,7 @@ remap_ssa_name (tree name, copy_body_data *id) { gimple_stmt_iterator gsi = gsi_last_bb (id->entry_bb); gimple *init_stmt; - tree zero = build_zero_cst (TREE_TYPE (new_tree)); + zero = build_zero_cst (TREE_TYPE (new_tree)); init_stmt = gimple_build_assign (new_tree, zero); gsi_insert_after (&gsi, init_stmt, GSI_NEW_STMT); @@ -319,6 +309,17 @@ remap_ssa_name (tree name, copy_body_data *id) set_ssa_default_def (cfun, SSA_NAME_VAR (new_tree), new_tree); } } + /* Range info can be transferred if local addresses are removed + and no uninitialized name was processed and set to zero. */ + if (!zero && SSA_NAME_RANGE_INFO (name)) + duplicate_ssa_name_range_info (new_tree, name, true); + /* At least IPA points-to info can be directly transferred. */ + if (id->src_cfun->gimple_df + && id->src_cfun->gimple_df->ipa_pta + && POINTER_TYPE_P (TREE_TYPE (name)) + && (pt = ssa_name_pt_solution (name)) + && !pt->anything) + set_ssa_name_pt_solution (new_tree, *pt); } else insert_decl_map (id, name, new_tree); diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index b97738834f1b..77d8a9af6010 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -986,10 +986,14 @@ duplicate_ssa_name_pt_solution (tree dest, tree src) duplicate_ssa_name_pt_solution (dest, pt); } -/* Copy any global range information from SRC to NAME. */ +/* Copy any global range information from SRC to NAME. If REMOVE_LOCAL_ADDR + is true, then any specified address that a prange may refer to is checked + to see if it's local to the function and removed if so. + The default is FALSE, which is the previous default behaviour and copies + the entire range as is. */ void -duplicate_ssa_name_range_info (tree name, tree src) +duplicate_ssa_name_range_info (tree name, tree src, bool remove_local_addr) { gcc_checking_assert (!SSA_NAME_RANGE_INFO (name)); @@ -998,6 +1002,10 @@ duplicate_ssa_name_range_info (tree name, tree src) value_range src_range (TREE_TYPE (src)); range_info_get_range (src, src_range); + + /* Remove any local addresses from the range if present. */ + if (remove_local_addr && is_a <prange> (src_range)) + as_a <prange> (src_range).clear_function_local_addr (); range_info_set_range (name, src_range); unsigned align, misalign; diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index 9798df7d04d7..7f0b2f1f6574 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -88,7 +88,8 @@ extern tree copy_ssa_name_fn (struct function *, tree, gimple *); extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *); extern void duplicate_ssa_name_pt_solution (tree dest, const pt_solution *); extern void duplicate_ssa_name_pt_solution (tree dest, tree src); -extern void duplicate_ssa_name_range_info (tree dest, tree src); +extern void duplicate_ssa_name_range_info (tree dest, tree src, + bool remove_local_addr = false); extern void maybe_duplicate_ssa_info_at_copy (tree dest, tree src); extern void reset_flow_sensitive_info (tree); extern void reset_flow_sensitive_info_in_bb (basic_block); diff --git a/gcc/value-range.cc b/gcc/value-range.cc index bfc196f8ad2e..a7bd9db6bd49 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -585,7 +585,13 @@ prange::set_addr (tree expr, bool known_p) bool prange::clear_function_local_addr () { - if (m_addr && !is_gimple_ip_invariant (m_addr)) + if (!m_addr) + return false; + + /* is_gimple_ip_invariant () accepts the address of a LABEL_DECL, but + inlining and cloning could remap it, so remove it as well. */ + if (!is_gimple_ip_invariant (m_addr) + || TREE_CODE (TREE_OPERAND (m_addr, 0)) == LABEL_DECL) { set_addr_unknown (); return true;
