xiaoming gu
2012-Apr-20 05:43 UTC
[LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
Hi, all. I'm using void LoopBase::getExitBlocks (SmallVectorImpl< BlockT *> &ExitBlocks) const to get allexit blocks for a loop. The problem I find with this API is that it returns repetitive basic blocks in certain situations. Should repetitive basic blocks be removed? I have an example to show the problem. Following is the source code and the CFG is enclosed. int main() { int i = rand()%10; while ( i < 20 ) { i++; if ( i == 5) return 21; if ( i == 9) continue; else if ( i == 10) break; } return i; } If you use getExitBlocks() to get the exit basic blocks for the loop, the block "10" will show up twice in the results. Xiaoming -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120420/a25241fe/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: test_cfg.pdf Type: application/pdf Size: 4013 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120420/a25241fe/attachment.pdf>
Andrew Trick
2012-Apr-24 05:31 UTC
[LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
On Apr 19, 2012, at 10:43 PM, xiaoming gu <xiaoming.gu at gmail.com> wrote:> Hi, all. I'm using void LoopBase::getExitBlocks (SmallVectorImpl< BlockT * > &ExitBlocks) const to get all > exit blocks for a loop. The problem I find with this API is that it returns repetitive basic blocks in certain > situations. Should repetitive basic blocks be removed?Users generally expect a unique set of exit blocks, but don't make any strong assumption. The worst that can happen is missed optimization or redundant analysis. In most cases, the loop is in LoopSimplifyForm, so it's probably not a problem in practice. -Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120423/7de00d74/attachment.html>
Andrew Trick
2012-Apr-24 05:39 UTC
[LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
On Apr 23, 2012, at 10:31 PM, Andrew Trick <atrick at apple.com> wrote:> > On Apr 19, 2012, at 10:43 PM, xiaoming gu <xiaoming.gu at gmail.com> wrote: > >> Hi, all. I'm using void LoopBase::getExitBlocks (SmallVectorImpl< BlockT * > &ExitBlocks) const to get all >> exit blocks for a loop. The problem I find with this API is that it returns repetitive basic blocks in certain >> situations. Should repetitive basic blocks be removed? > > Users generally expect a unique set of exit blocks, but don't make any strong assumption. The worst that can happen is missed optimization or redundant analysis. In most cases, the loop is in LoopSimplifyForm, so it's probably not a problem in practice.Another thing I should mention. The iteration order of ExitBlocks is important. In llvm, generating unique sets is a pain because values are not numbered and iteration order needs to be reproducible. We would need to keep a SmallPtrSet for membership checking while populating the result vector. -Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120423/74bcabc8/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
- [LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
- [LLVMdev] Should repetitive basic blocks be removed in the results of LoopBase::getExitBlocks()?
- [LLVMdev] getExitBlocks returns duplicates in result vector
- [LLVMdev] Make LoopBase inherit from "RegionBase"?