diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-24 10:01:47 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-24 10:01:47 -0800 |
| commit | bd6306cdaa4a49344658bd026721b6532e103d09 (patch) | |
| tree | bb7f666d426e6cfc7777a3ccac0a1d628588eb39 /source/slang/slang-ir-loop-unroll.cpp | |
| parent | e8c08e7ecb1124f115a1d1042277776193122b57 (diff) | |
More control flow simplifications. (#2673)
* More control flow and Phi param simplifications.
* Fix.
* Fix gcc error.
* Fix.
* More IR cleanup.
* Fix bug in phi param dce + ifelse simplify.
* Propagate and DCE side-effect-free functions.
* Enhance CFG simplifcation to remove loops with no side effects.
* Fix.
* Fixes.
* Fix tests. Add [__AlwaysFoldIntoUseSite] for rayPayloadLocation.
* More cleanup.
* Fixes.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-loop-unroll.cpp')
| -rw-r--r-- | source/slang/slang-ir-loop-unroll.cpp | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/source/slang/slang-ir-loop-unroll.cpp b/source/slang/slang-ir-loop-unroll.cpp index 79b00f60a..2f689ebde 100644 --- a/source/slang/slang-ir-loop-unroll.cpp +++ b/source/slang/slang-ir-loop-unroll.cpp @@ -47,7 +47,7 @@ static bool _eliminateDeadBlocks(List<IRBlock*>& blocks, IRBlock* unreachableBlo return changed; } -List<IRBlock*> _collectBlocksInLoop(Dictionary<IRBlock*, int>& blockOrdering, IRLoop* loopInst) +List<IRBlock*> _collectBlocksInLoop(IRDominatorTree* dom, IRLoop* loopInst) { List<IRBlock*> loopBlocks; HashSet<IRBlock*> loopBlocksSet; @@ -58,7 +58,6 @@ List<IRBlock*> _collectBlocksInLoop(Dictionary<IRBlock*, int>& blockOrdering, IR }; auto firstBlock = as<IRBlock>(loopInst->block.get()); auto breakBlock = as<IRBlock>(loopInst->breakBlock.get()); - auto breakBlockOrdering = blockOrdering[breakBlock].GetValue(); addBlock(firstBlock); for (Index i = 0; i < loopBlocks.getCount(); i++) @@ -68,18 +67,19 @@ List<IRBlock*> _collectBlocksInLoop(Dictionary<IRBlock*, int>& blockOrdering, IR { if (succ == breakBlock) continue; - auto successorOrdering = blockOrdering[block].GetValue(); - // The target must be post-dominated by the break block in order to be considered - // the body of the loop. - // Since we don't support arbitrary goto or multi-level continue, the simple - // ordering comparison is sufficient to serve as a post-dominance check. - if (successorOrdering < breakBlockOrdering) + if (dom->dominates(firstBlock, succ) && !dom->dominates(breakBlock, succ)) 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 = 100; @@ -483,15 +483,7 @@ bool unrollLoopsInFunc( // Remove any continue jumps from the loop. eliminateContinueBlocks(module, loop); - auto postOrderReverseCFG = getPostorderOnReverseCFG(func); - Dictionary<IRBlock*, int> blockOrdering; - - for (Index i = 0; i < postOrderReverseCFG.getCount(); i++) - { - blockOrdering[postOrderReverseCFG[i]] = (int)i; - } - - auto blocks = _collectBlocksInLoop(blockOrdering, loop); + auto blocks = collectBlocksInLoop(func, loop); auto loopLoc = loop->sourceLoc; if (!_unrollLoop(module, loop, blocks)) { |
