On Wed, Nov 18, 2026 at 9:41 AM <[email protected]> wrote: > > From: Kyrylo Tkachov <[email protected]> > > pcom_worker::determine_offset places two references in the same chain > when their types satisfy useless_type_conversion_p. On LP64 long and > long long satisfy it but have different alias sets. References created > for a chain (ref_at_iteration) copy the alias info of the chain root. > In the PR a long store and a long long load form one chain, so the > preheader load of the long long location is created as a long access. > With the IPA modref summary of f, which only writes long long, TBAA then > treats the long load as independent of the call f (b) and the value is > read before the call, giving 0 instead of 7. > > Require equal alias sets in determine_offset, in addition to the type > check, so every reference in a chain has the alias info of its root. > > Bootstrapped and tested on aarch64-non-linux-gnu. > Ok for trunk?
I think you should probably use refs_same_for_tbaa_p for the check, possibly in both "directions". At least just comparing get_alias_set () of both is not enough. Richard. > Thanks, > Kyrill > > gcc/ChangeLog: > > PR tree-optimization/128641 > * tree-predcom.cc (pcom_worker::determine_offset): Also require > equal alias sets for the two references. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/128641 > * gcc.dg/torture/pr128641.c: New test. > > Signed-off-by: Kyrylo Tkachov <[email protected]> > --- > gcc/testsuite/gcc.dg/torture/pr128641.c | 27 +++++++++++++++++++++++++ > gcc/tree-predcom.cc | 7 +++++-- > 2 files changed, 32 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/torture/pr128641.c > > diff --git a/gcc/testsuite/gcc.dg/torture/pr128641.c > b/gcc/testsuite/gcc.dg/torture/pr128641.c > new file mode 100644 > index 00000000000..a9370fd7ef5 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/torture/pr128641.c > @@ -0,0 +1,27 @@ > +/* { dg-do run } */ > + > +extern void *malloc (__SIZE_TYPE__); > + > +int n; > + > +__attribute__((noinline)) void > +f (char *p) > +{ > + *(long long *) p = 7; > +} > + > +int > +main (void) > +{ > + char *b = malloc (72); > + f (b); > + long long s = 0; > + for (int k = 0; k < (n & 7) + 1; k++) > + { > + s = s * 31 + *(long long *) (b + k * 8); > + *(long *) (b + 8 + k * 8) = k; > + } > + if (s != 7) > + __builtin_abort (); > + return 0; > +} > diff --git a/gcc/tree-predcom.cc b/gcc/tree-predcom.cc > index a2043ef3122..e2a2b21b8c3 100644 > --- a/gcc/tree-predcom.cc > +++ b/gcc/tree-predcom.cc > @@ -833,10 +833,13 @@ pcom_worker::determine_offset (struct data_reference *a, > aff_tree diff, baseb, step; > tree typea, typeb; > > - /* Check that both the references access the location in the same type. */ > + /* Check that both the references access the location in the same type > + and with the same alias set, since the references created for a chain > + reuse the alias info of the chain root. */ > typea = TREE_TYPE (DR_REF (a)); > typeb = TREE_TYPE (DR_REF (b)); > - if (!useless_type_conversion_p (typeb, typea)) > + if (!useless_type_conversion_p (typeb, typea) > + || get_alias_set (DR_REF (a)) != get_alias_set (DR_REF (b))) > return false; > > /* Check whether the base address and the step of both references is the > -- > 2.54.0 (Apple Git-157) >
