Skip to content

Commit ba5a697

Browse files
Miguel MartinsMylesBorins
Miguel Martins
authored andcommitted
deps: cherry-pick 5005faed5 from V8 upstream
Original commit message: [turbofan] Improve representation selection for type guard. This takes into account the type of the type guard when choosing representation for a node. To make the representation changes unambiguous, we pass the restricted type to the changer. BUG=chromium:726554 Review-Url: https://codereview.chromium.org/2920193004 Cr-Commit-Position: refs/heads/master@{#45734} PR-URL: #15177 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 105acf4 commit ba5a697

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

deps/v8/src/compiler/simplified-lowering.cc

+23-12
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,11 @@ class RepresentationSelector {
734734
!GetUpperBound(node->InputAt(1))->Maybe(type);
735735
}
736736

737-
void ConvertInput(Node* node, int index, UseInfo use) {
737+
// Converts input {index} of {node} according to given UseInfo {use},
738+
// assuming the type of the input is {input_type}. If {input_type} is null,
739+
// it takes the input from the input node {TypeOf(node->InputAt(index))}.
740+
void ConvertInput(Node* node, int index, UseInfo use,
741+
Type* input_type = nullptr) {
738742
Node* input = node->InputAt(index);
739743
// In the change phase, insert a change before the use if necessary.
740744
if (use.representation() == MachineRepresentation::kNone)
@@ -752,8 +756,11 @@ class RepresentationSelector {
752756
TRACE(" to ");
753757
PrintUseInfo(use);
754758
TRACE("\n");
759+
if (input_type == nullptr) {
760+
input_type = TypeOf(input);
761+
}
755762
Node* n = changer_->GetRepresentationFor(
756-
input, input_info->representation(), TypeOf(input), node, use);
763+
input, input_info->representation(), input_type, node, use);
757764
node->ReplaceInput(index, n);
758765
}
759766
}
@@ -2802,18 +2809,22 @@ class RepresentationSelector {
28022809
case IrOpcode::kObjectState:
28032810
return VisitObjectState(node);
28042811
case IrOpcode::kTypeGuard: {
2805-
// We just get rid of the sigma here. In principle, it should be
2806-
// possible to refine the truncation and representation based on
2807-
// the sigma's type.
2812+
// We just get rid of the sigma here, choosing the best representation
2813+
// for the sigma's type.
2814+
Type* type = TypeOf(node);
28082815
MachineRepresentation representation =
2809-
GetOutputInfoForPhi(node, TypeOf(node->InputAt(0)), truncation);
2810-
2811-
// For now, we just handle specially the impossible case.
2812-
MachineRepresentation output = TypeOf(node)->IsInhabited()
2813-
? representation
2814-
: MachineRepresentation::kNone;
2816+
GetOutputInfoForPhi(node, type, truncation);
28152817

2816-
VisitUnop(node, UseInfo(representation, truncation), output);
2818+
// Here we pretend that the input has the sigma's type for the
2819+
// conversion.
2820+
UseInfo use(representation, truncation);
2821+
if (propagate()) {
2822+
EnqueueInput(node, 0, use);
2823+
} else if (lower()) {
2824+
ConvertInput(node, 0, use, type);
2825+
}
2826+
ProcessRemainingInputs(node, 1);
2827+
SetOutput(node, representation);
28172828
if (lower()) DeferReplacement(node, node->InputAt(0));
28182829
return;
28192830
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
function h(a,b){
8+
for(var i=0; i<a.length; i++) {h(a[i],b[i]); }
9+
}
10+
11+
function g() {
12+
h(arguments.length, 2);
13+
}
14+
15+
function f() {
16+
return g(1, 2);
17+
}
18+
19+
b = [1,,];
20+
b[1] = 3.5;
21+
22+
h(b, [1073741823, 2147483648, -12]);
23+
24+
f();
25+
f();
26+
%OptimizeFunctionOnNextCall(f);
27+
f();

0 commit comments

Comments
 (0)