Skip to content

Commit

Permalink
Fix loop hoisting logic in redundancy pass. (shader-slang#5836)
Browse files Browse the repository at this point in the history
* Fix fast single iteration loop test in redundancy pass.

* Fix.
  • Loading branch information
csyonghe authored Dec 11, 2024
1 parent 941f070 commit 0af589b
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions source/slang/slang-ir-redundancy-removal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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++)
{
Expand Down

0 comments on commit 0af589b

Please sign in to comment.