getTripCount requires which optimization passes?

Hi,

For me, getTripCount always returns null, even for trivial loops such as:

void simple(int j) {
     for (int i = 0; i < 10; i++) {
         j++;
     }
}

Looking through the mailing list archive, it appears that getTripCount requires certain optimization passes to run first, but it's not clear which ones. There doesn't seem to be any documentation on this. Does anybody know exactly which passes must run in order for getTripCount to work?

Thanks,

Trevor

hi,

Hi,

For me, getTripCount always returns null, even for trivial loops such
as:

void simple(int j) {
for (int i = 0; i < 10; i++) {
j++;
}
}

Looking through the mailing list archive, it appears that getTripCount
requires certain optimization passes to run first, but it’s not clear
which ones. There doesn’t seem to be any documentation on this. Does
anybody know exactly which passes must run in order for getTripCount
to work?

As the comment said:
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.

you could try -indvars.

Thanks,

Trevor


LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

best regards
ether

After adding -indvars to the opt command, getTripCount still returns null.

I suppose it's possible, depending on the scheduling of the pass manager, that indvars is running after my pass runs. I could force it to run first by adding it to my pass's getAnalysisUsage:

void MyPass::getAnalysisUsage(AnalysisUsage &AU) const {
     AU.addRequired<IndVarSimplify>();
}

But this isn't possible because for some reason there's no IndVarSimplify.h header file. The IndVarSimplify pass is defined only in its IndVarSimplify.cpp, so my pass can't use it.

Not sure where to go from here. Should I post a test case illustrating the problem?

Trevor

As the comment said:
/// The IndVarSimplify pass transforms loops to have a form that
this
/// function easily understands.

you could try -indvars.

After adding -indvars to the opt command, getTripCount still returns
null.

Code coming from C front-ends typically also needs -loop-rotate, in
addition to all the usual stuff (mem2reg, instcombine, simplifycfg, etc).
It depends a fair amount on the front-end; take a look at what opt -O2
does and experiment with it.

I suppose it's possible, depending on the scheduling of the pass
manager, that indvars is running after my pass runs. I could force it
to run first by adding it to my pass's getAnalysisUsage:

void MyPass::getAnalysisUsage(AnalysisUsage &AU) const {
    AU.addRequired<IndVarSimplify>();
}

But this isn't possible because for some reason there's no
IndVarSimplify.h header file. The IndVarSimplify pass is defined only
in its IndVarSimplify.cpp, so my pass can't use it.

The design idea here is that you should write your pass to be
conservatively correct in the case that indvars and whatever else
hasn't run, and then just make your front-ends add -indvars before
adding your pass.

Dan

Sorry, I don't have a clue how to do this, and I can't find any docs about it. I'm using llvm-gcc; how can I tell it to add a pass?

Trevor

llvm-gcc uses include/llvm/Support/StandardPasses.h. It already
includes indvars and others.

Dan