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

Unified Diff: src/compiler/js-native-context-specialization.cc

Issue 2474013002: [turbofan] CheckBounds cannot be used within asm.js. (Closed)
Patch Set: Created 4 years, 1 month 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 | src/compiler/node-matchers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-native-context-specialization.cc
diff --git a/src/compiler/js-native-context-specialization.cc b/src/compiler/js-native-context-specialization.cc
index 57e933b1aa0c3b28db60ff0567db144605787a47..e6f4194cfeb5173a767ec7b21d5d48b738a9d56b 100644
--- a/src/compiler/js-native-context-specialization.cc
+++ b/src/compiler/js-native-context-specialization.cc
@@ -688,19 +688,29 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
// Strings are immutable in JavaScript.
if (access_mode == AccessMode::kStore) return NoChange();
- // Ensure that {index} is less than {receiver} length.
- Node* length = jsgraph()->Constant(string->length());
- index = effect = graph()->NewNode(simplified()->CheckBounds(), index,
- length, effect, control);
-
- // Load the character from the {receiver}.
- value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver,
- index, control);
-
- // Return it as a single character string.
- value = graph()->NewNode(simplified()->StringFromCharCode(), value);
- ReplaceWithValue(node, value, effect, control);
- return Replace(value);
+ // Properly deal with constant {index}.
+ NumberMatcher mindex(index);
+ if (mindex.IsInteger() && mindex.IsInRange(0.0, string->length() - 1)) {
+ // Constant-fold the {index} access to {string}.
+ Node* value =
+ jsgraph()->Constant(string->Get(static_cast<int>(mindex.Value())));
+ ReplaceWithValue(node, value, effect, control);
+ return Replace(value);
+ } else if (flags() & kDeoptimizationEnabled) {
+ // Ensure that {index} is less than {receiver} length.
+ Node* length = jsgraph()->Constant(string->length());
+ index = effect = graph()->NewNode(simplified()->CheckBounds(), index,
+ length, effect, control);
+
+ // Load the character from the {receiver}.
+ value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver,
+ index, control);
+
+ // Return it as a single character string.
+ value = graph()->NewNode(simplified()->StringFromCharCode(), value);
+ ReplaceWithValue(node, value, effect, control);
+ return Replace(value);
+ }
}
}
« no previous file with comments | « no previous file | src/compiler/node-matchers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698