Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Unified Diff: src/compiler/linkage.cc

Issue 1245523002: [turbofan]: Fix tail calls edge cases and add tests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@1220823004
Patch Set: Cleanup tests Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler/linkage.cc
diff --git a/src/compiler/linkage.cc b/src/compiler/linkage.cc
index 691a3b38614fce0d045bc86af0584ae8d5b876c0..030c8277be8c9e4240c721a83ebae2b5f8754c84 100644
--- a/src/compiler/linkage.cc
+++ b/src/compiler/linkage.cc
@@ -53,6 +53,24 @@ bool CallDescriptor::HasSameReturnLocationsAs(
bool CallDescriptor::CanTailCall(const Node* node) const {
+ // Determine the number of stack parameters passed in
+ size_t stack_params = 0;
+ for (int 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 (int i = 0; i < InputCount(); ++i) {
+ if (!GetInputLocation(i).is_register()) {
+ if (GetInputLocation(i) !=
+ LinkageLocation(current_stack_param - stack_params)) {
+ return false;
+ }
+ ++current_stack_param;
+ }
+ }
// Tail calling is currently allowed if return locations match and all
// parameters are either in registers or on the stack but match exactly in
// number and content.
@@ -60,10 +78,9 @@ bool CallDescriptor::CanTailCall(const Node* node) const {
if (!HasSameReturnLocationsAs(other)) return false;
size_t current_input = 0;
size_t other_input = 0;
- size_t stack_parameter = 0;
while (true) {
if (other_input >= other->InputCount()) {
- while (current_input <= InputCount()) {
+ while (current_input < InputCount()) {
if (!GetInputLocation(current_input).is_register()) {
return false;
}
@@ -96,11 +113,12 @@ bool CallDescriptor::CanTailCall(const Node* node) const {
if (input->opcode() != IrOpcode::kParameter) {
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());
- if (param_index != stack_parameter) {
+ if (param_index != current_input - 1) {
return false;
}
- ++stack_parameter;
++current_input;
++other_input;
}

Powered by Google App Engine
This is Rietveld 408576698