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

Unified Diff: src/compiler/escape-analysis-reducer.cc

Issue 2363573003: [turbofan] Add proper type guards to escape analysis. (Closed)
Patch Set: Better comment. Created 4 years, 3 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 | « no previous file | test/mjsunit/regress/regress-crbug-640497.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/escape-analysis-reducer.cc
diff --git a/src/compiler/escape-analysis-reducer.cc b/src/compiler/escape-analysis-reducer.cc
index a2b53c0b875b5b54e9feac606e3939cab6f9226a..bcd91e302fb1591249760eb35ff2648bbd1fe9f5 100644
--- a/src/compiler/escape-analysis-reducer.cc
+++ b/src/compiler/escape-analysis-reducer.cc
@@ -97,6 +97,22 @@ Reduction EscapeAnalysisReducer::Reduce(Node* node) {
return NoChange();
}
+namespace {
+
+Node* MaybeGuard(JSGraph* jsgraph, Node* original, Node* replacement) {
+ // We might need to guard the replacement if the type of the {replacement}
+ // node is not in a sub-type relation to the type of the the {original} node.
+ Type* const replacement_type = NodeProperties::GetType(replacement);
+ Type* const original_type = NodeProperties::GetType(original);
+ if (!replacement_type->Is(original_type)) {
+ Node* const control = NodeProperties::GetControlInput(original);
+ replacement = jsgraph->graph()->NewNode(
+ jsgraph->common()->TypeGuard(original_type), replacement, control);
+ }
+ return replacement;
+}
+
+} // namespace
Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) {
DCHECK(node->opcode() == IrOpcode::kLoadField ||
@@ -108,6 +124,7 @@ Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) {
isolate()->counters()->turbo_escape_loads_replaced()->Increment();
TRACE("Replaced #%d (%s) with #%d (%s)\n", node->id(),
node->op()->mnemonic(), rep->id(), rep->op()->mnemonic());
+ rep = MaybeGuard(jsgraph(), node, rep);
ReplaceWithValue(node, rep);
return Replace(rep);
}
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-640497.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698