source: webkit/trunk/Source/JavaScriptCore/dfg/DFGUseKind.cpp

Last change on this file was 282200, checked in by [email protected], 4 years ago

Optimize compareStrictEq when neither side is a double and at least one is not a BigInt
https://bugs.webkit.org/show_bug.cgi?id=226755
<rdar://problem/79321542>

Reviewed by Yusuke Suzuki.

JSTests:

Made the error messages in stress/reflect-set a bit more informative in the process of debugging an issue with the patch.

  • stress/reflect-set.js:

(shouldBe):
(shouldThrow):

Source/JavaScriptCore:

This is a very similar patch to https://bugs.webkit.org/show_bug.cgi?id=226676.
The difference is that here we allow Strings on both side of the comparison, so we must add code to handle equality among strings.

Like for that other patch, the optimization is disabled for BigInt32.
Enabling it in that case would either need modifying the speculation (from banning HeapBigInt to banning all BigInts), or ensuring that we can never have a HeapBigInt so small it compares equal to a BigInt32.

I only implemented this optimization on 64-bits: it is just painful to write code that handles registers at such a low-level without a 32-bit machine to test things locally.
If anyone wants to make this optimization work on 32-bit, I don't foretell any major difficulty.

Finally, like quite a few other useKinds already, this case does not make the CompareStrictEq merge with an adjacent Branch.
The reason is simply that this patch relies on compileStringEquality, which currently does not support that feature.
I intend to fix this (for all useKinds at once) in a separate patch.

Effect on microbenchmarks:
poly-stricteq-not-double 46.8000+-0.4110 23.5872+-0.3061 definitely 1.9841x faster
poly-stricteq-not-double-nor-string 16.6880+-0.2317 16.3627+-0.3729 might be 1.0199x faster
poly-stricteq 49.2175+-0.6047 48.9532+-0.6758

I looked at how many cases of Untyped/Untyped compareStrictEq have been fixed by this patch and two other recent patches.
On JetStream2:

This leaves 20 instances of Untyped/Untyped.

On Speedometer2.0:

This leaves 75 instances of Untyped/Untyped.

  • bytecode/SpeculatedType.h:

(JSC::isNeitherDoubleNorHeapBigIntSpeculation):

  • dfg/DFGDoesGC.cpp:

(JSC::DFG::doesGC):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupCompareStrictEqAndSameValue):

  • dfg/DFGNode.h:

(JSC::DFG::Node::shouldSpeculateNeitherDoubleNorHeapBigInt):

  • dfg/DFGSafeToExecute.h:

(JSC::DFG::SafeToExecuteEdge::operator()):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileStrictEq):
(JSC::DFG::SpeculativeJIT::emitBitwiseJSValueEquality):
(JSC::DFG::SpeculativeJIT::emitBranchOnBitwiseJSValueEquality):
(JSC::DFG::SpeculativeJIT::compileNotDoubleNeitherDoubleNorHeapBigIntNorStringStrictEquality):
(JSC::DFG::SpeculativeJIT::compilePeepHoleNotDoubleNeitherDoubleNorHeapBigIntNorStringStrictEquality):
(JSC::DFG::SpeculativeJIT::speculateNeitherDoubleNorHeapBigInt):
(JSC::DFG::SpeculativeJIT::speculateNeitherDoubleNorHeapBigIntNorString):
(JSC::DFG::SpeculativeJIT::speculate):

  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compileNeitherDoubleNorHeapBigIntToNotDoubleStrictEquality):

  • dfg/DFGUseKind.cpp:

(WTF::printInternal):

  • dfg/DFGUseKind.h:

(JSC::DFG::typeFilterFor):
(JSC::DFG::checkMayCrashIfInputIsEmpty):

  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):

