diff options
author | 2015-02-24 13:35:38 +0000 | |
---|---|---|
committer | 2015-02-24 14:44:46 +0000 | |
commit | 817bce7658918b7a70c17b70aa5e6a46b1ae8b3d (patch) | |
tree | 4dc41c5a319d948ff09666cec28f530282191f72 /compiler | |
parent | 0b6daeb0f0014474b542cbba1f713eb0dbefb7f9 (diff) |
Fix inlining in the presence of multiple returns.
One return could actually return a phi, so doing a phi check for
knowing if the result phi was already created was bogus.
Bug: 19454010
Change-Id: Iee703a2d1071ae263092354465eda368e5d6770d
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/optimizing/nodes.cc | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 93787b8bfd..e51bbc330a 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -893,28 +893,32 @@ void HGraph::InlineInto(HGraph* outer_graph, HInvoke* invoke) { exit_block_->ReplaceWith(to); // Update all predecessors of the exit block (now the `to` block) - // to not `HReturn` but `HGoto` instead. Also collect the return - // values if any, and potentially make it a phi if there are multiple - // predecessors. + // to not `HReturn` but `HGoto` instead. HInstruction* return_value = nullptr; - for (size_t i = 0, e = to->GetPredecessors().Size(); i < e; ++i) { - HBasicBlock* predecessor = to->GetPredecessors().Get(i); + bool returns_void = to->GetPredecessors().Get(0)->GetLastInstruction()->IsReturnVoid(); + if (to->GetPredecessors().Size() == 1) { + HBasicBlock* predecessor = to->GetPredecessors().Get(0); HInstruction* last = predecessor->GetLastInstruction(); - if (!last->IsReturnVoid()) { - if (return_value != nullptr) { - if (!return_value->IsPhi()) { - HPhi* phi = new (allocator) HPhi(allocator, kNoRegNumber, 0, invoke->GetType()); - to->AddPhi(phi); - phi->AddInput(return_value); - return_value = phi; - } - return_value->AsPhi()->AddInput(last->InputAt(0)); - } else { - return_value = last->InputAt(0); - } + if (!returns_void) { + return_value = last->InputAt(0); } predecessor->AddInstruction(new (allocator) HGoto()); predecessor->RemoveInstruction(last); + } else { + if (!returns_void) { + // There will be multiple returns. + return_value = new (allocator) HPhi(allocator, kNoRegNumber, 0, invoke->GetType()); + to->AddPhi(return_value->AsPhi()); + } + for (size_t i = 0, e = to->GetPredecessors().Size(); i < e; ++i) { + HBasicBlock* predecessor = to->GetPredecessors().Get(i); + HInstruction* last = predecessor->GetLastInstruction(); + if (!returns_void) { + return_value->AsPhi()->AddInput(last->InputAt(0)); + } + predecessor->AddInstruction(new (allocator) HGoto()); + predecessor->RemoveInstruction(last); + } } if (return_value != nullptr) { |