Hello,
I'm writing a new function pass, and I'm having trouble with getTripCount() in Loop. If I generate the bitcode for the test code with no optimization then getTripCount() returns NULL, but if I pass -O3 to the front-end then getTripCount() returns fine. My phase calls addRequiredID(LoopSimplifyID) from getAnalysisUsage() and I also tried putting -mem2reg at the front of the arguments to opt as advised in
bug 2253 (http://llvm.org/bugs/show_bug.cgi?id=2253), but it still behaves the same.
Am I missing something, or is there a bug associated with getTripCount() ?
thanks,
Anthony
Anthony Danalis wrote:
Hello,
I'm writing a new function pass, and I'm having trouble with getTripCount() in Loop. If I generate the bitcode for the test code with no optimization then getTripCount() returns NULL, but if I pass - O3 to the front-end then getTripCount() returns fine. My phase calls addRequiredID(LoopSimplifyID) from getAnalysisUsage() and I also tried putting -mem2reg at the front of the arguments to opt as advised in
bug 2253 (2253 – loop unroll crashes on example with -unroll-count=2), but it still behaves the same.
Am I missing something, or is there a bug associated with getTripCount() ?
getTripCount relies on there being a simple equality test for loop exit. LoopSimplify might not be enough to guarantee that, try -indvars before your pass. (And if that doesn't work, also try -loop-rotate.)
What indvars does is get the trip count the expensive way, by calling into ScalarEvolution, and if possible rewrite the loop in a manner that is trivial and can be picked up by LoopInfo::getTripCount().
There's nothing stopping you from calling into scalar evolutions directly, if for whatever reason you want to be able to analyze loops in otherwise unoptimized code.
Nick