From 453683bf44f2112719802eaac2b332d49eebd640 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 19 Aug 2024 15:03:56 -0700 Subject: Tuple swizzling, concat, comparison and `countof`. (#4856) * Tuple swizzling and element access. * Update proposal status. * Cleanup. * Fix merrge error. * Address review. --- source/slang/slang-ir-redundancy-removal.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-redundancy-removal.cpp') 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 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(terminatorInst))) { // Consider hoisting the inst into this block. // This is only possible if all operands of the inst are dominating `parentBlock`. -- cgit v1.2.3