problem with loopinfo

hi,
The loopinfo pass failed to recognize the Tripcount of a simple program constructed by me, can you help me to figure out why this happened? Thanks.
The C program and corresponding .ll files are shown below. I used llvm1.7 to develop my own pass, and want to use the loop information.
-Wei

Test.c:
#include “stdio.h”
#define N 40
void func1() {
int a[N];
int i,j;
for (i=0; i<N; i++) {
if (i==0)
a[i] = iN;
else
a[i] = i
i;
}
}

Test.ll:
void %func1() {
entry:
%a = alloca [40 x int] ; <[40 x int]*> [#uses=1]
br label %no_exit

no_exit: ; preds = %else, %then, %entry
%i.0.0 = phi int [ 0, %entry ], [ %inc9, %then ], [ %inc, %else ] ; [#uses=7]
%tmp.4 = seteq int %i.0.0, 0 ; [#uses=1]
%tmp.7 = getelementptr [40 x int]* %a, int 0, int %i.0.0 ; <int*> [#uses=2]
br bool %tmp.4, label %then, label %else

then: ; preds = %no_exit
%tmp.9 = mul int %i.0.0, 40 ; [#uses=1]
store int %tmp.9, int* %tmp.7
%inc9 = add int %i.0.0, 1 ; [#uses=2]
%tmp.112 = setlt int %inc9, 40 ; [#uses=1]
br bool %tmp.112, label %no_exit, label %return

else: ; preds = %no_exit
%tmp.14 = mul int %i.0.0, %i.0.0 ; [#uses=1]
store int %tmp.14, int* %tmp.7
%inc = add int %i.0.0, 1 ; [#uses=2]
%tmp.1 = setlt int %inc, 40 ; [#uses=1]
br bool %tmp.1, label %no_exit, label %return

return: ; preds = %else, %then
ret void
}

hi,
   The loopinfo pass failed to recognize the Tripcount of a simple program constructed by me, can you help me to figure out why this happened? Thanks.
   The C program and corresponding .ll files are shown below. I used llvm1.7 to develop my own pass, and want to use the loop information.

What passes are you running before your pass? trip count information is generally only available after the "indvars" pass runs.

-Chris

Test.c:
#include "stdio.h"
#define N 40
void func1() {
int a[N];
int i,j;
for (i=0; i<N; i++) {
     if (i==0)
       a[i] = i*N;
     else
       a[i] = i*i;
}
}

Test.ll:
void %func1() {
entry:
       %a = alloca [40 x int] ; <[40 x int]*> [#uses=1]
       br label %no_exit

no_exit: ; preds = %else, %then, %entry
       %i.0.0 = phi int [ 0, %entry ], [ %inc9, %then ], [ %inc, %else ] ; <int> [#uses=7]
       %tmp.4 = seteq int %i.0.0, 0 ; <bool> [#uses=1]
       %tmp.7 = getelementptr [40 x int]* %a, int 0, int %i.0.0 ; <int*> [#uses=2]
       br bool %tmp.4, label %then, label %else

then: ; preds = %no_exit
       %tmp.9 = mul int %i.0.0, 40 ; <int> [#uses=1]
       store int %tmp.9, int* %tmp.7
       %inc9 = add int %i.0.0, 1 ; <int> [#uses=2]
       %tmp.112 = setlt int %inc9, 40 ; <bool> [#uses=1]
       br bool %tmp.112, label %no_exit, label %return

else: ; preds = %no_exit
       %tmp.14 = mul int %i.0.0, %i.0.0 ; <int> [#uses=1]
       store int %tmp.14, int* %tmp.7
       %inc = add int %i.0.0, 1 ; <int> [#uses=2]
       %tmp.1 = setlt int %inc, 40 ; <bool> [#uses=1]
       br bool %tmp.1, label %no_exit, label %return

return: ; preds = %else, %then
       ret void
}

-Chris

I did run the indvars pass, but it seemed that it didn't work.
-Wei

I did run the indvars pass, but it seemed that it didn't work.

Then you'll have to trace through and find out why it's failing...

-Chris

I will. I am working on another part currently, so if somebody have encountered the same problem before or know how to solve it, please let me know. Thanks.
-Wei