getSmallConstantTripCount problem

In my pass, I add LoopInfo as a required pass. Then I’d like to print the constant loop trip count of each loop if it has one. However, every time I call loop->
getSmallConstantTripCount(), it returns 0, even for a very simple loop: for(i=0; i<3; ++i) {;} What’s the possible cause of this problem?

regards,
Bo

Hi Bo,

In my pass, I add LoopInfo as a required pass. Then I'd like to print the
constant loop trip count of each loop if it has one. However, every time I call
loop->
getSmallConstantTripCount(), it returns 0, even for a very simple loop: for(i=0;
i<3; ++i) {;} What's the possible cause of this problem?

this comes up regularly, so search the mailing list archives. IIRC, you need to
run some other passes first: mem2reg and probably some others I forget.

Ciao, Duncan.

Did you run the IndVarSimplify pass? For things like canonical
inductive variables and trip counts, LoopInfo seems to rely on the
loop already being in a canonical form presented by passes such as
IndVarSimplify. You'll also want to make sure not to do something like
StrengthReduction which will invalidate the canonicalization done by
IndVarSimplify until you're done with the LoopInfo analysis.