[LLVMdev] noalias locals

Reid Kleckner reid.kleckner at gmail.com
Sun Nov 14 09:45:49 PST 2010

On Sun, Nov 14, 2010 at 11:17 AM, Kenneth Uildriks <kennethuil at gmail.com> wrote:
> To fix that and compile C++ correctly while aggressively
> devirtualizing it, we would need to apply "noalias" to the result of
> placement-new in all cases, even when placement-new is inlined.  More
> generally, when inlining any function with a "noalias" return, the
> inlined result needs to have "noalias" applied to it.

Is that the right way to go?  It seems like that might cause other
optimizers to introduce invalid transformations.  For example, if the
instruction scheduler knows that those pointers don't alias, it might
reschedule a store to the memory after the constructor call from the
placement new.

struct Foo {
  int a;
  Foo(int a) : a(a) {}

int main(void) {
  Foo f;
  f.a = 1;
  Foo *p = new (&f) Foo(2);
  // what does p->a contain?  1 or 2?

There's a lot of problems with this example, but I don't know enough
optimizer details to construct a better one.

Can you get by with a MayAlias?  It seems like you can divirtualize
everything that MustAlias and ignore the rest.

If I understood the last discussion on this, the reason you don't need
to worry about placement new getting called within callees is that you
have to use the pointer returned by placement new, or you get
undefined behavior, so you can safely assume the vptr is immutable.


More information about the llvm-dev mailing list