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-builtin-reducer.cc

Issue 2313073002: [builtins] Migrate Number predicates and make them optimizable. (Closed)
Patch Set: 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 | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/typer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-builtin-reducer.cc
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc
index b2f9d6bde71b3f8ce7ef1653761b0cc27989137f..f028cb70c44fc77dc8339c32968b3d8f51cf509c 100644
--- a/src/compiler/js-builtin-reducer.cc
+++ b/src/compiler/js-builtin-reducer.cc
@@ -375,6 +375,34 @@ Reduction JSBuiltinReducer::ReduceDateGetTime(Node* node) {
return NoChange();
}
+// ES6 section 18.2.2 isFinite ( number )
+Reduction JSBuiltinReducer::ReduceGlobalIsFinite(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::PlainPrimitive())) {
+ // isFinite(a:plain-primitive) -> NumberEqual(a', a')
+ // where a' = NumberSubtract(ToNumber(a), ToNumber(a))
+ Node* input = ToNumber(r.GetJSCallInput(0));
+ Node* diff = graph()->NewNode(simplified()->NumberSubtract(), input, input);
+ Node* value = graph()->NewNode(simplified()->NumberEqual(), diff, diff);
+ return Replace(value);
+ }
+ return NoChange();
+}
+
+// ES6 section 18.2.3 isNaN ( number )
+Reduction JSBuiltinReducer::ReduceGlobalIsNaN(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::PlainPrimitive())) {
+ // isNaN(a:plain-primitive) -> BooleanNot(NumberEqual(a', a'))
+ // where a' = ToNumber(a)
+ Node* input = ToNumber(r.GetJSCallInput(0));
+ Node* check = graph()->NewNode(simplified()->NumberEqual(), input, input);
+ Node* value = graph()->NewNode(simplified()->BooleanNot(), check);
+ return Replace(value);
+ }
+ return NoChange();
+}
+
// ES6 section 20.2.2.1 Math.abs ( x )
Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
JSCallReduction r(node);
@@ -789,6 +817,60 @@ Reduction JSBuiltinReducer::ReduceMathTrunc(Node* node) {
return NoChange();
}
+// ES6 section 20.1.2.2 Number.isFinite ( number )
+Reduction JSBuiltinReducer::ReduceNumberIsFinite(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Number.isFinite(a:number) -> NumberEqual(a', a')
+ // where a' = NumberSubtract(a, a)
+ Node* input = r.GetJSCallInput(0);
+ Node* diff = graph()->NewNode(simplified()->NumberSubtract(), input, input);
+ Node* value = graph()->NewNode(simplified()->NumberEqual(), diff, diff);
+ return Replace(value);
+ }
+ return NoChange();
+}
+
+// ES6 section 20.1.2.3 Number.isInteger ( number )
+Reduction JSBuiltinReducer::ReduceNumberIsInteger(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Number.isInteger(x:number) -> NumberEqual(NumberSubtract(x, x'), #0)
+ // where x' = NumberTrunc(x)
+ Node* input = r.GetJSCallInput(0);
+ Node* trunc = graph()->NewNode(simplified()->NumberTrunc(), input);
+ Node* diff = graph()->NewNode(simplified()->NumberSubtract(), input, trunc);
+ Node* value = graph()->NewNode(simplified()->NumberEqual(), diff,
+ jsgraph()->ZeroConstant());
+ return Replace(value);
+ }
+ return NoChange();
+}
+
+// ES6 section 20.1.2.4 Number.isNaN ( number )
+Reduction JSBuiltinReducer::ReduceNumberIsNaN(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Number.isNaN(a:number) -> BooleanNot(NumberEqual(a, a))
+ Node* input = r.GetJSCallInput(0);
+ Node* check = graph()->NewNode(simplified()->NumberEqual(), input, input);
+ Node* value = graph()->NewNode(simplified()->BooleanNot(), check);
+ return Replace(value);
+ }
+ return NoChange();
+}
+
+// ES6 section 20.1.2.5 Number.isSafeInteger ( number )
+Reduction JSBuiltinReducer::ReduceNumberIsSafeInteger(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(type_cache_.kSafeInteger)) {
+ // Number.isInteger(x:safe-integer) -> #true
+ Node* value = jsgraph()->TrueConstant();
+ return Replace(value);
+ }
+ return NoChange();
+}
+
// ES6 section 20.1.2.13 Number.parseInt ( string, radix )
Reduction JSBuiltinReducer::ReduceNumberParseInt(Node* node) {
JSCallReduction r(node);
@@ -981,6 +1063,12 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
return ReduceArrayPush(node);
case kDateGetTime:
return ReduceDateGetTime(node);
+ case kGlobalIsFinite:
+ reduction = ReduceGlobalIsFinite(node);
+ break;
+ case kGlobalIsNaN:
+ reduction = ReduceGlobalIsNaN(node);
+ break;
case kMathAbs:
reduction = ReduceMathAbs(node);
break;
@@ -1080,6 +1168,18 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathTrunc:
reduction = ReduceMathTrunc(node);
break;
+ case kNumberIsFinite:
+ reduction = ReduceNumberIsFinite(node);
+ break;
+ case kNumberIsInteger:
+ reduction = ReduceNumberIsInteger(node);
+ break;
+ case kNumberIsNaN:
+ reduction = ReduceNumberIsNaN(node);
+ break;
+ case kNumberIsSafeInteger:
+ reduction = ReduceNumberIsSafeInteger(node);
+ break;
case kNumberParseInt:
reduction = ReduceNumberParseInt(node);
break;
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/typer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698