On Sun, 25 Oct 2026, Andrea Pinski wrote:
> On Sat, Oct 24, 2026 at 3:49 AM Andrew Pinski <[email protected]> wrote:
> >
> >
> >
> > On Sat, Oct 24, 2026, 12:25 AM Philipp Tomsich <[email protected]>
> > wrote:
> >>
> >> Andrea,
> >>
> >> On Sat, 24 Oct 2026 at 11:10, Andrea Pinski
> >> <[email protected]> wrote:
> >> >
> >> > So thinking about this a little more, this seems like this could be
> >> > done in SRA. The heuristics there should be able to handle this case
> >> > better than adding a whole thing to forwprop. I don't know if SRA is
> >> > able to handle that but it does seems like it handles all of the BFRs
> >> > in a reasonable fashion. And even decides if where the loads and/or
> >> > stores should be split up.
> >> > Have you thought of improving SRA to handle this?
> >>
> >> We originally looked at that, but I don’t think SRA can handle this case.
> >>
> >> SRA only considers aggregate-typed local variables and by-value
> >> parameters, and it ignores accesses through pointers:
> >> build_access_from_expr_1 returns NULL for a MEM_REF whose base is not
> >> an ADDR_EXPR. In the motivating case there is no aggregate.
> >
> >
> >
> > Yes but the interger ssa name here is basically an aggregate as it is doing
> > extractions and insertions on it. That is my point you have to extend sra
> > to treat that as an aggregate. It is definitely much harder than the patch
> > you came up with but the heuristics of when to split up the "copies"
> > (load/stores) is exists already.
>
>
> I just noticed a related SRA patch which handles part of this here:
> https://inbox.sourceware.org/gcc-patches/[email protected]/
>
> This is similar to what I mentioned about memcpy handling inside SRA.
> I am not saying it is a complete solution for what you are seeing but
> it is a start which you should look into.
Only replying at the end of this long thread (sorry). From the
original description it seems you are looking at what optimize_vector_load
already does. And yes, having SRA analysis, even if just to drive
heuristics, would be good - ISTR the "expand SRA" patches attempt to
split out the analysis phase to some extent so it can be used on
pointers. The memcpy work still only scalarizes local aggregates, so
not cases the last snippet show.
That said, the patch seems overly large which hints at that it is not
suitable for forwprop and better fit in some other code transform.
If the issue is the vectorizer cannot handle something, why not extend it?
Can you open a PR with the _actual_ testcase you are trying to optimize?
Thanks,
Richard.
> Thanks,
> Andrea
>
> >
> >
> >> in and out
> >> point into the caller’s pixel buffers, and by the lower pass the
> >> memcpy is already a uint128_t load and store through them:
> >> _25 = MEM <uint128_t> [(char * {ref-all})in];
> >> MEM <uint128_t> [(char * {ref-all})out] = _25;
> >>
> >> For the reduced kernel below (trunk, -Ofast -mcpu=neoverse-n1), both
> >> esra and sra find no candidates and reject every decl as “not
> >> aggregate”. The loop then fails with “no vectype for stmt: _19 = MEM
> >> <uint128_t> [in_42]”.
> >>
> >> #include <cmath>
> >> #include <cstring>
> >>
> >> struct R {
> >> float m_base[3];
> >> float m_log2_base;
> >> void apply (const void *inImg, void *outImg, long n) const;
> >> };
> >>
> >> void R::apply (const void *inImg, void *outImg, long n) const
> >> {
> >> const float *in = (const float *) inImg;
> >> float *out = (float *) outImg;
> >> for (long i = 0; i < n; ++i)
> >> {
> >> const float alphares = in[3];
> >> std::memcpy (out, in, 16);
> >> out[0] = exp2f (out[0] * m_log2_base) * m_base[0];
> >> out[1] = exp2f (out[1] * m_log2_base) * m_base[1];
> >> out[2] = exp2f (out[2] * m_log2_base) * m_base[2];
> >> out[3] = alphares;
> >> in += 4; out += 4;
> >> }
> >> }
> >>
> >> Extending SRA to memory behind pointers would give up that it sees
> >> every access to a candidate: in this particular loop, the pointer
> >> 'out' may alias this. That is why the copy store survives until
> >> vectorization: m_log2_base is loaded after the copy and may read any
> >> of its 16 bytes.
> >>
> >> Also: the memcpy fold can’t pick a better type either. It sees only
> >> char * operands, so uint128_t is all it has.
> >>
> >> Thanks,
> >> Philipp
>
--
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri; (HRB 36809, AG Nuernberg)