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

Unified Diff: src/compiler/js-typed-lowering.cc

Issue 758643003: [turbofan] Insert appropriate conversions for typed array stores. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 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 | test/mjsunit/compiler/truncating-store.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-typed-lowering.cc
diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc
index 745aafd811e8f94c84749eb58135078b709331c5..0813136fc184df264e05ff38226ff8bf4aafb473 100644
--- a/src/compiler/js-typed-lowering.cc
+++ b/src/compiler/js-typed-lowering.cc
@@ -725,10 +725,36 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
Node* length = jsgraph()->Constant(array->length()->Number());
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
- Node* store = graph()->NewNode(
- simplified()->StoreElement(
- AccessBuilder::ForTypedArrayElement(type, true)),
- pointer, key, length, value, effect, control);
+
+ ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true);
+ Type* value_type = NodeProperties::GetBounds(value).upper;
+ // If the value input does not have the required type, insert the
+ // appropriate conversion.
+
+ // Convert to a number first.
+ if (!value_type->Is(Type::Number())) {
+ Reduction number_reduction = ReduceJSToNumberInput(value);
+ if (number_reduction.Changed()) {
+ value = number_reduction.replacement();
+ } else {
+ Node* context = NodeProperties::GetContextInput(node);
+ value = graph()->NewNode(javascript()->ToNumber(), value, context,
+ effect, control);
+ effect = value;
+ }
+ }
+ // For integer-typed arrays, convert to the integer type.
+ if (access.type->Is(Type::Signed32()) &&
+ !value_type->Is(Type::Signed32())) {
+ value = graph()->NewNode(simplified()->NumberToInt32(), value);
+ } else if (access.type->Is(Type::Unsigned32()) &&
+ !value_type->Is(Type::Unsigned32())) {
+ value = graph()->NewNode(simplified()->NumberToUint32(), value);
+ }
+
+ Node* store =
+ graph()->NewNode(simplified()->StoreElement(access), pointer, key,
+ length, value, effect, control);
return ReplaceEagerly(node, store);
}
}
« no previous file with comments | « no previous file | test/mjsunit/compiler/truncating-store.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698