[LLVMdev] Rotated loop identification
Andrew Trick
atrick at apple.com
Fri Feb 8 11:52:35 PST 2013
On Feb 8, 2013, at 12:49 AM, Michele Scandale <michele.scandale at gmail.com> wrote:
> On 02/08/2013 06:56 AM, Andrew Trick wrote:
>> There's been talk of adding metata do the branch that terminates the loop latch block. What llvm calls the "latch" is just a unique backward branch to the loop header and not necessarilly even a loop exit.
>>
>> I'm not sure how you would interpret that metadata, since the branch exit may be rewritten (just like the loop guard). For example, the indvars pass may convert it into a != test.
>>
>> As long as this is brainstorming time, I actually like the idea of an llvm.invariant intrinsic that the optimizers know to ignore. I like it for other purposes, but would happen to work for you as a temporary workaround. It could take one or two IR values (as metadata operands) and a metadata language describing the invariant, such as a relational operator and optional constant. In your case, you want to know that the loop counter's starting value is less than its limit, so you could conveniently plop one of those in the loop preheader. The invariant would only go away if no one else used the value, which in your case would make sense (e.g. if the loop test were rewritten in terms of %b, you probably wouldn't need the invariant any more).
>>
>> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121210/158601.html
>>
>
> I read the post you suggested. If I understood correctly the idea I like it very much. Just to better understand, when you say <<< It would be generally useful to model an intrinsic that is free and not a strong use but does have control dependence. That's what I call a meta-intrinsic. >>> you mean that this class of intrinsics cannot be removed because they have no uses and the can't be moved freely, e.g. hoisted from a loop?
> Indeed, if they handle a value (they are users), that value would never be eliminated if the only user is the meta-intrinsic itself? Maybe this kind of behaviour must be a parameter respect to the semantic you need to implement (At the end, if the intrinsic is the only user and during lowering is simply eliminated all the values used can be checked to be dead and deleted in that case).
The value used by the intrinsic would be naturally eliminated as dead code if its only users were meta-intrinsics. It's just metadata that happens to be associated with some position in the control flow graph other than the value's definition. So in that sense it would not be a great solution for attaching metadata to a basic block independent of a value. For that, you probably want metadata directly on the block's terminator.
> IMHO this is like a property that an intrinsic can have or not and the proposed llvm.invariant intrinsic is a particular intrinsic that has this property and whose semantic is to describe invariant facts (the metadata language you mentioned).
Yes, I agree. I mainly want a uniform approach for the optimizer. Currently we have a various ad-hoc approaches.
-Andy
More information about the llvm-dev
mailing list