Hi! On Thu, Feb 15, 2024 at 08:29:24AM +0100, Jakub Jelinek wrote: > 2024-02-15 Jakub Jelinek <ja...@redhat.com> > > PR middle-end/113907 > * ipa-icf.cc (sem_item_optimizer::merge_classes): Reset > SSA_NAME_RANGE_INFO and SSA_NAME_PTR_INFO on successfully ICF merged > functions. > > * gcc.dg/pr113907.c: New test.
I'd like to ping the https://gcc.gnu.org/pipermail/gcc-patches/2024-February/645644.html patch. After looking at this PR again yesterday, I'm convinced we don't need either this patch or some other patch to deal with the jump functions, but both, this patch to clear (or other variant would be to union them) SSA_NAME_RANGE_INFO in the bodies of IPA-ICF merged functions, and another patch that would maybe in sem_function::merge go through all the callees cgraph edges and for each of them attempt to merge (for value range union) at least the value range/pointer alignment information from the corresponding cgraph edge from alias for all jump functions of all the arguments. Bootstrapped/regtested again last night. > --- gcc/ipa-icf.cc.jj 2024-02-14 14:26:11.101933914 +0100 > +++ gcc/ipa-icf.cc 2024-02-14 16:49:35.141518117 +0100 > @@ -3396,6 +3397,7 @@ sem_item_optimizer::merge_classes (unsig > continue; > > sem_item *source = c->members[0]; > + bool this_merged_p = false; > > if (DECL_NAME (source->decl) > && MAIN_NAME_P (DECL_NAME (source->decl))) > @@ -3443,7 +3445,7 @@ sem_item_optimizer::merge_classes (unsig > if (dbg_cnt (merged_ipa_icf)) > { > bool merged = source->merge (alias); > - merged_p |= merged; > + this_merged_p |= merged; > > if (merged && alias->type == VAR) > { > @@ -3452,6 +3454,35 @@ sem_item_optimizer::merge_classes (unsig > } > } > } > + > + merged_p |= this_merged_p; > + if (this_merged_p > + && source->type == FUNC > + && (!flag_wpa || flag_checking)) > + { > + unsigned i; > + tree name; > + FOR_EACH_SSA_NAME (i, name, DECL_STRUCT_FUNCTION (source->decl)) > + { > + /* We need to either merge or reset SSA_NAME_*_INFO. > + For merging we don't preserve the mapping between > + original and alias SSA_NAMEs from successful equals > + calls. */ > + if (POINTER_TYPE_P (TREE_TYPE (name))) > + { > + if (SSA_NAME_PTR_INFO (name)) > + { > + gcc_checking_assert (!flag_wpa); > + SSA_NAME_PTR_INFO (name) = NULL; > + } > + } > + else if (SSA_NAME_RANGE_INFO (name)) > + { > + gcc_checking_assert (!flag_wpa); > + SSA_NAME_RANGE_INFO (name) = NULL; > + } > + } > + } > } > > if (!m_merged_variables.is_empty ()) > --- gcc/testsuite/gcc.dg/pr113907.c.jj 2024-02-14 16:13:48.486555159 > +0100 > +++ gcc/testsuite/gcc.dg/pr113907.c 2024-02-14 16:13:29.198825045 +0100 > @@ -0,0 +1,49 @@ > +/* PR middle-end/113907 */ > +/* { dg-do run } */ > +/* { dg-options "-O2" } */ > +/* { dg-additional-options "-minline-all-stringops" { target i?86-*-* > x86_64-*-* } } */ > + > +static inline int > +foo (int len, void *indata, void *outdata) > +{ > + if (len < 0 || (len & 7) != 0) > + return 0; > + if (len != 0 && indata != outdata) > + __builtin_memcpy (outdata, indata, len); > + return len; > +} > + > +static inline int > +bar (int len, void *indata, void *outdata) > +{ > + if (len < 0 || (len & 1) != 0) > + return 0; > + if (len != 0 && indata != outdata) > + __builtin_memcpy (outdata, indata, len); > + return len; > +} > + > +int (*volatile p1) (int, void *, void *) = foo; > +int (*volatile p2) (int, void *, void *) = bar; > + > +__attribute__((noipa)) int > +baz (int len, void *indata, void *outdata) > +{ > + if ((len & 6) != 0) > + bar (len, indata, outdata); > + else > + foo (len, indata, outdata); > +} > + > +struct S { char buf[64]; } s __attribute__((aligned (8))); > + > +int > +main () > +{ > + for (int i = 0; i < 64; ++i) > + s.buf[i] = ' ' + i; > + p2 (2, s.buf, s.buf + 33); > + for (int i = 0; i < 64; ++i) > + if (s.buf[i] != ' ' + ((i >= 33 && i < 35) ? i - 33 : i)) > + __builtin_abort (); > +} Jakub