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

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

Issue 1848243002: [turbofan] Introduce JSToInteger and JSToLength operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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/js-typed-lowering.h ('k') | src/compiler/opcodes.h » ('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 b9f7c2ed27c771148b589ade3d00ac4f2223c5e1..7e1a0dc24e7b0c91195e710b98f8b670fd4679da 100644
--- a/src/compiler/js-typed-lowering.cc
+++ b/src/compiler/js-typed-lowering.cc
@@ -644,6 +644,51 @@ Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) {
return NoChange();
}
+Reduction JSTypedLowering::ReduceJSToInteger(Node* node) {
+ Node* const input = NodeProperties::GetValueInput(node, 0);
+ Type* const input_type = NodeProperties::GetType(input);
+ if (input_type->Is(type_cache_.kIntegerOrMinusZero)) {
+ // JSToInteger(x:integer) => x
+ ReplaceWithValue(node, input);
+ return Replace(input);
+ }
+ return NoChange();
+}
+
+Reduction JSTypedLowering::ReduceJSToLength(Node* node) {
+ Node* input = NodeProperties::GetValueInput(node, 0);
+ Type* input_type = NodeProperties::GetType(input);
+ if (input_type->Is(type_cache_.kIntegerOrMinusZero)) {
+ if (input_type->Max() <= 0.0) {
+ input = jsgraph()->ZeroConstant();
+ } else if (input_type->Min() >= kMaxSafeInteger) {
+ input = jsgraph()->Constant(kMaxSafeInteger);
+ } else {
+ if (input_type->Min() <= 0.0) {
+ input = graph()->NewNode(
+ common()->Select(MachineRepresentation::kTagged),
+ graph()->NewNode(simplified()->NumberLessThanOrEqual(), input,
+ jsgraph()->ZeroConstant()),
+ jsgraph()->ZeroConstant(), input);
+ input_type = Type::Range(0.0, input_type->Max(), graph()->zone());
+ NodeProperties::SetType(input, input_type);
+ }
+ if (input_type->Max() > kMaxSafeInteger) {
+ input = graph()->NewNode(
+ common()->Select(MachineRepresentation::kTagged),
+ graph()->NewNode(simplified()->NumberLessThanOrEqual(),
+ jsgraph()->Constant(kMaxSafeInteger), input),
+ jsgraph()->Constant(kMaxSafeInteger), input);
+ input_type =
+ Type::Range(input_type->Min(), kMaxSafeInteger, graph()->zone());
+ NodeProperties::SetType(input, input_type);
+ }
+ }
+ ReplaceWithValue(node, input);
+ return Replace(input);
+ }
+ return NoChange();
+}
Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) {
if (input->opcode() == IrOpcode::kJSToNumber) {
@@ -1683,6 +1728,10 @@ Reduction JSTypedLowering::Reduce(Node* node) {
return ReduceJSModulus(node);
case IrOpcode::kJSToBoolean:
return ReduceJSToBoolean(node);
+ case IrOpcode::kJSToInteger:
+ return ReduceJSToInteger(node);
+ case IrOpcode::kJSToLength:
+ return ReduceJSToLength(node);
case IrOpcode::kJSToNumber:
return ReduceJSToNumber(node);
case IrOpcode::kJSToString:
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | src/compiler/opcodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698