Commit 0af589b 1 parent 941f070 commit 0af589b Copy full SHA for 0af589b
File tree 1 file changed +7
-16
lines changed
1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,6 @@ namespace Slang
9
9
struct RedundancyRemovalContext
10
10
{
11
11
RefPtr<IRDominatorTree> dom;
12
- bool isSingleIterationLoop (IRLoop* loop)
13
- {
14
- int useCount = 0 ;
15
- for (auto use = loop->getBreakBlock ()->firstUse ; use; use = use->nextUse )
16
- {
17
- if (use->getUser () == loop)
18
- continue ;
19
- useCount++;
20
- if (useCount > 1 )
21
- return false ;
22
- }
23
- return true ;
24
- }
25
12
26
13
bool tryHoistInstToOuterMostLoop (IRGlobalValueWithCode* func, IRInst* inst)
27
14
{
@@ -31,11 +18,15 @@ struct RedundancyRemovalContext
31
18
parentBlock = dom->getImmediateDominator (parentBlock))
32
19
{
33
20
auto terminatorInst = parentBlock->getTerminator ();
34
- if (terminatorInst->getOp () == kIROp_loop &&
35
- !isSingleIterationLoop (as<IRLoop>(terminatorInst)))
21
+ if (auto loop = as<IRLoop>(terminatorInst))
36
22
{
23
+ // If `inst` is outside of the loop region, don't hoist it into the loop.
24
+ if (dom->dominates (loop->getBreakBlock (), inst))
25
+ continue ;
26
+
37
27
// Consider hoisting the inst into this block.
38
- // This is only possible if all operands of the inst are dominating `parentBlock`.
28
+ // This is only possible if all operands of the inst are dominating
29
+ // `parentBlock`.
39
30
bool canHoist = true ;
40
31
for (UInt i = 0 ; i < inst->getOperandCount (); i++)
41
32
{
You can’t perform that action at this time.
0 commit comments