On Thu, Jul 24, 2014 at 11:53 AM, Richard Biener
<richard.guent...@gmail.com> wrote:
> On Thu, Jul 24, 2014 at 11:23 AM, Jan Hubicka <hubi...@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.

Btw, we don't create a runtime test here.  The argument is as simple
as overlap may only happen during iteration 0, otherwise you have
an invalid read via short of sth stored via int.

Thus if you are in loops you are usually fine to use TBAA.

Richard.

> 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

Reply via email to