Loop optimisation with identical counters

Roman Leshchinskiy rl at cse.unsw.edu.au
Fri Nov 5 20:55:14 EDT 2010

On 06/11/2010, at 00:28, David Peixotto wrote:

> Yes, the LLVM code has Sp, Hp, Base all annotated as noalias. I believe that Sp, Hp, and Base should never alias, but a (boxed) R1 should always alias with either Sp or Hp. I had a hard time determining exactly how LLVM uses the noalias annotation, but playing with opt -print-alias-sets I saw that Sp was a MayAlias with the pointers derived from R1. I would guess that casting an int to a pointer (like we do for R1) makes that pointer MayAlias with everything regardless of the noalias annotation.

Are you sure about R1 aliasing Sp? AFAIK, R1 points to a closure on the heap, not to a stack location. That is, it can alias pointers on the stack or Hp but it can't alias the Sp itself. I don't think Sp can be aliased by anything outside of the garbage collector.

Perhaps we shouldn't mark Hp as noalias, though.

>> But shouldn't it just promote stack locations to registers?
> Yes, LLVM can and will promote the stack locations to registers, but since it doesn't know that Sp is really a stack, it is difficult for it to tell when it can avoid the writes back to the stack even though *we* know they will not be visible once the function call returns.

Right, I meant GHC stack locations. Let me rephrase my question: shouldn't it just promote array locations to registers?

> It may profitable to write our own alias analysis pass for LLVM that encodes our knowledge of what can alias in the GHC world view. It wouldn't be useful for other LLVM clients, but might be a good option for us.

Actually, I think our aliasing properties should be fairly close to those of, say, Java. I wonder how LLVM deals with those.

> Yeah, I'm generally very impressed with what LLVM is able to do with the code from GHC. Any help we can give it will just make it that much better!

I have to say I'm slightly disappointed with what LLVM does with tight loops generated by GHC. That's not necessarily LLVM's fault, you are quite right that we should probably give it more information.


More information about the Glasgow-haskell-users mailing list