[LLVMdev] noalias locals

Kenneth Uildriks kennethuil at gmail.com
Sun Nov 14 08:17:53 PST 2010


Right now, I don't see any way to declare that a pointer value within
a function does not alias any pointer not based on it.  Basically, I
would like to be able to apply "noalias" to an instruction/virtual reg
the same way that noalias is applied to function arguments.

A few weeks ago when discussing devirtualization possibilities in C++,
it turned out that while you can assume that the vtbl pointer is the
same for every use of a given object pointer, you cannot assume that
the vtbl pointer is the same for every pointer that MustAlias's that
object pointer.  This means that, without the ability to apply
"noalias" to the result of placement-new, we cannot simply declare
vtbl pointers to be invariant... that would lead the optimizer to
assume that the vtbl pointer accessed through the placement-new'd
pointer must be the same as the vtbl pointer accessed through a
pointer to an object previously allocated in that same memory
location, which is not required to be the case.

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.

To implement it, we can either declare a no-op intrinsic that simply
transfers the value while preventing AliasAnalysis from looking
through it, or we can introduce a new attribute and teach alias
analysis to recognize it.  The first one requires small changes to
codegen, while the second one would require changes to every alias
analysis (I don't think the default AA is called unless all AA's
chained to it return MayAlias) in order to stop them from returning
MustAlias on annotated values and force them to return NoAlias
instead.



More information about the llvm-dev mailing list