Skip to content

Commit 2b4f214

Browse files
committed
v8: fix load elimination liveness checks
This commit back-ports the implementations of IsRename() and MayAlias() from the upstream 8.0 branch wholesale. Fixes several bugs where V8's load elimination pass considered values to be alive when they weren't. Fixes: nodejs#31484
1 parent 84eec80 commit 2b4f214

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

deps/v8/src/compiler/load-elimination.cc

+10-23
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool IsRename(Node* node) {
2121
switch (node->opcode()) {
2222
case IrOpcode::kFinishRegion:
2323
case IrOpcode::kTypeGuard:
24-
return true;
24+
return !node->IsDead();
2525
default:
2626
return false;
2727
}
@@ -35,12 +35,14 @@ Node* ResolveRenames(Node* node) {
3535
}
3636

3737
bool MayAlias(Node* a, Node* b) {
38-
if (a == b) return true;
39-
if (!NodeProperties::GetType(a).Maybe(NodeProperties::GetType(b))) {
40-
return false;
41-
}
42-
switch (b->opcode()) {
43-
case IrOpcode::kAllocate: {
38+
if (a != b) {
39+
if (!NodeProperties::GetType(a).Maybe(NodeProperties::GetType(b))) {
40+
return false;
41+
} else if (IsRename(b)) {
42+
return MayAlias(a, b->InputAt(0));
43+
} else if (IsRename(a)) {
44+
return MayAlias(a->InputAt(0), b);
45+
} else if (b->opcode() == IrOpcode::kAllocate) {
4446
switch (a->opcode()) {
4547
case IrOpcode::kAllocate:
4648
case IrOpcode::kHeapConstant:
@@ -49,30 +51,15 @@ bool MayAlias(Node* a, Node* b) {
4951
default:
5052
break;
5153
}
52-
break;
53-
}
54-
case IrOpcode::kFinishRegion:
55-
case IrOpcode::kTypeGuard:
56-
return MayAlias(a, b->InputAt(0));
57-
default:
58-
break;
59-
}
60-
switch (a->opcode()) {
61-
case IrOpcode::kAllocate: {
54+
} else if (a->opcode() == IrOpcode::kAllocate) {
6255
switch (b->opcode()) {
6356
case IrOpcode::kHeapConstant:
6457
case IrOpcode::kParameter:
6558
return false;
6659
default:
6760
break;
6861
}
69-
break;
7062
}
71-
case IrOpcode::kFinishRegion:
72-
case IrOpcode::kTypeGuard:
73-
return MayAlias(a->InputAt(0), b);
74-
default:
75-
break;
7663
}
7764
return true;
7865
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2018 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+
for (x = 0; x < 10000; ++x) {
6+
[(x) => x, [, 4294967295].find((x) => x), , 2].includes('x', -0);
7+
}

0 commit comments

Comments
 (0)