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

Unified Diff: src/compiler/load-elimination.cc

Issue 2295643002: [turbofan] Extend LoadElimination to introduce TypeGuards. (Closed)
Patch Set: Fix assertion in SimplifiedLowering. Created 4 years, 4 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
« no previous file with comments | « src/compiler/load-elimination.h ('k') | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/load-elimination.cc
diff --git a/src/compiler/load-elimination.cc b/src/compiler/load-elimination.cc
index 2ad21d02ccf1f8b724b3e5cc95cb3561b80308e4..82fc47af075dad3c32e1b614432c2a5866d79434 100644
--- a/src/compiler/load-elimination.cc
+++ b/src/compiler/load-elimination.cc
@@ -4,6 +4,7 @@
#include "src/compiler/load-elimination.h"
+#include "src/compiler/common-operator.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/simplified-operator.h"
@@ -521,16 +522,21 @@ Reduction LoadElimination::ReduceLoadField(Node* node) {
FieldAccess const& access = FieldAccessOf(node->op());
Node* const object = NodeProperties::GetValueInput(node, 0);
Node* const effect = NodeProperties::GetEffectInput(node);
+ Node* const control = NodeProperties::GetControlInput(node);
AbstractState const* state = node_states_.Get(effect);
if (state == nullptr) return NoChange();
int field_index = FieldIndexOf(access);
if (field_index >= 0) {
- if (Node* const replacement = state->LookupField(object, field_index)) {
- // Make sure the {replacement} has at least as good type
- // as the original {node}.
- if (!replacement->IsDead() &&
- NodeProperties::GetType(replacement)
- ->Is(NodeProperties::GetType(node))) {
+ if (Node* replacement = state->LookupField(object, field_index)) {
+ // Make sure we don't resurrect dead {replacement} nodes.
+ if (!replacement->IsDead()) {
+ // We might need to guard the {replacement} if the type of the
+ // {node} is more precise than the type of the {replacement}.
+ Type* const node_type = NodeProperties::GetType(node);
+ if (!NodeProperties::GetType(replacement)->Is(node_type)) {
+ replacement = graph()->NewNode(common()->TypeGuard(node_type),
+ replacement, control);
+ }
ReplaceWithValue(node, replacement, effect);
return Replace(replacement);
}
@@ -568,14 +574,19 @@ Reduction LoadElimination::ReduceLoadElement(Node* node) {
Node* const object = NodeProperties::GetValueInput(node, 0);
Node* const index = NodeProperties::GetValueInput(node, 1);
Node* const effect = NodeProperties::GetEffectInput(node);
+ Node* const control = NodeProperties::GetControlInput(node);
AbstractState const* state = node_states_.Get(effect);
if (state == nullptr) return NoChange();
- if (Node* const replacement = state->LookupElement(object, index)) {
- // Make sure the {replacement} has at least as good type
- // as the original {node}.
- if (!replacement->IsDead() &&
- NodeProperties::GetType(replacement)
- ->Is(NodeProperties::GetType(node))) {
+ if (Node* replacement = state->LookupElement(object, index)) {
+ // Make sure we don't resurrect dead {replacement} nodes.
+ if (!replacement->IsDead()) {
+ // We might need to guard the {replacement} if the type of the
+ // {node} is more precise than the type of the {replacement}.
+ Type* const node_type = NodeProperties::GetType(node);
+ if (!NodeProperties::GetType(replacement)->Is(node_type)) {
+ replacement = graph()->NewNode(common()->TypeGuard(node_type),
+ replacement, control);
+ }
ReplaceWithValue(node, replacement, effect);
return Replace(replacement);
}
@@ -805,6 +816,12 @@ int LoadElimination::FieldIndexOf(FieldAccess const& access) {
return field_index;
}
+CommonOperatorBuilder* LoadElimination::common() const {
+ return jsgraph()->common();
+}
+
+Graph* LoadElimination::graph() const { return jsgraph()->graph(); }
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/load-elimination.h ('k') | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698