getTripCount and pointers

Hello,

I'm having some trouble with getTripCount() ... again. In particular it fails in the first of the following two examples, although it works for the second. By fails, I mean it returns NULL.

---------- example 1 ----------
test1(int *a, const int *ip) {
   int k;

   for (k = 0; k < ip[2]; ++k) {
         a[k] = (k+11)/(k+2);
   }
}

---------- example 2 ----------
test2(int *a) {
   int k, ip[4];

   vbar(ip, 4, 7);

   for (k = 0; k < ip[2]; ++k) {
         a[k] = (k+11)/(k+2);
   }
}

However, in both cases the trip count is the same and equally undecidable, since "vbar()" is an external function.

Note that in each example that is the only code in the file and I am running my pass as:
opt -O1 -licm -load ... -mypass < test.bc > /dev/null

Any suggestions?

thanks,
Anthony

I'm having some trouble with getTripCount() ... again. In particular
it fails in the first of the following two examples, although it works
for the second. By fails, I mean it returns NULL.

The main difference between the two cases below is that in case 1, LLVM can't prove that "a" and "ip" don't alias (the fact that ip is a "const int*" doesn't help, since that only tells the compiler to not allow writing to ip's contents directly, not that the contents of ip remain constant). In case 2, ip points to the local stack, and therefore "a" can't possibly alias it.

So, in case 1, the write to a[k] inside the loop might actually modify ip[2], and thus the loop bound is not loop-invariant.

Stefanus