local restrict - again

Hi, Jeroen,

We should move these conversations to llvm-dev so that they don't get
missed and others can contribute. Can I cc the list?

[+llvm-dev] - Jeroen consented.

There was another thread recently ("alias.scope and local restricted C pointers") where it seemed understood that the present noalias and alias.scope IR was sufficient to model local restrict, but that Clang wasn't making use of it. This thread implies that even if Clang were to make use of it, there would need to be changes in LLVM to help support it. Which is it?

Is the problem perhaps that noalias is presently an attribute of function parameters (as set by CodeGenFunction::EmitFunctionProlog in Clang) and there is no way to attach it to, say, the alloca used to create a local pointer? Thus this proposal of the additional "%rp = llvm.noalias ..."?


Hi Troy,

Some time ago (a few years by now), Hal created a set of patches that, together, provide an implementation of 'local restrict'.
They also contain a fix for the issue when functions with restrict parameters are inlined inside a loop, making it possible to see if the restrictness is
only valid in a single iteration or across iterations. (The llvm.noalias intrinsics (together with the !noalias and !scope metadata) helps with identifying if the restrictness ends inside or outside the loop)

These patches are available here: <Login;
Some of them have been committed to the main llvm, but not all of them.

A number of people that are using all of these patches have found some issues in certain circumstances. One of the bigger problems is, that
some optimization passes optimize away some (but not all) of the llvm.noalias intrinsics in a function. Because of that, the alias analysis can get confused
and can identify two pointers as not-aliasing where they should be aliasing.

In the past llvm conferences, there has been some discussions about possible solutions (like making llvm.noalias opaque), but these have other drawbacks. (worse optimization behavior).


Jeroen Dobbelaere