开发者

The use of getSmallConstantTripCount method of Loop in LLVM

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 called getSmallConstantTripCount, it returns 0, even for a very simple loop:

for(i=0; i<3; ++i) {;}  

Any idea why?


LLVM has a principle of making each part do the least amount of work. LoopInfo::getSmallConstantTripCount doesn't do any fancy analysis, it looks for a simple loop with a single backedge that increments a value by 1 each time and is compared using != against a constant integer.

When you compile the code you wrote at -O0, every "i < 3" actually causes a load from memory to read in the latest value of 'i'. LoopInfo certainly isn't going to do the type of analysis necessary to figure out that the memory accesses aren't needed, that's the job of "opt -mem2reg". Try running that optimization, and maybe -instcombine -loopsimplify -loop-rotate over the code to get it into the shape the getSmallConstantTripCount will handle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