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. 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