diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-08-25 14:53:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-25 14:53:12 -0400 |
| commit | 06f7ef354cdde4cf8e8797d8853ed2d9c3208b5b (patch) | |
| tree | 43458d031c791b1e03b469f2b059391cf4a755b6 /source/slang/slang-ir-loop-unroll.cpp | |
| parent | ef4c9f1f1c297f1a33be95795a7a7561e0cc3bde (diff) | |
Fix various issues with trivial loops (#3149)
* Fix issue with trivial loop detection
* Fix issue with unreachable blocks in break elimination
Add logic to avoid eliminating loops with multi-level breaks.
* Incorporate feedback
- Use a boolean for multi-level break check
- Use dominator trees for region check instead of exhaustive enumeration
- Fix potential issue with enumerating parent break blocks.
* fix
Diffstat (limited to 'source/slang/slang-ir-loop-unroll.cpp')
| -rw-r--r-- | source/slang/slang-ir-loop-unroll.cpp | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/source/slang/slang-ir-loop-unroll.cpp b/source/slang/slang-ir-loop-unroll.cpp index c9ac4191b..c4ef1650c 100644 --- a/source/slang/slang-ir-loop-unroll.cpp +++ b/source/slang/slang-ir-loop-unroll.cpp @@ -48,45 +48,6 @@ static bool _eliminateDeadBlocks(List<IRBlock*>& blocks, IRBlock* unreachableBlo return changed; } -List<IRBlock*> _collectBlocksInLoop(IRDominatorTree* dom, IRLoop* loopInst) -{ - List<IRBlock*> loopBlocks; - HashSet<IRBlock*> loopBlocksSet; - auto addBlock = [&](IRBlock* block) - { - if (loopBlocksSet.add(block)) - loopBlocks.add(block); - }; - auto firstBlock = as<IRBlock>(loopInst->block.get()); - auto breakBlock = as<IRBlock>(loopInst->breakBlock.get()); - - addBlock(firstBlock); - for (Index i = 0; i < loopBlocks.getCount(); i++) - { - auto block = loopBlocks[i]; - for (auto succ : block->getSuccessors()) - { - if (succ == breakBlock) - continue; - if (!dom->dominates(firstBlock, succ)) - continue; - if (!as<IRUnreachable>(breakBlock->getTerminator())) - { - if (dom->dominates(breakBlock, succ)) - continue; - } - addBlock(succ); - } - } - return loopBlocks; -} - -List<IRBlock*> collectBlocksInLoop(IRGlobalValueWithCode* func, IRLoop* loopInst) -{ - auto dom = computeDominatorTree(func); - return _collectBlocksInLoop(dom, loopInst); -} - static int _getLoopMaxIterationsToUnroll(IRLoop* loopInst) { static constexpr int kMaxIterationsToAttempt = 4096; @@ -440,7 +401,7 @@ static bool _unrollLoop( firstIterationBreakBlock->removeAndDeallocateAllDecorationsAndChildren(); builder.setInsertInto(firstIterationBreakBlock); - builder.emitBranch(unreachableBlock); + builder.emitUnreachable(); break; } @@ -487,7 +448,7 @@ bool unrollLoopsInFunc( // Remove any continue jumps from the loop. eliminateContinueBlocks(module, loop); - auto blocks = collectBlocksInLoop(func, loop); + auto blocks = collectBlocksInRegion(func, loop); auto loopLoc = loop->sourceLoc; if (!_unrollLoop(module, loop, blocks)) { |
