[LLVMdev] Get the loop trip count variable

Eli Friedman eli.friedman at gmail.com
Tue Apr 6 12:41:35 PDT 2010


On Tue, Apr 6, 2010 at 10:47 AM, Zheng Wang <jason.wangz at gmail.com> wrote:
> Sorry, I could not the the loop trip count with getTripCount(). I used
> a simple program as a test case:
>
> ------------------------------------------------------
> #include <stdio.h>
> int getV(int i)
> {
>        return i * 2;
> }
> int main()
> {
>        int num = 10;
>        int sum=0;
>        int i;
>
>        for (i=0; i<num; i++)
>        {
>                sum += getV(i);
>        }
>        return 0;
> }
> --------------------------------------------------------
>
> 2. Then, I translated it to LLVM bitcode by:
>
> llvm-gcc -emit-llvm -c test.c
>
> 3. Then, I performed some optimization passes as:
>
> opt  -loop-rotate -loops -loopvr -indvars -loopsimplify -f < test.o > n.o

You're likely to get bad results if you don't run mem2reg.

-Eli




More information about the llvm-dev mailing list