Commit 2c0b1f6e authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[turbofan] re-wire Unreachable to the graph end at EffectPhi's

This avoids the EffectControlLinearizer stumbling upon unreachable
code.

Bug: chromium:958718
Change-Id: I135c17813741e48e878a4624370eee1e06081031
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1605737Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61434}
parent 5554781f
......@@ -61,7 +61,7 @@ Reduction DeadCodeElimination::Reduce(Node* node) {
case IrOpcode::kPhi:
return ReducePhi(node);
case IrOpcode::kEffectPhi:
return PropagateDeadControl(node);
return ReduceEffectPhi(node);
case IrOpcode::kDeoptimize:
case IrOpcode::kReturn:
case IrOpcode::kTerminate:
......@@ -109,7 +109,6 @@ Reduction DeadCodeElimination::ReduceEnd(Node* node) {
return NoChange();
}
Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) {
DCHECK(IrOpcode::IsMergeOpcode(node->opcode()));
Node::Inputs inputs = node->inputs();
......@@ -233,6 +232,36 @@ Reduction DeadCodeElimination::ReducePhi(Node* node) {
return NoChange();
}
Reduction DeadCodeElimination::ReduceEffectPhi(Node* node) {
DCHECK_EQ(IrOpcode::kEffectPhi, node->opcode());
Reduction reduction = PropagateDeadControl(node);
if (reduction.Changed()) return reduction;
Node* merge = NodeProperties::GetControlInput(node);
DCHECK(merge->opcode() == IrOpcode::kMerge ||
merge->opcode() == IrOpcode::kLoop);
int input_count = node->op()->EffectInputCount();
for (int i = 0; i < input_count; ++i) {
Node* effect = NodeProperties::GetEffectInput(node, i);
if (effect->opcode() == IrOpcode::kUnreachable) {
// If Unreachable hits an effect phi, we can re-connect the effect chain
// to the graph end and delete the corresponding inputs from the merge and
// phi nodes.
Node* control = NodeProperties::GetControlInput(merge, i);
Node* throw_node = graph_->NewNode(common_->Throw(), effect, control);
NodeProperties::MergeControlToEnd(graph_, common_, throw_node);
// Only remove the value uses of the Unreachable node, since other Throw
// nodes might already have the Unreachable node as an input.
ReplaceWithValue(effect, dead_, effect);
NodeProperties::ReplaceEffectInput(node, dead_, i);
NodeProperties::ReplaceControlInput(merge, dead_, i);
Revisit(merge);
reduction = Changed(node);
}
}
return reduction;
}
Reduction DeadCodeElimination::ReducePureNode(Node* node) {
DCHECK_EQ(0, node->op()->EffectInputCount());
if (node->opcode() == IrOpcode::kDeadValue) return NoChange();
......
......@@ -53,6 +53,7 @@ class V8_EXPORT_PRIVATE DeadCodeElimination final
Reduction ReduceLoopExit(Node* node);
Reduction ReduceNode(Node* node);
Reduction ReducePhi(Node* node);
Reduction ReduceEffectPhi(Node* node);
Reduction ReducePureNode(Node* node);
Reduction ReduceUnreachableOrIfException(Node* node);
Reduction ReduceEffectNode(Node* node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment