https://gcc.gnu.org/g:e7dabe6fa0b428522458d538ba5c8ca71a79a35c
commit r17-6417-ge7dabe6fa0b428522458d538ba5c8ca71a79a35c Author: Filip Kastl <[email protected]> Date: Tue Sep 15 16:42:13 2026 +0200 IPA PTA: Remove redundant iteration over fields of globals IPA PTA postprocesses points-to solutions to correctly handle recursive invocations of functions. This is because a recursive function may use pointers to automatic variables from the previous stack frames. IPA PTA uses shadow variables for this. The shadow variable logic iterates over IPA PTA's representation of global variables (varinfo_t structs with ->is_global_var = true). A global variable may contain multiple fields. For example: struct { int *x; int *y; } a; The shadow variable logic addresses this with a loop over varinfos representing the fields of a global variable. But this is redundant since each field is itself considered a global variable by IPA PTA. Thus, we visit a single varinfo multiple times. In the case of struct a, we visit x and y. Then, when the outer loop reaches y directly, we visit y again. This patch fixes this by removing the inner loop over fields. Note that to my knowledge, this issue is latent. Although IPA PTA contains the logic for handling global struct variables, it currently doesn't have this feature enabled. gcc/ChangeLog: * tree-ssa-structalias.cc (ipa_pta_execute): In shadow variable solution postprocessing, don't iterate over fields of global variables. Signed-off-by: Filip Kastl <[email protected]> Diff: --- gcc/tree-ssa-structalias.cc | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc index af8100d49a52..2c379e431a41 100644 --- a/gcc/tree-ssa-structalias.cc +++ b/gcc/tree-ssa-structalias.cc @@ -1898,21 +1898,18 @@ ipa_pta_execute (void) arguments to recursive invocations. */ else if (fi->is_global_var) { - for (varinfo_t ai = fi; ai; ai = vi_next (ai)) + varinfo_t vi = get_varinfo (var_rep[fi->id]); + bitmap_iterator bi; + unsigned j; + EXECUTE_IF_SET_IN_BITMAP (vi->solution, 0, j, bi) { - varinfo_t vi = get_varinfo (var_rep[ai->id]); - bitmap_iterator bi; - unsigned j; - EXECUTE_IF_SET_IN_BITMAP (vi->solution, 0, j, bi) + varinfo_t pt = get_varinfo (j); + if (pt->shadow_var_uid == 0 + && pt->decl + && auto_var_p (pt->decl)) { - varinfo_t pt = get_varinfo (j); - if (pt->shadow_var_uid == 0 - && pt->decl - && auto_var_p (pt->decl)) - { - pt->shadow_var_uid = allocate_decl_uid (); - shadow_var_cnt++; - } + pt->shadow_var_uid = allocate_decl_uid (); + shadow_var_cnt++; } } }
