[LLVMdev] Rotated loop identification

Andrew Trick atrick at apple.com
Wed Feb 6 15:07:42 PST 2013


On Feb 4, 2013, at 10:48 AM, Michele Scandale <michele.scandale at gmail.com> wrote:

> Dear all,
> 
> I'm working on a late IR target dependent optimization on loops. A part of this
> optimization requires to derive "by hand" the trip-count expression of a given
> loop. In order to handle correctly these cases I need to check if the loop has
> an entry guard or not. The problem I have is that starting from the information
> I derive during my analysis (initial IV value, last IV value, comparison kind) I
> don't know how to verify if the entry guard is present or not, mainly because
> algebraic simplifications changed the entry guard comparison. Being able to know
> if a given loop has been rotated would be enough for my purposes but I haven't
> found a way to obtain this.
> 
> I think that the only way is to track in the IR the information, but I don't
> know how to track it in a safe (the information shouldn't be lost) and
> transparent way (it should not interfere with the optimizer). Thinking to custom
> intrinsics I don't understand how to allow memory optimizations and, at the same
> time, prevent the intrinsic elimination or hoisting from the target loop.
> 
> I would appreciate any hint on this topic.

See ScalarEvolution::isLoopEntryGuardedByCond. It's part of the analysis that we use to determine trip count and benefits from rotated loops.

LLVM never annotates the IR with a history of transformations. You could potentially annotate the LoopInfo analysis, but it will only be preserved within the same LoopPassManager (you would have to run right after LoopRotate).

The only robust solution is ScalarEvolution.

-Andy



More information about the llvm-dev mailing list