Commit d1a6dfaf authored by danno's avatar danno Committed by Commit bot

[turbofan]: Fix tail calls edge cases and add tests

Review URL: https://codereview.chromium.org/1245523002

Cr-Commit-Position: refs/heads/master@{#29791}
parent 2c07b0d0
...@@ -53,6 +53,25 @@ bool CallDescriptor::HasSameReturnLocationsAs( ...@@ -53,6 +53,25 @@ bool CallDescriptor::HasSameReturnLocationsAs(
bool CallDescriptor::CanTailCall(const Node* node) const { bool CallDescriptor::CanTailCall(const Node* node) const {
// Determine the number of stack parameters passed in
size_t stack_params = 0;
for (size_t i = 0; i < InputCount(); ++i) {
if (!GetInputLocation(i).is_register()) {
++stack_params;
}
}
// Ensure the input linkage contains the stack parameters in the right order
size_t current_stack_param = 0;
for (size_t i = 0; i < InputCount(); ++i) {
if (!GetInputLocation(i).is_register()) {
if (GetInputLocation(i) !=
LinkageLocation(static_cast<int>(current_stack_param) -
static_cast<int>(stack_params))) {
return false;
}
++current_stack_param;
}
}
// Tail calling is currently allowed if return locations match and all // Tail calling is currently allowed if return locations match and all
// parameters are either in registers or on the stack but match exactly in // parameters are either in registers or on the stack but match exactly in
// number and content. // number and content.
...@@ -60,10 +79,9 @@ bool CallDescriptor::CanTailCall(const Node* node) const { ...@@ -60,10 +79,9 @@ bool CallDescriptor::CanTailCall(const Node* node) const {
if (!HasSameReturnLocationsAs(other)) return false; if (!HasSameReturnLocationsAs(other)) return false;
size_t current_input = 0; size_t current_input = 0;
size_t other_input = 0; size_t other_input = 0;
size_t stack_parameter = 0;
while (true) { while (true) {
if (other_input >= other->InputCount()) { if (other_input >= other->InputCount()) {
while (current_input <= InputCount()) { while (current_input < InputCount()) {
if (!GetInputLocation(current_input).is_register()) { if (!GetInputLocation(current_input).is_register()) {
return false; return false;
} }
...@@ -96,11 +114,12 @@ bool CallDescriptor::CanTailCall(const Node* node) const { ...@@ -96,11 +114,12 @@ bool CallDescriptor::CanTailCall(const Node* node) const {
if (input->opcode() != IrOpcode::kParameter) { if (input->opcode() != IrOpcode::kParameter) {
return false; return false;
} }
// Make sure that the parameter input passed through to the tail call
// corresponds to the correct stack slot.
size_t param_index = ParameterIndexOf(input->op()); size_t param_index = ParameterIndexOf(input->op());
if (param_index != stack_parameter) { if (param_index != current_input - 1) {
return false; return false;
} }
++stack_parameter;
++current_input; ++current_input;
++other_input; ++other_input;
} }
......
This diff is collapsed.
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
'compiler/js-operator-unittest.cc', 'compiler/js-operator-unittest.cc',
'compiler/js-typed-lowering-unittest.cc', 'compiler/js-typed-lowering-unittest.cc',
'compiler/js-type-feedback-unittest.cc', 'compiler/js-type-feedback-unittest.cc',
'compiler/linkage-tail-call-unittest.cc',
'compiler/liveness-analyzer-unittest.cc', 'compiler/liveness-analyzer-unittest.cc',
'compiler/load-elimination-unittest.cc', 'compiler/load-elimination-unittest.cc',
'compiler/loop-peeling-unittest.cc', 'compiler/loop-peeling-unittest.cc',
......
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