Hi Christopher, On Friday 17 August 2007 19:42:31 Christopher Lamb wrote:> On Aug 16, 2007, at 9:09 AM, Chris Lattner wrote: > > On Thu, 16 Aug 2007, Holger Schurig wrote: > >>> if the programmer is going to tell you that the memory pointed > >>> to by a pointer argument is never written. > > If you use a const * __restrict pointer then you should get the > benefit of this as the alias analysis will assume that the pointed to > object is neither aliased nor written.can you please explain more about what restrict means: it may help in improving code quality for Ada. In Ada you have runtime constants that are really constant, for example array bounds. The bounds are passed around by pointer, which causes LLVM to think they may be aliased and changed by function calls (which is impossible). This results on rotten code since (for example) the array length and bounds checks are recalculated again and again when one calculation would do. [The front-end outputs a bound check for every array access, expecting the optimizers to remove redundant checks, which LLVM often does not do]. If I could teach LLVM that array bounds are really constant that would presumably solve the problem. Thanks, Duncan.
On 2007-08-19, at 15:41, Duncan Sands wrote:> can you please explain more about what restrict means: it may help > in improving code quality for Ada. In Ada you have runtime > constants that are really constant, for example array bounds. The > bounds are passed around by pointer, which causes LLVM to think > they may be aliased and changed by function calls (which is > impossible). This results on rotten code since (for example) the > array length and bounds checks are recalculated again and again > when one calculation would do. [The front-end outputs a bound > check for every array access, expecting the optimizers to remove > redundant checks, which LLVM often does not do]. If I could teach > LLVM that array bounds are really constant that would presumably > solve the problem.Here's a thread about it: lists.cs.uiuc.edu/pipermail/llvmdev/2007-March/thread.html#8291 I don't think anything has been implemented. — Gordon -------------- next part -------------- An HTML attachment was scrubbed... URL: <lists.llvm.org/pipermail/llvm-dev/attachments/20070819/9f106447/attachment.html>
On Aug 19, 2007, at 1:15 PM, Gordon Henriksen wrote:> On 2007-08-19, at 15:41, Duncan Sands wrote: > >> can you please explain more about what restrict means: it may help >> in improving code quality for Ada. In Ada you have runtime >> constants that are really constant, for example array bounds. The >> bounds are passed around by pointer, which causes LLVM to think >> they may be aliased and changed by function calls (which is >> impossible). This results on rotten code since (for example) the >> array length and bounds checks are recalculated again and again >> when one calculation would do. [The front-end outputs a bound >> check for every array access, expecting the optimizers to remove >> redundant checks, which LLVM often does not do]. If I could teach >> LLVM that array bounds are really constant that would presumably >> solve the problem.The benefits of a const * __restrict come from two different places. The const part is essentially enforced by the front-end and the restrict part is used to inform the alias analysis (it becomes a noalias parameter attribute). The noalias parameter attribute may be of use to you eventually, but full noalias implementation isn't yet complete. Specifically the case where a function with noalias parameter attributes is inlined does not currently preserve the noalias information.> Here's a thread about it: > > lists.cs.uiuc.edu/pipermail/llvmdev/2007-March/thread.html#8291You should also take a look at PR 1373, as that is where progress is being tracked. llvm.org/bugs/show_bug.cgi?id=1373> I don't think anything has been implemented.Per the discussion and PR there has been work done to implement the 'noalias' parameter attribute in LLVM, and currently BasicAA will use this attribute to inform alias queries that are made. There has also been work to map __restrict C/C++ pointer and reference parameters onto the noalias parameter attribute. There is still much work to be done to fully implement noalias in LLVM, notably the intrinsic and updates to tolerate/use it, as well as to fully support all uses of the __restrict qualifier in the C/C++ front end. -- Christopher Lamb -------------- next part -------------- An HTML attachment was scrubbed... URL: <lists.llvm.org/pipermail/llvm-dev/attachments/20070819/03241375/attachment.html>