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

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 1898653003: [turbofan] Optimize typeof in abstract/strict equality comparison. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | src/compiler/node-matchers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/compilation-dependencies.h" 6 #include "src/compilation-dependencies.h"
7 #include "src/compiler/access-builder.h" 7 #include "src/compiler/access-builder.h"
8 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/js-typed-lowering.h" 9 #include "src/compiler/js-typed-lowering.h"
10 #include "src/compiler/linkage.h" 10 #include "src/compiler/linkage.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 break; 488 break;
489 default: 489 default:
490 return NoChange(); 490 return NoChange();
491 } 491 }
492 return r.ChangeToPureOperator(comparison); 492 return r.ChangeToPureOperator(comparison);
493 } 493 }
494 // TODO(turbofan): relax/remove effects of this operator in other cases. 494 // TODO(turbofan): relax/remove effects of this operator in other cases.
495 return NoChange(); // Keep a generic comparison. 495 return NoChange(); // Keep a generic comparison.
496 } 496 }
497 497
498 Reduction JSTypedLowering::ReduceJSEqualTypeOf(Node* node, bool invert) {
499 HeapObjectBinopMatcher m(node);
500 if (m.left().IsJSTypeOf() && m.right().HasValue() &&
501 m.right().Value()->IsString()) {
502 Node* replacement;
503 Node* input = m.left().InputAt(0);
504 Handle<String> value = Handle<String>::cast(m.right().Value());
505 if (String::Equals(value, factory()->boolean_string())) {
506 replacement = graph()->NewNode(
507 common()->Select(MachineRepresentation::kTagged),
508 graph()->NewNode(simplified()->ReferenceEqual(Type::Any()), input,
509 jsgraph()->TrueConstant()),
510 jsgraph()->TrueConstant(),
511 graph()->NewNode(simplified()->ReferenceEqual(Type::Any()), input,
512 jsgraph()->FalseConstant()));
513 } else if (String::Equals(value, factory()->function_string())) {
514 replacement = graph()->NewNode(simplified()->ObjectIsCallable(), input);
515 } else if (String::Equals(value, factory()->number_string())) {
516 replacement = graph()->NewNode(simplified()->ObjectIsNumber(), input);
517 } else if (String::Equals(value, factory()->string_string())) {
518 replacement = graph()->NewNode(simplified()->ObjectIsString(), input);
519 } else if (String::Equals(value, factory()->undefined_string())) {
520 replacement = graph()->NewNode(
521 common()->Select(MachineRepresentation::kTagged),
522 graph()->NewNode(simplified()->ReferenceEqual(Type::Any()), input,
523 jsgraph()->NullConstant()),
524 jsgraph()->FalseConstant(),
525 graph()->NewNode(simplified()->ObjectIsUndetectable(), input));
526 } else {
527 return NoChange();
528 }
529 if (invert) {
530 replacement = graph()->NewNode(simplified()->BooleanNot(), replacement);
531 }
532 return Replace(replacement);
533 }
534 return NoChange();
535 }
498 536
499 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { 537 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) {
500 if (flags() & kDisableBinaryOpReduction) return NoChange(); 538 if (flags() & kDisableBinaryOpReduction) return NoChange();
501 539
540 Reduction const reduction = ReduceJSEqualTypeOf(node, invert);
541 if (reduction.Changed()) {
542 ReplaceWithValue(node, reduction.replacement());
543 return reduction;
544 }
545
502 JSBinopReduction r(this, node); 546 JSBinopReduction r(this, node);
503 547
504 if (r.BothInputsAre(Type::Number())) { 548 if (r.BothInputsAre(Type::Number())) {
505 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); 549 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert);
506 } 550 }
507 if (r.BothInputsAre(Type::String())) { 551 if (r.BothInputsAre(Type::String())) {
508 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); 552 return r.ChangeToPureOperator(simplified()->StringEqual(), invert);
509 } 553 }
510 if (r.BothInputsAre(Type::Boolean())) { 554 if (r.BothInputsAre(Type::Boolean())) {
511 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Boolean()), 555 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Boolean()),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 592 }
549 if (r.OneInputCannotBe(Type::NumberOrString())) { 593 if (r.OneInputCannotBe(Type::NumberOrString())) {
550 // For values with canonical representation (i.e. not string nor number) an 594 // For values with canonical representation (i.e. not string nor number) an
551 // empty type intersection means the values cannot be strictly equal. 595 // empty type intersection means the values cannot be strictly equal.
552 if (!r.left_type()->Maybe(r.right_type())) { 596 if (!r.left_type()->Maybe(r.right_type())) {
553 Node* replacement = jsgraph()->BooleanConstant(invert); 597 Node* replacement = jsgraph()->BooleanConstant(invert);
554 ReplaceWithValue(node, replacement); 598 ReplaceWithValue(node, replacement);
555 return Replace(replacement); 599 return Replace(replacement);
556 } 600 }
557 } 601 }
602 Reduction const reduction = ReduceJSEqualTypeOf(node, invert);
603 if (reduction.Changed()) {
604 return reduction;
605 }
558 if (r.OneInputIs(the_hole_type_)) { 606 if (r.OneInputIs(the_hole_type_)) {
559 return r.ChangeToPureOperator(simplified()->ReferenceEqual(the_hole_type_), 607 return r.ChangeToPureOperator(simplified()->ReferenceEqual(the_hole_type_),
560 invert); 608 invert);
561 } 609 }
562 if (r.OneInputIs(Type::Undefined())) { 610 if (r.OneInputIs(Type::Undefined())) {
563 return r.ChangeToPureOperator( 611 return r.ChangeToPureOperator(
564 simplified()->ReferenceEqual(Type::Undefined()), invert); 612 simplified()->ReferenceEqual(Type::Undefined()), invert);
565 } 613 }
566 if (r.OneInputIs(Type::Null())) { 614 if (r.OneInputIs(Type::Null())) {
567 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Null()), 615 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Null()),
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1833 }
1786 1834
1787 1835
1788 CompilationDependencies* JSTypedLowering::dependencies() const { 1836 CompilationDependencies* JSTypedLowering::dependencies() const {
1789 return dependencies_; 1837 return dependencies_;
1790 } 1838 }
1791 1839
1792 } // namespace compiler 1840 } // namespace compiler
1793 } // namespace internal 1841 } // namespace internal
1794 } // namespace v8 1842 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | src/compiler/node-matchers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698