[LLVMdev] Pointer aliasing

Dan Gohman gohman at apple.com
Tue Jan 24 11:52:59 PST 2012


On Jan 24, 2012, at 7:45 AM, Brent Walker wrote:

> Can you explain please why it works for this version of the function:
> 
> double f(double *__restrict__ x, double *__restrict__ y, double
> *__restrict__ z);
> 
> What is different here?  There are stores here as well.

LLVM ignores restrict everywhere except function parameters. This is a
compromise aimed at a sweet spot in the balance of compiler complexity
vs. optimization opportunity.

 - Many analysis and optimization techniques naturally apply to whole
   functions. When restrict appears on a local variable inside a
   function, its special aliasing property applies to only a subset of
   the function. It's awkward to teach such code to understand and
   respect local scope boundaries, in general.

 - Function boundaries are often the boundaries of analysis.
   Interprocedural analysis can be expensive and complex, so many
   optimization passes are limited to thinking about one function
   at a time. And even interprocedural analysis passes are
   bounded by shared library boundaries. While local variables can
   often be analyzed automatically (as in your first example),
   function paramters are often incoming mystery values, so they
   are where restrict is most often interesting.

This compromise does mean that some opportunities are lost (as in
your second example), but from clang's perspective these cases are
rare.

Dan




More information about the llvm-dev mailing list