[LLVMdev] Strange pointer aliasing behaviour

Pierre C lists at peufeu.com
Thu Jun 17 11:40:34 PDT 2010

> Exactly. To elaborate on my probably-too-curt initial response, I  
> believe that optimizations should not be constrained by non-comformant  
> code.

The example I chose (LittleList class) was not really innocent : this kind  
of initialization in a constructor is quite common. Suppose we have a  
class for short vectors (there is one in LLVM), in this case we expect the  
compiler to "do the right thing", when the length is a known constant that  
means inline the constructor, unroll the loop, and basically turn it into  
something that looks like an intrinsic memset(). Doesn't happen because of  
the aliasing... GCC figures it out though.

> helping people find and fix these issues. Tracking down a bug like that  
> in user code is an absolute nightmare. Specifically, we should issue  
> good diagnostics for problems of this sort, from the compiler and/or  
> from the static analyzer, whenever possible.

Warnings are useful.

Note that if in a struct { int32 length, double data[10] } "data[x]" can  
alias "length", why can't it alias the rest of the stack, or even the  
entire memory space ? If the compiler supposes that out of bounds accesses  
are "legal" on data[x] we might as well deactivate alias analysis for the  
whole program...

It would also be cool to be able to tell the compiler that 2 pointers  
don't alias (or that they do). __restrict only works on function arguments  
which makes it a lot less useful...

More information about the llvm-dev mailing list