https://gcc.gnu.org/g:c7fbae9475808c8ddd5165e484815a3d854ddcd5
commit r17-5684-gc7fbae9475808c8ddd5165e484815a3d854ddcd5 Author: Andrew MacLeod <[email protected]> Date: Wed Oct 21 20:51:59 2026 -0400 Adjust ptr_info_align API to take an ssa name All ptr_info_align queries require geting the ptr_info_def structure from a prange_storage, then using that as the paramater in the rotuines. This changes the API to take the name directly, avoiding the get_ptr_info() call, and simplifying removal of the alignment fields in a later patch as all references to the ptr_info_)def structure are removed from the client calls. Assisted-by: Claude Opus 5 * builtins.cc (get_pointer_alignment_1): Adjust call to new API. * gimple-low.cc (lower_builtin_assume_aligned): Likewise. * gimple-pretty-print.cc (dump_ssaname_info): Likewise. * ipa-prop.cc (ipcp_update_vr): Likewise. * tree-ssa-ccp.cc (ccp_finalize): Likewise. * tree-ssa-dom.cc (maybe_set_nonzero_bits): Likewise. * tree-ssa-loop-ivopts.cc (rewrite_use_nonlinear_expr): Likewise. * tree-ssa-loop-prefetch.cc (issue_prefetch_ref): Likewise. * tree-ssa-pre.cc (create_expression_by_pieces): Likewise. * tree-ssanames.cc (get_nonzero_bits_1): Likewise. (get_ptr_info_alignment): Adjust parameter. (mark_ptr_info_alignment_unknown): Likewise. (set_ptr_info_alignment): Likewise. (adjust_ptr_info_misalignment): Remove. (get_ptr_info): Use new API. (reset_flow_sensitive_info): Likewise. (flow_sensitive_info_storage::save): Likewise. (flow_sensitive_info_storage::restore): Likewise. * tree-ssanames.h (get_ptr_info_alignment): Adjust prototype. (mark_ptr_info_alignment_unknown): Likewise. (set_ptr_info_alignment): Likewise. (adjust_ptr_info_misalignment): Remove prototype. * tree-vect-data-refs.cc (vect_duplicate_ssa_name_ptr_info): Adjust to new API. * tree-vect-stmts.cc (create_array_ref): Likewise. (vectorizable_store): Likewise. (vectorizable_load): Likewise. Diff: --- gcc/builtins.cc | 3 +- gcc/gimple-low.cc | 3 +- gcc/gimple-pretty-print.cc | 2 +- gcc/ipa-prop.cc | 8 ++--- gcc/tree-ssa-ccp.cc | 2 +- gcc/tree-ssa-dom.cc | 9 ++--- gcc/tree-ssa-loop-ivopts.cc | 3 +- gcc/tree-ssa-loop-prefetch.cc | 3 +- gcc/tree-ssa-pre.cc | 3 +- gcc/tree-ssanames.cc | 82 ++++++++++++++++++------------------------- gcc/tree-ssanames.h | 15 ++++---- gcc/tree-vect-data-refs.cc | 2 +- gcc/tree-vect-stmts.cc | 7 ++-- 13 files changed, 62 insertions(+), 80 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 3127e0e82a1c..9a8e499ddb19 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -454,9 +454,8 @@ get_pointer_alignment_1 (tree exp, unsigned int *alignp, && POINTER_TYPE_P (TREE_TYPE (exp))) { unsigned int ptr_align, ptr_misalign; - struct ptr_info_def *pi = SSA_NAME_PTR_INFO (exp); - if (pi && get_ptr_info_alignment (pi, &ptr_align, &ptr_misalign)) + if (get_ptr_info_alignment (exp, &ptr_align, &ptr_misalign)) { *bitposp = ptr_misalign * BITS_PER_UNIT; *alignp = ptr_align * BITS_PER_UNIT; diff --git a/gcc/gimple-low.cc b/gcc/gimple-low.cc index f5e175387fcc..7c8055076c3b 100644 --- a/gcc/gimple-low.cc +++ b/gcc/gimple-low.cc @@ -1421,8 +1421,7 @@ lower_builtin_assume_aligned (gimple_stmt_iterator *gsi) /* For lowering we simply transfer alignment information to the result and leave the call otherwise unchanged, it will be elided at RTL expansion time. */ - ptr_info_def *pi = get_ptr_info (lhs); - set_ptr_info_alignment (pi, aligni, misaligni); + set_ptr_info_alignment (lhs, aligni, misaligni); } diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc index ecbd02c92da7..ae7fdb2d7525 100644 --- a/gcc/gimple-pretty-print.cc +++ b/gcc/gimple-pretty-print.cc @@ -2408,7 +2408,7 @@ dump_ssaname_info (pretty_printer *pp, tree node, int spc) pp_string (pp, "# PT = "); pp_points_to_solution (pp, &pi->pt); newline_and_indent (pp, spc); - if (get_ptr_info_alignment (pi, &align, &misalign)) + if (get_ptr_info_alignment (node, &align, &misalign)) { pp_printf (pp, "# ALIGN = %u, MISALIGN = %u", align, misalign); newline_and_indent (pp, spc); diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 209dd1d4c0bf..473239db36dd 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -6694,9 +6694,9 @@ ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts) align, misalign); unsigned old_align, old_misalign; - struct ptr_info_def *pi = get_ptr_info (ddef); - bool old_known = get_ptr_info_alignment (pi, &old_align, - &old_misalign); + bool old_known + = get_ptr_info_alignment (ddef, &old_align, + &old_misalign); if (old_known && old_align > align) { @@ -6722,7 +6722,7 @@ ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts) "mismatch\n", old_misalign, misalign); - set_ptr_info_alignment (pi, align, misalign); + set_ptr_info_alignment (ddef, align, misalign); } } else if (dump_file && INTEGRAL_TYPE_P (TREE_TYPE (parm))) diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc index 981346230b05..089c6ae3bf76 100644 --- a/gcc/tree-ssa-ccp.cc +++ b/gcc/tree-ssa-ccp.cc @@ -1036,7 +1036,7 @@ ccp_finalize (bool nonzero_p) tem = val->mask.to_uhwi (); align = least_bit_hwi (tem); if (align > 1) - set_ptr_info_alignment (get_ptr_info (name), align, + set_ptr_info_alignment (name, align, (TREE_INT_CST_LOW (val->value) & (align - 1))); } diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 9c4fb474f5fc..970d45da6af7 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1255,16 +1255,17 @@ maybe_set_nonzero_bits (edge e, tree var) cst = gimple_assign_rhs2 (stmt); if (POINTER_TYPE_P (TREE_TYPE (var))) { - struct ptr_info_def *pi = SSA_NAME_PTR_INFO (var); - if (pi && pi->misalign) + unsigned int old_align, old_misalign; + bool known = get_ptr_info_alignment (var, &old_align, &old_misalign); + if (known && old_misalign) return; wide_int w = wi::bit_not (wi::to_wide (cst)); unsigned int bits = wi::ctz (w); if (bits == 0 || bits >= HOST_BITS_PER_INT) return; unsigned int align = 1U << bits; - if (pi == NULL || pi->align < align) - set_ptr_info_alignment (get_ptr_info (var), align, 0); + if (!known || old_align < align) + set_ptr_info_alignment (var, align, 0); } else set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var), diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc index 006ec7362bc7..1a51c7046fbd 100644 --- a/gcc/tree-ssa-loop-ivopts.cc +++ b/gcc/tree-ssa-loop-ivopts.cc @@ -7547,8 +7547,7 @@ rewrite_use_nonlinear_expr (struct ivopts_data *data, duplicate_ssa_name_ptr_info (comp, SSA_NAME_PTR_INFO (tgt)); /* As this isn't a plain copy we have to reset alignment information. */ - if (SSA_NAME_PTR_INFO (comp)) - mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (comp)); + mark_ptr_info_alignment_unknown (comp); } } diff --git a/gcc/tree-ssa-loop-prefetch.cc b/gcc/tree-ssa-loop-prefetch.cc index ab9824c48f38..16f3c02d7f91 100644 --- a/gcc/tree-ssa-loop-prefetch.cc +++ b/gcc/tree-ssa-loop-prefetch.cc @@ -1214,8 +1214,7 @@ issue_prefetch_ref (struct mem_ref *ref, unsigned unroll_factor, unsigned ahead) duplicate_ssa_name_ptr_info (addr, SSA_NAME_PTR_INFO (addr_base)); /* As this isn't a plain copy we have to reset alignment information. */ - if (SSA_NAME_PTR_INFO (addr)) - mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (addr)); + mark_ptr_info_alignment_unknown (addr); } /* Create the prefetch instruction. */ diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index d2f0a93858c2..5d50e92a1d34 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -3169,8 +3169,7 @@ create_expression_by_pieces (basic_block block, pre_expr expr, if ((halign & (halign - 1)) == 0 && (hmisalign & ~(halign - 1)) == 0 && (unsigned int)halign != 0) - set_ptr_info_alignment (get_ptr_info (forcedname), - halign, hmisalign); + set_ptr_info_alignment (forcedname, halign, hmisalign); } gimple_set_vuse (call, BB_LIVE_VOP_ON_EXIT (block)); gimple_seq_add_stmt_without_update (&forced_stmts, call); diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index 9f0cddfb38ab..5ab3f156e0c5 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -545,10 +545,10 @@ get_nonzero_bits_1 (const_tree name) if (POINTER_TYPE_P (TREE_TYPE (name))) { - struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name); - if (pi && pi->align) - return wi::shwi (-(HOST_WIDE_INT) pi->align - | (HOST_WIDE_INT) pi->misalign, precision); + unsigned int align, misalign; + if (get_ptr_info_alignment (name, &align, &misalign)) + return wi::shwi (-(HOST_WIDE_INT) align + | (HOST_WIDE_INT) misalign, precision); return wi::shwi (-1, precision); } @@ -745,15 +745,18 @@ release_ssa_name_fn (struct function *fn, tree var) } } -/* If the alignment of the pointer described by PI is known, return true and - store the alignment and the deviation from it into *ALIGNP and *MISALIGNP - respectively. Otherwise return false. */ +/* If the alignment of the pointer NAME is known, return true and store the + alignment and the deviation from it into *ALIGNP and *MISALIGNP + respectively. Otherwise return false. A name with no aliasing info has + no known alignment, so this is safe to ask about any name. */ bool -get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp, +get_ptr_info_alignment (const_tree name, unsigned int *alignp, unsigned int *misalignp) { - if (pi->align) + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name); + + if (pi && pi->align) { *alignp = pi->align; *misalignp = pi->misalign; @@ -763,48 +766,38 @@ get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp, return false; } -/* State that the pointer described by PI has unknown alignment. */ +/* State that the pointer NAME has unknown alignment. A name with no + aliasing info already has unknown alignment, so this is a no-op rather + than a reason for the caller to check. */ void -mark_ptr_info_alignment_unknown (struct ptr_info_def *pi) +mark_ptr_info_alignment_unknown (tree name) { - pi->align = 0; - pi->misalign = 0; + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name); + + if (pi) + { + pi->align = 0; + pi->misalign = 0; + } } /* Store the power-of-two byte alignment and the deviation from that - alignment of pointer described by PI to ALIOGN and MISALIGN - respectively. */ + alignment of the pointer NAME to ALIGN and MISALIGN respectively. + Aliasing info is created for NAME if it does not have any yet. */ void -set_ptr_info_alignment (struct ptr_info_def *pi, unsigned int align, - unsigned int misalign) +set_ptr_info_alignment (tree name, unsigned int align, unsigned int misalign) { gcc_checking_assert (align != 0); gcc_assert ((align & (align - 1)) == 0); gcc_assert ((misalign & ~(align - 1)) == 0); + struct ptr_info_def *pi = get_ptr_info (name); pi->align = align; pi->misalign = misalign; } -/* If pointer described by PI has known alignment, increase its known - misalignment by INCREMENT modulo its current alignment. */ - -void -adjust_ptr_info_misalignment (struct ptr_info_def *pi, poly_uint64 increment) -{ - if (pi->align != 0) - { - increment += pi->misalign; - if (!known_misalignment (increment, pi->align, &pi->misalign)) - { - pi->align = known_alignment (increment); - pi->misalign = 0; - } - } -} - /* Make PI the aliasing information for NAME. Allocate a VARYING range if NAME does not already have a range. */ @@ -834,9 +827,10 @@ get_ptr_info (tree t) pi = SSA_NAME_PTR_INFO (t); if (pi == NULL) { + // The cleared allocation leaves align and misalign zero, which is + // what unknown alignment is, so there is nothing more to initialize. pi = ggc_cleared_alloc<ptr_info_def> (); pt_solution_reset (&pi->pt); - mark_ptr_info_alignment_unknown (pi); set_ssa_name_ptr_info (t, pi); } @@ -950,7 +944,7 @@ reset_flow_sensitive_info (tree name) set_ssa_name_ptr_info (name, pi); /* [E]VRP can derive context sensitive alignment info and non-nullness properties. We must reset both. */ - mark_ptr_info_alignment_unknown (pi); + mark_ptr_info_alignment_unknown (name); pi->pt.null = 1; } @@ -1102,19 +1096,13 @@ flow_sensitive_info_storage::save (tree name) return; } state = -1; - auto ptr_info = SSA_NAME_PTR_INFO (name); - if (ptr_info) - { - align = ptr_info->align; - misalign = ptr_info->misalign; - null = SSA_NAME_PTR_INFO (name)->pt.null; - } - else + if (!get_ptr_info_alignment (name, &align, &misalign)) { align = 0; misalign = 0; - null = true; } + auto ptr_info = SSA_NAME_PTR_INFO (name); + null = ptr_info ? ptr_info->pt.null : true; } /* Restore the flow sensitive info from NAME. */ @@ -1136,9 +1124,9 @@ flow_sensitive_info_storage::restore (tree name) if (!ptr_info) return; if (align != 0) - set_ptr_info_alignment (ptr_info, align, misalign); + set_ptr_info_alignment (name, align, misalign); else - mark_ptr_info_alignment_unknown (ptr_info); + mark_ptr_info_alignment_unknown (name); SSA_NAME_PTR_INFO (name)->pt.null = null; } diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index ea38a3bc3c52..311c4c2a1617 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -34,9 +34,10 @@ struct GTY(()) ptr_info_def /* When known, this is the power-of-two byte alignment of the object this pointer points into. This is usually DECL_ALIGN_UNIT for decls and MALLOC_ABI_ALIGNMENT for allocated storage. When the alignment is not - known, it is zero. Do not access directly but use functions - get_ptr_info_alignment, set_ptr_info_alignment, - mark_ptr_info_alignment_unknown and similar. */ + known, it is zero. Do not access directly: the only accessors are + get_ptr_info_alignment, set_ptr_info_alignment and + mark_ptr_info_alignment_unknown, and they take the SSA name rather + than this structure, so that the representation can move. */ unsigned int align; /* When alignment is known, the byte offset this pointer differs from the @@ -73,12 +74,10 @@ extern tree make_ssa_name_fn (struct function *, tree, gimple *, unsigned int version = 0); extern void init_ssa_name_imm_use (tree); extern void release_ssa_name_fn (struct function *, tree); -extern bool get_ptr_info_alignment (struct ptr_info_def *, unsigned int *, +extern bool get_ptr_info_alignment (const_tree, unsigned int *, unsigned int *); -extern void mark_ptr_info_alignment_unknown (struct ptr_info_def *); -extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int, - unsigned int); -extern void adjust_ptr_info_misalignment (struct ptr_info_def *, poly_uint64); +extern void mark_ptr_info_alignment_unknown (tree); +extern void set_ptr_info_alignment (tree, unsigned int, unsigned int); extern struct ptr_info_def *get_ptr_info (tree); extern void set_ptr_nonnull (tree); diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 22fce2c927b3..38889b734910 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -5554,7 +5554,7 @@ vect_duplicate_ssa_name_ptr_info (tree name, dr_vec_info *dr_info) duplicate_ssa_name_ptr_info (name, DR_PTR_INFO (dr_info->dr)); /* DR_PTR_INFO is for a base SSA name, not including constant or variable offsets in the ref so its alignment info does not apply. */ - mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (name)); + mark_ptr_info_alignment_unknown (name); } else if (!SSA_NAME_PTR_INFO (name)) { diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index b33d3f6b7826..94231514b0e2 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -227,7 +227,7 @@ create_array_ref (tree type, tree ptr, tree alias_ptr_type) mem_ref = build2 (MEM_REF, type, ptr, build_int_cst (alias_ptr_type, 0)); /* Arrays have the same alignment as their type. */ - set_ptr_info_alignment (get_ptr_info (ptr), TYPE_ALIGN_UNIT (type), 0); + set_ptr_info_alignment (ptr, TYPE_ALIGN_UNIT (type), 0); return mem_ref; } @@ -9497,7 +9497,7 @@ vectorizable_store (vec_info *vinfo, misalign = misalignment; if (dataref_offset == NULL_TREE && TREE_CODE (dataref_ptr) == SSA_NAME) - set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, misalign); + set_ptr_info_alignment (dataref_ptr, align, misalign); align = least_bit_hwi (misalign | align); /* Compute IFN when LOOP_LENS or final_mask valid. */ @@ -11563,8 +11563,7 @@ vectorizable_load (vec_info *vinfo, misalign = misalignment; if (dataref_offset == NULL_TREE && TREE_CODE (dataref_ptr) == SSA_NAME) - set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, - misalign); + set_ptr_info_alignment (dataref_ptr, align, misalign); align = least_bit_hwi (misalign | align); /* Compute IFN when LOOP_LENS or final_mask valid. */
