This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC, PR 80689] Copy small aggregates element-wise
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Jambor <mjambor at suse dot cz>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Jan Hubicka <hubicka at ucw dot cz>, Michael Matz <matz at suse dot de>
- Date: Thu, 23 Nov 2017 16:50:09 +0100
- Subject: Re: [RFC, PR 80689] Copy small aggregates element-wise
- Authentication-results: sourceware.org; auth=none
- References: <CAFiYyc3xY8+NQCRPRgKScN+bKtWPnFuJMF6xJC1PwE7=nbKOuA@mail.gmail.com> <CAFiYyc3sv-_fherea2JEKUMp47A9u360oOQL2TaMXo=4TQNiAA@mail.gmail.com> <20171103163830.hfisosan5zcfow5j@virgil.suse.cz> <CAFiYyc3O44aAw3pu9EKZ0T-r+r3+TYc61v_MonjfxPqzWcEwmg@mail.gmail.com> <ri660a1ggdg.fsf@suse.cz>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Nov 23, 2017 at 04:32:43PM +0100, Martin Jambor wrote:
> > struct A { short s; long i; long j; };
> > struct A a, b;
> > void foo ()
> > {
> > struct A c;
> > __builtin_memcpy (&c, &b, sizeof (struct A));
> > __builtin_memcpy (&a, &c, sizeof (struct A));
> > }
> > int main()
> > {
> > __builtin_memset (&b, 0, sizeof (struct A));
> > b.s = 1;
> > __builtin_memcpy ((char *)&b+2, &b, 2);
> > foo ();
> > __builtin_memcpy (&a, (char *)&a+2, 2);
> > if (a.s != 1)
> > __builtin_abort ();
> > return 0;
> > }
Note the testcase would need to be guarded with sizeof (short) == 2
and offsetof (struct A, i) >= 4.
> Thanks for the testcase, I agree that is a fairly big problem. Do you
> think that the following (untested) patch is an appropriate way of
> fixing it and generally of extending gimple to capture that a statement
> is a bit-copy?
Can you bail out just if the type contains any padding? If there is no
padding, then perhaps SRA still might do its stuff (though, e.g. if it
contains bitfields, we'd need to hope store-merging merges it all back
again).
Jakub