[turbofan] CheckBounds cannot be used within asm.js.

Also properly deal with constant indices for String element access in
the JSNativeContextSpecialization.

BUG=chromium:661949
R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2474013002
Cr-Commit-Position: refs/heads/master@{#40723}
This commit is contained in:
bmeurer 2016-11-03 05:34:49 -07:00 committed by Commit bot
parent f04a9b4936
commit 10033749fd
3 changed files with 39 additions and 11 deletions

View File

@ -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);
// 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);
// 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);
// Return it as a single character string.
value = graph()->NewNode(simplified()->StringFromCharCode(), value);
ReplaceWithValue(node, value, effect, control);
return Replace(value);
}
}
}

View File

@ -167,6 +167,9 @@ struct FloatMatcher final : public ValueMatcher<T, kOpcode> {
bool IsNormal() const {
return this->HasValue() && std::isnormal(this->Value());
}
bool IsInteger() const {
return this->HasValue() && std::nearbyint(this->Value()) == this->Value();
}
bool IsPositiveOrNegativePowerOf2() const {
if (!this->HasValue() || (this->Value() == 0.0)) {
return false;

View File

@ -0,0 +1,15 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
var foo = (function() {
'use asm';
function foo() { ''[0]; }
return foo;
})();
foo();
%OptimizeFunctionOnNextCall(foo);
foo();