This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: movmem pattern and missed alignment
Hi,
On Mon, 8 Oct 2018, Paul Koning wrote:
> >> extern int *i, *j;
> >> extern int iv[40], jv[40];
> >>
> >> void f1(void)
> >> {
> >> __builtin_memcpy (i, j, 32);
> >> }
> >>
> >> void f2(void)
> >> {
> >> __builtin_memcpy (iv, jv, 32);
> >> }
> >
> > Yes, memcpy doesn't require anything bigger than byte alignment and
> > GCC infers alignemnt
> > only from actual memory references or from declarations (like iv /
> > jv). For i and j there
> > are no dereferences and thus you get alignment of 1.
> >
> > Richard.
>
> Ok, but why is that not a bug? The whole point of passing alignment to
> the movmem pattern is to let it generate code that takes advantage of
> the alignment. So we get a missed optimization.
Only if you somewhere visibly add accesses to *i and *j. Without them you
only have the "accesses" via memcpy, and as Richi says, those don't imply
any alignment requirements. The i and j pointers might validly be char*
pointers in disguise and hence be in fact only 1-aligned. I.e. there's
nothing in your small example program from which GCC can infer that those
two global pointers are in fact 2-aligned.
Ciao,
Michael.