[PATCH] Loop Rerolling Pass
Andrew Trick
atrick at apple.com
Thu Oct 17 11:39:18 PDT 2013
On Oct 17, 2013, at 11:33 AM, Hal Finkel <hfinkel at anl.gov> wrote:
> ----- Original Message -----
>>
>>
>>
>> On Oct 17, 2013, at 10:30 AM, Hal Finkel < hfinkel at anl.gov > wrote:
>>
>>
>>
>>
>> If the loop is testing less-than constant ’n’, I think we already
>> handle it (knowing n < INT_MAX-stride). I’m not sure what we do for
>> equals ’n’.
>>
>> No, that does not currently work. Compiling the following with clang:
>>
>> void foo(int n, int *x) {
>> for (int i = 0; i < n; i += 3) {
>> x[i] = i;
>> x[i+1] = i+1;
>> x[i+2] = i+2;
>> }
>> }
>>
>> I find that SE->hasLoopInvariantBackedgeTakenCount(L) returns false.
>> From what you're saying, this sounds like a bug, no?
>>
>> By “constant n” I meant “a constant” ;)
>
> Right, and the constant case works. The variable case does not, and if I understand correctly, this is the 'we ignore the nsw flag' case. If we get to assume that i += 3 does not wrap, then we can positively return a backedge taken count of n/3-1, right?
>
> You had also said that we need to make clear what the number returned means (because we can't actually guarantee that many iterations in the face of functions that might throw, etc.), but I don't see how this interpretation concern is affected by whether or not n is a constant. Are these two issues related?
Ah. When I say the “constant” case is handled, I mean we know that we must take the exit at iteration n/3. For a nonconstant, we may exit at n/3 or may terminate later via a call, exit later via a different loop test, etc. If the client can prove that there’s no other way for the loop to terminate or exit, then it can use n/3 as the trip count.
-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131017/28544e47/attachment.html>
More information about the llvm-commits
mailing list