This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Strenghten assumption about dynamic type changes (placement new)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: Jason Merrill <jason at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 24 Jul 2014 11:53:23 +0200
- Subject: Re: Strenghten assumption about dynamic type changes (placement new)
- Authentication-results: sourceware.org; auth=none
- References: <20140719154408 dot GA8665 at kam dot mff dot cuni dot cz> <CAFiYyc0hDA+9G+wBVkf8Gif8vsDdpvyf4r3X8P=7G-P=QaWwqQ at mail dot gmail dot com> <20140722135434 dot GA12329 at kam dot mff dot cuni dot cz> <CAFiYyc37YkpYFGX2WJ14BUyEQ5k6ggvLrntsemtMEmat+6RgXA at mail dot gmail dot com> <20140722151720 dot GA25121 at kam dot mff dot cuni dot cz> <CAFiYyc0o5mRFF3V_nFBX5+TSDNKT9=BfqoUj6xN=gaNiY+UJuA at mail dot gmail dot com> <20140723144222 dot GA23992 at kam dot mff dot cuni dot cz> <3aa8219d-8bde-4a69-afbd-97bf15396bf2 at email dot android dot com> <20140723162951 dot GA28234 at kam dot mff dot cuni dot cz> <CAFiYyc1FSAEsr7=OJMXVnHSPU9JaPgPEksEHNizknwWs2xvOAw at mail dot gmail dot com> <20140724092304 dot GA6797 at kam dot mff dot cuni dot cz>
On Thu, Jul 24, 2014 at 11:23 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> > *shortptr = exp
>> > <longer dependency chain with shortptr>
>> > var = *shortptr
>> > *intptr = exp
>> > <longer dependency chain with intptr>
>> > var = *intptr
>>
>> Yes (that is, you can't hoist the *intptr = exp store above the var = *shortptr
>> load with TBAA only). You can probably still hoist the <longer dependency
>> chain with intptr>, it's not clear from your example.
>
> Well, this is placement new version of this, where of course the movement is not desirable.
> Obvioulsy the chains can not overlap:
> #include <new>
> #include <stdio.h>
> struct A {short a; short b; A(){a=1;}};
> struct B {int a; B(){a=2;}};
>
> struct A a;
> struct A *pa = &a;
> struct B *pb = reinterpret_cast<struct B *>(&a);
> int
> main()
> {
> int sum;
> struct A *ppa = pa;
> struct B *ppb = pb;
> if (!pa || !pb)
> return 1;
> ppa->~A();
> new (ppa) A();
> asm ("#asm1":"=m"(ppa->a):"m"(ppa->a));
> sum = ppa->a*11;
> new (ppb) B();
>
> asm ("#asm2":"=m"(ppb->a):"m"(ppb->a));
> sum += ppb->a*11;
> printf ("%i\n",sum);
> return 0;
> }
>
> Of course it makes us i.e. in
> t(short *a, short *b, int *c)
> {
> int i;
> for (i=0;i<1000000;i++)
> c[i]=a[i]+b[i];
> }
>
> generate the fallback case when vectorizing where c is overlapping with a or b, while clang doesn't.
Yep. I bet clang gets it wrong with placement new (but then for
PODs simply writing to a storage location ends lifetime of the old
object in there and starts lifetime of a new object, so placement new
is not needed to make an overlap valid as far as I read the standard(s)).
So I don't think omitting the runtime alias check is valid for the above
case.
Richard.
> Honza
>>
>> That said, being able to optimize union accesses with TBAA at all
>> is still nice (esp. for GCC). Now, the C frontend still forces alias-set zero
>> for this case because of the RTL alias oracle disfunctionality which doesn't
>> treat a must-alias as an alias if it can TBAA disambiguate.
>>
>> Richard.
>>
>> > Honza