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

Side by Side Diff: src/compiler/x64/instruction-selector-x64.cc

Issue 2475433005: [turbofan] Refactor the compare-zero folding in instruction selector. (Closed)
Patch Set: Make mips64 happy Created 4 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 unified diff | Download patch
« no previous file with comments | « src/compiler/mips64/instruction-selector-mips64.cc ('k') | no next file » | 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "src/base/adapters.h" 7 #include "src/base/adapters.h"
8 #include "src/compiler/instruction-selector-impl.h" 8 #include "src/compiler/instruction-selector-impl.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/node-properties.h" 10 #include "src/compiler/node-properties.h"
(...skipping 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 Node* const left = node->InputAt(0); 1862 Node* const left = node->InputAt(0);
1863 Node* const right = node->InputAt(1); 1863 Node* const right = node->InputAt(1);
1864 InstructionCode const opcode = 1864 InstructionCode const opcode =
1865 selector->IsSupported(AVX) ? kAVXFloat64Cmp : kSSEFloat64Cmp; 1865 selector->IsSupported(AVX) ? kAVXFloat64Cmp : kSSEFloat64Cmp;
1866 VisitCompare(selector, opcode, right, left, cont, false); 1866 VisitCompare(selector, opcode, right, left, cont, false);
1867 } 1867 }
1868 1868
1869 // Shared routine for word comparison against zero. 1869 // Shared routine for word comparison against zero.
1870 void VisitWordCompareZero(InstructionSelector* selector, Node* user, 1870 void VisitWordCompareZero(InstructionSelector* selector, Node* user,
1871 Node* value, FlagsContinuation* cont) { 1871 Node* value, FlagsContinuation* cont) {
1872 while (selector->CanCover(user, value)) { 1872 // Try to combine with comparisons against 0 by simply inverting the branch.
1873 while (value->opcode() == IrOpcode::kWord32Equal &&
1874 selector->CanCover(user, value)) {
1875 Int32BinopMatcher m(value);
1876 if (!m.right().Is(0)) break;
1877
1878 user = value;
1879 value = m.left().node();
1880 cont->Negate();
1881 }
1882
1883 if (selector->CanCover(user, value)) {
1873 switch (value->opcode()) { 1884 switch (value->opcode()) {
1874 case IrOpcode::kWord32Equal: { 1885 case IrOpcode::kWord32Equal:
1875 // Combine with comparisons against 0 by simply inverting the
1876 // continuation.
1877 Int32BinopMatcher m(value);
1878 if (m.right().Is(0)) {
1879 user = value;
1880 value = m.left().node();
1881 cont->Negate();
1882 continue;
1883 }
1884 cont->OverwriteAndNegateIfEqual(kEqual); 1886 cont->OverwriteAndNegateIfEqual(kEqual);
1885 return VisitWordCompare(selector, value, kX64Cmp32, cont); 1887 return VisitWordCompare(selector, value, kX64Cmp32, cont);
1886 }
1887 case IrOpcode::kInt32LessThan: 1888 case IrOpcode::kInt32LessThan:
1888 cont->OverwriteAndNegateIfEqual(kSignedLessThan); 1889 cont->OverwriteAndNegateIfEqual(kSignedLessThan);
1889 return VisitWordCompare(selector, value, kX64Cmp32, cont); 1890 return VisitWordCompare(selector, value, kX64Cmp32, cont);
1890 case IrOpcode::kInt32LessThanOrEqual: 1891 case IrOpcode::kInt32LessThanOrEqual:
1891 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); 1892 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1892 return VisitWordCompare(selector, value, kX64Cmp32, cont); 1893 return VisitWordCompare(selector, value, kX64Cmp32, cont);
1893 case IrOpcode::kUint32LessThan: 1894 case IrOpcode::kUint32LessThan:
1894 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); 1895 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan);
1895 return VisitWordCompare(selector, value, kX64Cmp32, cont); 1896 return VisitWordCompare(selector, value, kX64Cmp32, cont);
1896 case IrOpcode::kUint32LessThanOrEqual: 1897 case IrOpcode::kUint32LessThanOrEqual:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 return VisitWordCompare(selector, value, kX64Cmp32, cont); 1986 return VisitWordCompare(selector, value, kX64Cmp32, cont);
1986 case IrOpcode::kInt64Sub: 1987 case IrOpcode::kInt64Sub:
1987 return VisitWord64Compare(selector, value, cont); 1988 return VisitWord64Compare(selector, value, cont);
1988 case IrOpcode::kWord32And: 1989 case IrOpcode::kWord32And:
1989 return VisitWordCompare(selector, value, kX64Test32, cont); 1990 return VisitWordCompare(selector, value, kX64Test32, cont);
1990 case IrOpcode::kWord64And: 1991 case IrOpcode::kWord64And:
1991 return VisitWordCompare(selector, value, kX64Test, cont); 1992 return VisitWordCompare(selector, value, kX64Test, cont);
1992 default: 1993 default:
1993 break; 1994 break;
1994 } 1995 }
1995 break;
1996 } 1996 }
1997 1997
1998 // Branch could not be combined with a compare, emit compare against 0. 1998 // Branch could not be combined with a compare, emit compare against 0.
1999 VisitCompareZero(selector, value, kX64Cmp32, cont); 1999 VisitCompareZero(selector, value, kX64Cmp32, cont);
2000 } 2000 }
2001 2001
2002 } // namespace 2002 } // namespace
2003 2003
2004 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 2004 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
2005 BasicBlock* fbranch) { 2005 BasicBlock* fbranch) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 // static 2346 // static
2347 MachineOperatorBuilder::AlignmentRequirements 2347 MachineOperatorBuilder::AlignmentRequirements
2348 InstructionSelector::AlignmentRequirements() { 2348 InstructionSelector::AlignmentRequirements() {
2349 return MachineOperatorBuilder::AlignmentRequirements:: 2349 return MachineOperatorBuilder::AlignmentRequirements::
2350 FullUnalignedAccessSupport(); 2350 FullUnalignedAccessSupport();
2351 } 2351 }
2352 2352
2353 } // namespace compiler 2353 } // namespace compiler
2354 } // namespace internal 2354 } // namespace internal
2355 } // namespace v8 2355 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/mips64/instruction-selector-mips64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698