summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-11 14:18:41 -0800
committerGitHub <noreply@github.com>2024-12-11 14:18:41 -0800
commit0af589bf2ddf383eb8e6014e8e9da3309284ce0f (patch)
tree99cd562e24105341267d8d4a3ea6c994e3d75439 /source
parent941f07040a505f1f673c96da959bde839c629aba (diff)
Fix loop hoisting logic in redundancy pass. (#5836)
* Fix fast single iteration loop test in redundancy pass. * Fix.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-redundancy-removal.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/source/slang/slang-ir-redundancy-removal.cpp b/source/slang/slang-ir-redundancy-removal.cpp
index b885a8946..0d9b910c4 100644
--- a/source/slang/slang-ir-redundancy-removal.cpp
+++ b/source/slang/slang-ir-redundancy-removal.cpp
@@ -9,19 +9,6 @@ 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)
{
@@ -31,11 +18,15 @@ struct RedundancyRemovalContext
parentBlock = dom->getImmediateDominator(parentBlock))
{
auto terminatorInst = parentBlock->getTerminator();
- if (terminatorInst->getOp() == kIROp_loop &&
- !isSingleIterationLoop(as<IRLoop>(terminatorInst)))
+ if (auto loop = as<IRLoop>(terminatorInst))
{
+ // If `inst` is outside of the loop region, don't hoist it into the loop.
+ if (dom->dominates(loop->getBreakBlock(), inst))
+ continue;
+
// Consider hoisting the inst into this block.
- // This is only possible if all operands of the inst are dominating `parentBlock`.
+ // This is only possible if all operands of the inst are dominating
+ // `parentBlock`.
bool canHoist = true;
for (UInt i = 0; i < inst->getOperandCount(); i++)
{