[LLVMdev] getSmallConstantTripCount function doesn't work for obvious cases
Bo Wu
wubousc at gmail.com
Tue Jan 17 18:30:31 PST 2012
Hi,
My pass heavily relies on llvm::Loop's getSmallConstantTripCount method.
However, I found that it doesn't work for some simple cases.
In the following example, I can get the constant trip count of the
outermost loop if statement "a[l] = a[l] + 1" is there. After commenting
out this line, the returned constant trip count for that loop is 0. In my
pass, I traverse the nested loops starting from statement "a[i] = b[i] *
b[i+1]; ", and use a for loop to traverse each parent loop.
void f(int *a, int b[], double *c, int n)
{
int i,j,k,l;
if(n>20)
a[j] = 4;
else {
for(l=0; l<200; ++l) {
a[l] = a[l] + 1; //if remove this line, the above loop's trip count
can not be obtained.
if(b[1]>30) {
c[k] = c[k] * c[k+1];
}
else {
for(k=0; k<400;++k) {
for(i=0; i<400; ++i) {
a[i] = b[i] * b[i+1]; // nested loop traversal starts here.
}
}
}
}
}
}
As long as statement "a[l] = a[l] + 1;" is in the outermost loop body, the
trip count can be obtained. Is there a way to get the constant trip count
of a loop in similar cases, even if the induction variable is not used in
the loop body?
Thanks,
Bo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120117/ee7fbdd6/attachment.html>
More information about the llvm-dev
mailing list