Skip to content

Commit 0f1a89d

Browse files
committed
SpeculativeDevirtualizer: erase a dead block and not just remove it from the function.
And add a few asserts to make the code clearer.
1 parent 5d34f66 commit 0f1a89d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,19 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI,
153153
}
154154

155155
// Remove the old Apply instruction.
156-
if (!isa<TryApplyInst>(AI))
156+
assert(AI.getInstruction() == &Continue->front() &&
157+
"AI should be the first instruction in the split Continue block");
158+
if (!isa<TryApplyInst>(AI)) {
157159
AI.getInstruction()->replaceAllUsesWith(Arg);
158-
auto *OriginalBB = AI.getParent();
159-
AI.getInstruction()->eraseFromParent();
160-
if (OriginalBB->empty())
161-
OriginalBB->removeFromParent();
160+
AI.getInstruction()->eraseFromParent();
161+
assert(!Continue->empty() &&
162+
"There should be at least a terminator after AI");
163+
} else {
164+
AI.getInstruction()->eraseFromParent();
165+
assert(Continue->empty() &&
166+
"There should not be an instruction after try_apply");
167+
Continue->eraseFromParent();
168+
}
162169

163170
// Update the stats.
164171
NumTargetsPredicted++;

0 commit comments

Comments
 (0)