File size: 5.4 KB
Line 
1/*
2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "DFGUseKind.h"
28
29#if ENABLE(DFG_JIT)
30
31namespace WTF {
32
33using namespace JSC::DFG;
34
35void printInternal(PrintStream& out, UseKind useKind)
36{
37 switch (useKind) {
38 case UntypedUse:
39 out.print("Untyped");
40 return;
41 case Int32Use:
42 out.print("Int32");
43 return;
44 case KnownInt32Use:
45 out.print("KnownInt32");
46 return;
47 case Int52RepUse:
48 out.print("Int52Rep");
49 return;
50 case AnyIntUse:
51 out.print("AnyInt");
52 return;
53 case NumberUse:
54 out.print("Number");
55 return;
56 case RealNumberUse:
57 out.print("RealNumber");
58 return;
59 case DoubleRepUse:
60 out.print("DoubleRep");
61 return;
62 case DoubleRepRealUse:
63 out.print("DoubleRepReal");
64 return;
65 case DoubleRepAnyIntUse:
66 out.print("DoubleRepAnyInt");
67 return;
68 case BooleanUse:
69 out.print("Boolean");
70 return;
71 case KnownBooleanUse:
72 out.print("KnownBoolean");
73 return;
74 case CellUse:
75 out.print("Cell");
76 return;
77 case KnownCellUse:
78 out.print("KnownCell");
79 return;
80 case CellOrOtherUse:
81 out.print("CellOrOther");
82 return;
83 case ObjectUse:
84 out.print("Object");
85 return;
86 case ArrayUse:
87 out.print("Array");
88 return;
89 case FunctionUse:
90 out.print("Function");
91 return;
92 case FinalObjectUse:
93 out.print("FinalObject");
94 return;
95 case RegExpObjectUse:
96 out.print("RegExpObject");
97 return;
98 case PromiseObjectUse:
99 out.print("PromiseObject");
100 return;
101 case ProxyObjectUse:
102 out.print("ProxyObject");
103 return;
104 case DerivedArrayUse:
105 out.print("DerivedArray");
106 return;
107 case DateObjectUse:
108 out.print("DateObject");
109 return;
110 case MapObjectUse:
111 out.print("MapObject");
112 return;
113 case SetObjectUse:
114 out.print("SetObject");
115 return;
116 case WeakMapObjectUse:
117 out.print("WeakMapObject");
118 return;
119 case WeakSetObjectUse:
120 out.print("WeakSetObject");
121 return;
122 case DataViewObjectUse:
123 out.print("DataViewObject");
124 return;
125 case ObjectOrOtherUse:
126 out.print("ObjectOrOther");
127 return;
128 case StringIdentUse:
129 out.print("StringIdent");
130 return;
131 case StringUse:
132 out.print("String");
133 return;
134 case StringOrOtherUse:
135 out.print("StringOrOther");
136 return;
137 case KnownStringUse:
138 out.print("KnownString");
139 return;
140 case KnownPrimitiveUse:
141 out.print("KnownPrimitive");
142 return;
143 case SymbolUse:
144 out.print("Symbol");
145 return;
146 case AnyBigIntUse:
147 out.print("AnyBigInt");
148 return;
149 case HeapBigIntUse:
150 out.print("HeapBigInt");
151 return;
152 case BigInt32Use:
153 out.print("BigInt32");
154 return;
155 case StringObjectUse:
156 out.print("StringObject");
157 return;
158 case StringOrStringObjectUse:
159 out.print("StringOrStringObject");
160 return;
161 case NotStringVarUse:
162 out.print("NotStringVar");
163 return;
164 case NotSymbolUse:
165 out.print("NotSymbol");
166 return;
167 case NotCellUse:
168 out.print("NotCell");
169 return;
170 case NotCellNorBigIntUse:
171 out.print("NotCellNorBigInt");
172 return;
173 case NotDoubleUse:
174 out.print("NotDouble");
175 return;
176 case NeitherDoubleNorHeapBigIntUse:
177 out.print("NeitherDoubleNorHeapBigInt");
178 return;
179 case NeitherDoubleNorHeapBigIntNorStringUse:
180 out.print("NeitherDoubleNorHeapBigIntNorString");
181 return;
182 case KnownOtherUse:
183 out.print("KnownOther");
184 return;
185 case OtherUse:
186 out.print("Other");
187 return;
188 case MiscUse:
189 out.print("Misc");
190 return;
191 case LastUseKind:
192 RELEASE_ASSERT_NOT_REACHED();
193 return;
194 }
195 RELEASE_ASSERT_NOT_REACHED();
196}
197
198} // namespace WTF
199
200#endif // ENABLE(DFG_JIT)
201
Note: See TracBrowser for help on using the repository browser.