diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-19 15:03:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 15:03:56 -0700 |
| commit | 453683bf44f2112719802eaac2b332d49eebd640 (patch) | |
| tree | d399db4c9cba90c11980186d3df1ffcc4d423b5a /source/slang/slang-ir-redundancy-removal.cpp | |
| parent | ecf85df6eee3da76ef54b14e4ab083f22da89e46 (diff) | |
Tuple swizzling, concat, comparison and `countof`. (#4856)
* Tuple swizzling and element access.
* Update proposal status.
* Cleanup.
* Fix merrge error.
* Address review.
Diffstat (limited to 'source/slang/slang-ir-redundancy-removal.cpp')
| -rw-r--r-- | source/slang/slang-ir-redundancy-removal.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/source/slang/slang-ir-redundancy-removal.cpp b/source/slang/slang-ir-redundancy-removal.cpp index b679d8438..fa3cd444a 100644 --- a/source/slang/slang-ir-redundancy-removal.cpp +++ b/source/slang/slang-ir-redundancy-removal.cpp @@ -8,6 +8,19 @@ namespace Slang struct RedundancyRemovalContext { RefPtr<IRDominatorTree> dom; + bool isSingleIterationLoop(IRLoop* loop) + { + int useCount = 0; + for (auto use = loop->getBreakBlock()->firstUse; use; use = use->nextUse) + { + if (use->getUser() == loop) + continue; + useCount++; + if (useCount > 1) + return false; + } + return true; + } bool tryHoistInstToOuterMostLoop(IRGlobalValueWithCode* func, IRInst* inst) { @@ -17,7 +30,8 @@ struct RedundancyRemovalContext parentBlock = dom->getImmediateDominator(parentBlock)) { auto terminatorInst = parentBlock->getTerminator(); - if (terminatorInst->getOp() == kIROp_loop) + if (terminatorInst->getOp() == kIROp_loop && + !isSingleIterationLoop(as<IRLoop>(terminatorInst))) { // Consider hoisting the inst into this block. // This is only possible if all operands of the inst are dominating `parentBlock`. |
