Strenghten assumption about dynamic type changes (placement new)

Jan Hubicka hubicka@ucw.cz
Thu Jul 24 09:38:00 GMT 2014


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

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



More information about the Gcc-patches mailing list