Skip to content

Commit 4df926f

Browse files
committed
[Autobackout][BuildBreak]Revert of change: c538f3a
FlattenSmallSwitch: Ensure that all case blocks in the switch have the switch block as their unique predecessor to ensure that the switch block dominates the merge block. Change-Id: I868a9bcc842bf6b4e233cb83686613fe26b531ce
1 parent c538f3a commit 4df926f

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,11 +3875,9 @@ IGC_INITIALIZE_PASS_BEGIN(GenStrengthReduction, "GenStrengthReduction",
38753875
This class flatten small switch. For example,
38763876
38773877
before optimization:
3878-
then153:
38793878
switch i32 %115, label %else229 [
38803879
i32 1, label %then214
38813880
i32 2, label %then222
3882-
i32 3, label %then222 ; duplicate blocks are fine
38833881
]
38843882
38853883
then214: ; preds = %then153
@@ -3983,9 +3981,6 @@ bool FlattenSmallSwitch::processSwitchInst(SwitchInst* SI)
39833981
if (br->getSuccessor(0) != MergeBlock)
39843982
return false;
39853983

3986-
if (!BB->getUniquePredecessor())
3987-
return false;
3988-
39893984
return true;
39903985
};
39913986

@@ -4064,13 +4059,14 @@ bool FlattenSmallSwitch::processSwitchInst(SwitchInst* SI)
40644059
// from BB to the InsertPoint.
40654060
auto splice = [](BasicBlock* BB, Instruction* InsertPoint)
40664061
{
4067-
for (auto II = BB->begin(), IE = BB->end(); II != IE; /* empty */)
4062+
Instruction* preIter = nullptr;
4063+
for (auto& iter : *BB)
40684064
{
4069-
auto* I = &*II++;
4070-
if (I->isTerminator())
4071-
return;
4072-
4073-
I->moveBefore(InsertPoint);
4065+
if (preIter)
4066+
{
4067+
preIter->moveBefore(InsertPoint);
4068+
}
4069+
preIter = cast<Instruction>(&iter);
40744070
}
40754071
};
40764072

@@ -4109,8 +4105,6 @@ bool FlattenSmallSwitch::processSwitchInst(SwitchInst* SI)
41094105
// connect the original block and the phi node block with a pass through branch
41104106
builder.CreateBr(Dest);
41114107

4112-
SmallPtrSet<BasicBlock*, 4> Succs;
4113-
41144108
// Remove the switch.
41154109
BasicBlock* SelectBB = SI->getParent();
41164110
for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i)
@@ -4120,9 +4114,7 @@ bool FlattenSmallSwitch::processSwitchInst(SwitchInst* SI)
41204114
{
41214115
continue;
41224116
}
4123-
4124-
if (Succs.insert(Succ).second)
4125-
Succ->removePredecessor(SelectBB);
4117+
Succ->removePredecessor(SelectBB);
41264118
}
41274119
SI->eraseFromParent();
41284120

0 commit comments

Comments
 (0)