[DFG] ToString operation should have fixup for primitives to say this node does not...
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGAbstractInterpreterInlines.h
1 /*
2  * Copyright (C) 2013-2017 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 #pragma once
27
28 #if ENABLE(DFG_JIT)
29
30 #include "ArrayConstructor.h"
31 #include "DFGAbstractInterpreter.h"
32 #include "DOMJITGetterSetter.h"
33 #include "DOMJITSignature.h"
34 #include "GetByIdStatus.h"
35 #include "GetterSetter.h"
36 #include "HashMapImpl.h"
37 #include "JITOperations.h"
38 #include "MathCommon.h"
39 #include "Operations.h"
40 #include "PutByIdStatus.h"
41 #include "StringObject.h"
42
43 namespace JSC { namespace DFG {
44
45 template<typename AbstractStateType>
46 AbstractInterpreter<AbstractStateType>::AbstractInterpreter(Graph& graph, AbstractStateType& state)
47     : m_codeBlock(graph.m_codeBlock)
48     , m_graph(graph)
49     , m_vm(m_graph.m_vm)
50     , m_state(state)
51 {
52     if (m_graph.m_form == SSA)
53         m_phiChildren = std::make_unique<PhiChildren>(m_graph);
54 }
55
56 template<typename AbstractStateType>
57 AbstractInterpreter<AbstractStateType>::~AbstractInterpreter()
58 {
59 }
60
61 template<typename AbstractStateType>
62 typename AbstractInterpreter<AbstractStateType>::BooleanResult
63 AbstractInterpreter<AbstractStateType>::booleanResult(
64     Node* node, AbstractValue& value)
65 {
66     JSValue childConst = value.value();
67     if (childConst) {
68         if (childConst.toBoolean(m_codeBlock->globalObjectFor(node->origin.semantic)->globalExec()))
69             return DefinitelyTrue;
70         return DefinitelyFalse;
71     }
72
73     // Next check if we can fold because we know that the source is an object or string and does not equal undefined.
74     if (isCellSpeculation(value.m_type) && !value.m_structure.isTop()) {
75         bool allTrue = true;
76         for (unsigned i = value.m_structure.size(); i--;) {
77             RegisteredStructure structure = value.m_structure[i];
78             if (structure->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
79                 || structure->typeInfo().type() == StringType) {
80                 allTrue = false;
81                 break;
82             }
83         }
84         if (allTrue)
85             return DefinitelyTrue;
86     }
87     
88     return UnknownBooleanResult;
89 }
90
91 template<typename AbstractStateType>
92 void AbstractInterpreter<AbstractStateType>::startExecuting()
93 {
94     ASSERT(m_state.block());
95     ASSERT(m_state.isValid());
96     
97     m_state.setDidClobber(false);
98 }
99
100 template<typename AbstractStateType>
101 void AbstractInterpreter<AbstractStateType>::executeEdges(Node* node)
102 {
103     m_graph.doToChildren(
104         node,
105         [&] (Edge& edge) {
106             filterEdgeByUse(edge);
107         });
108 }
109
110 template<typename AbstractStateType>
111 void AbstractInterpreter<AbstractStateType>::executeKnownEdgeTypes(Node* node)
112 {
113     // Some use kinds are required to not have checks, because we know somehow that the incoming
114     // value will already have the type we want. In those cases, AI may not be smart enough to
115     // prove that this is indeed the case. But the existance of the edge is enough to prove that
116     // it is indeed the case. Taking advantage of this is not optional, since otherwise the DFG
117     // and FTL backends may emit checks in a node that lacks a valid exit origin.
118     m_graph.doToChildren(
119         node,
120         [&] (Edge& edge) {
121             if (mayHaveTypeCheck(edge.useKind()))
122                 return;
123             
124             filterEdgeByUse(edge);
125         });
126 }
127
128 template<typename AbstractStateType>
129 void AbstractInterpreter<AbstractStateType>::verifyEdge(Node* node, Edge edge)
130 {
131     if (!(forNode(edge).m_type & ~typeFilterFor(edge.useKind())))
132         return;
133     
134     DFG_CRASH(m_graph, node, toCString("Edge verification error: ", node, "->", edge, " was expected to have type ", SpeculationDump(typeFilterFor(edge.useKind())), " but has type ", SpeculationDump(forNode(edge).m_type), " (", forNode(edge).m_type, ")").data());
135 }
136
137 template<typename AbstractStateType>
138 void AbstractInterpreter<AbstractStateType>::verifyEdges(Node* node)
139 {
140     DFG_NODE_DO_TO_CHILDREN(m_graph, node, verifyEdge);
141 }
142
143 inline bool isToThisAnIdentity(bool isStrictMode, AbstractValue& valueForNode)
144 {
145     // We look at the type first since that will cover most cases and does not require iterating all the structures.
146     if (isStrictMode) {
147         if (valueForNode.m_type && !(valueForNode.m_type & SpecObjectOther))
148             return true;
149     } else {
150         if (valueForNode.m_type && !(valueForNode.m_type & (~SpecObject | SpecObjectOther)))
151             return true;
152     }
153
154     if ((isStrictMode || (valueForNode.m_type && !(valueForNode.m_type & ~SpecObject))) && valueForNode.m_structure.isFinite()) {
155         bool overridesToThis = false;
156         valueForNode.m_structure.forEach([&](RegisteredStructure structure) {
157             TypeInfo type = structure->typeInfo();
158             ASSERT(type.isObject() || type.type() == StringType || type.type() == SymbolType);
159             if (!isStrictMode)
160                 ASSERT(type.isObject());
161             // We don't need to worry about strings/symbols here since either:
162             // 1) We are in strict mode and strings/symbols are not wrapped
163             // 2) The AI has proven that the type of this is a subtype of object
164             if (type.isObject() && type.overridesToThis())
165                 overridesToThis = true;
166         });
167         return !overridesToThis;
168     }
169
170     return false;
171 }
172
173 template<typename AbstractStateType>
174 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimit, Node* node)
175 {
176     verifyEdges(node);
177     
178     m_state.createValueForNode(node);
179     
180     switch (node->op()) {
181     case JSConstant:
182     case DoubleConstant:
183     case Int52Constant: {
184         setBuiltInConstant(node, *node->constant());
185         break;
186     }
187
188     case LazyJSConstant: {
189         LazyJSValue value = node->lazyJSValue();
190         switch (value.kind()) {
191         case LazyJSValue::KnownValue:
192             setConstant(node, value.value()->value());
193             break;
194         case LazyJSValue::SingleCharacterString:
195         case LazyJSValue::KnownStringImpl:
196         case LazyJSValue::NewStringImpl:
197             forNode(node).setType(m_graph, SpecString);
198             break;
199         }
200         break;
201     }
202         
203     case Identity: {
204         forNode(node) = forNode(node->child1());
205         if (forNode(node).value())
206             m_state.setFoundConstants(true);
207         break;
208     }
209         
210     case ExtractOSREntryLocal: {
211         forNode(node).makeBytecodeTop();
212         break;
213     }
214             
215     case GetLocal: {
216         VariableAccessData* variableAccessData = node->variableAccessData();
217         AbstractValue value = m_state.variables().operand(variableAccessData->local().offset());
218         // The value in the local should already be checked.
219         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(variableAccessData->flushFormat())));
220         if (value.value())
221             m_state.setFoundConstants(true);
222         forNode(node) = value;
223         break;
224     }
225         
226     case GetStack: {
227         StackAccessData* data = node->stackAccessData();
228         AbstractValue value = m_state.variables().operand(data->local);
229         // The value in the local should already be checked.
230         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(data->format)));
231         if (value.value())
232             m_state.setFoundConstants(true);
233         forNode(node) = value;
234         break;
235     }
236         
237     case GetLocalUnlinked: {
238         AbstractValue value = m_state.variables().operand(node->unlinkedLocal().offset());
239         if (value.value())
240             m_state.setFoundConstants(true);
241         forNode(node) = value;
242         break;
243     }
244         
245     case SetLocal: {
246         m_state.variables().operand(node->local()) = forNode(node->child1());
247         break;
248     }
249         
250     case PutStack: {
251         m_state.variables().operand(node->stackAccessData()->local) = forNode(node->child1());
252         break;
253     }
254         
255     case MovHint: {
256         // Don't need to do anything. A MovHint only informs us about what would have happened
257         // in bytecode, but this code is just concerned with what is actually happening during
258         // DFG execution.
259         break;
260     }
261         
262     case KillStack: {
263         // This is just a hint telling us that the OSR state of the local is no longer inside the
264         // flushed data.
265         break;
266     }
267         
268     case SetArgument:
269         // Assert that the state of arguments has been set. SetArgument means that someone set
270         // the argument values out-of-band, and currently this always means setting to a
271         // non-clear value.
272         ASSERT(!m_state.variables().operand(node->local()).isClear());
273         break;
274         
275     case LoadVarargs:
276     case ForwardVarargs: {
277         // FIXME: ForwardVarargs should check if the count becomes known, and if it does, it should turn
278         // itself into a straight-line sequence of GetStack/PutStack.
279         // https://bugs.webkit.org/show_bug.cgi?id=143071
280         clobberWorld(node->origin.semantic, clobberLimit);
281         LoadVarargsData* data = node->loadVarargsData();
282         m_state.variables().operand(data->count).setType(SpecInt32Only);
283         for (unsigned i = data->limit - 1; i--;)
284             m_state.variables().operand(data->start.offset() + i).makeHeapTop();
285         break;
286     }
287             
288     case BitAnd:
289     case BitOr:
290     case BitXor:
291     case BitRShift:
292     case BitLShift:
293     case BitURShift: {
294         if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse) {
295             clobberWorld(node->origin.semantic, clobberLimit);
296             forNode(node).setType(m_graph, SpecInt32Only);
297             break;
298         }
299
300         JSValue left = forNode(node->child1()).value();
301         JSValue right = forNode(node->child2()).value();
302         if (left && right && left.isInt32() && right.isInt32()) {
303             int32_t a = left.asInt32();
304             int32_t b = right.asInt32();
305             switch (node->op()) {
306             case BitAnd:
307                 setConstant(node, JSValue(a & b));
308                 break;
309             case BitOr:
310                 setConstant(node, JSValue(a | b));
311                 break;
312             case BitXor:
313                 setConstant(node, JSValue(a ^ b));
314                 break;
315             case BitRShift:
316                 setConstant(node, JSValue(a >> static_cast<uint32_t>(b)));
317                 break;
318             case BitLShift:
319                 setConstant(node, JSValue(a << static_cast<uint32_t>(b)));
320                 break;
321             case BitURShift:
322                 setConstant(node, JSValue(static_cast<uint32_t>(a) >> static_cast<uint32_t>(b)));
323                 break;
324             default:
325                 RELEASE_ASSERT_NOT_REACHED();
326                 break;
327             }
328             break;
329         }
330         
331         if (node->op() == BitAnd
332             && (isBoolInt32Speculation(forNode(node->child1()).m_type) ||
333                 isBoolInt32Speculation(forNode(node->child2()).m_type))) {
334             forNode(node).setType(SpecBoolInt32);
335             break;
336         }
337         
338         forNode(node).setType(SpecInt32Only);
339         break;
340     }
341         
342     case UInt32ToNumber: {
343         JSValue child = forNode(node->child1()).value();
344         if (doesOverflow(node->arithMode())) {
345             if (enableInt52()) {
346                 if (child && child.isAnyInt()) {
347                     int64_t machineInt = child.asAnyInt();
348                     setConstant(node, jsNumber(static_cast<uint32_t>(machineInt)));
349                     break;
350                 }
351                 forNode(node).setType(SpecAnyInt);
352                 break;
353             }
354             if (child && child.isInt32()) {
355                 uint32_t value = child.asInt32();
356                 setConstant(node, jsNumber(value));
357                 break;
358             }
359             forNode(node).setType(SpecAnyIntAsDouble);
360             break;
361         }
362         if (child && child.isInt32()) {
363             int32_t value = child.asInt32();
364             if (value >= 0) {
365                 setConstant(node, jsNumber(value));
366                 break;
367             }
368         }
369         forNode(node).setType(SpecInt32Only);
370         break;
371     }
372         
373     case BooleanToNumber: {
374         JSValue concreteValue = forNode(node->child1()).value();
375         if (concreteValue) {
376             if (concreteValue.isBoolean())
377                 setConstant(node, jsNumber(concreteValue.asBoolean()));
378             else
379                 setConstant(node, *m_graph.freeze(concreteValue));
380             break;
381         }
382         AbstractValue& value = forNode(node);
383         value = forNode(node->child1());
384         if (node->child1().useKind() == UntypedUse && !(value.m_type & ~SpecBoolean))
385             m_state.setFoundConstants(true);
386         if (value.m_type & SpecBoolean) {
387             value.merge(SpecBoolInt32);
388             value.filter(~SpecBoolean);
389         }
390         break;
391     }
392             
393     case DoubleAsInt32: {
394         JSValue child = forNode(node->child1()).value();
395         if (child && child.isNumber()) {
396             double asDouble = child.asNumber();
397             int32_t asInt = JSC::toInt32(asDouble);
398             if (bitwise_cast<int64_t>(static_cast<double>(asInt)) == bitwise_cast<int64_t>(asDouble)) {
399                 setConstant(node, JSValue(asInt));
400                 break;
401             }
402         }
403         forNode(node).setType(SpecInt32Only);
404         break;
405     }
406             
407     case ValueToInt32: {
408         JSValue child = forNode(node->child1()).value();
409         if (child) {
410             if (child.isNumber()) {
411                 if (child.isInt32())
412                     setConstant(node, child);
413                 else
414                     setConstant(node, JSValue(JSC::toInt32(child.asDouble())));
415                 break;
416             }
417             if (child.isBoolean()) {
418                 setConstant(node, jsNumber(child.asBoolean()));
419                 break;
420             }
421             if (child.isUndefinedOrNull()) {
422                 setConstant(node, jsNumber(0));
423                 break;
424             }
425         }
426         
427         if (isBooleanSpeculation(forNode(node->child1()).m_type)) {
428             forNode(node).setType(SpecBoolInt32);
429             break;
430         }
431         
432         forNode(node).setType(SpecInt32Only);
433         break;
434     }
435         
436     case DoubleRep: {
437         JSValue child = forNode(node->child1()).value();
438         if (std::optional<double> number = child.toNumberFromPrimitive()) {
439             setConstant(node, jsDoubleNumber(*number));
440             break;
441         }
442
443         SpeculatedType type = forNode(node->child1()).m_type;
444         switch (node->child1().useKind()) {
445         case NotCellUse: {
446             if (type & SpecOther) {
447                 type &= ~SpecOther;
448                 type |= SpecDoublePureNaN | SpecBoolInt32; // Null becomes zero, undefined becomes NaN.
449             }
450             if (type & SpecBoolean) {
451                 type &= ~SpecBoolean;
452                 type |= SpecBoolInt32; // True becomes 1, false becomes 0.
453             }
454             type &= SpecBytecodeNumber;
455             break;
456         }
457
458         case Int52RepUse:
459         case NumberUse:
460         case RealNumberUse:
461             break;
462
463         default:
464             RELEASE_ASSERT_NOT_REACHED();
465         }
466         forNode(node).setType(type);
467         forNode(node).fixTypeForRepresentation(m_graph, node);
468         break;
469     }
470         
471     case Int52Rep: {
472         JSValue child = forNode(node->child1()).value();
473         if (child && child.isAnyInt()) {
474             setConstant(node, child);
475             break;
476         }
477         
478         forNode(node).setType(SpecInt32Only);
479         break;
480     }
481         
482     case ValueRep: {
483         JSValue value = forNode(node->child1()).value();
484         if (value) {
485             setConstant(node, value);
486             break;
487         }
488         
489         forNode(node).setType(m_graph, forNode(node->child1()).m_type & ~SpecDoubleImpureNaN);
490         forNode(node).fixTypeForRepresentation(m_graph, node);
491         break;
492     }
493         
494     case ValueAdd: {
495         ASSERT(node->binaryUseKind() == UntypedUse);
496         clobberWorld(node->origin.semantic, clobberLimit);
497         forNode(node).setType(m_graph, SpecString | SpecBytecodeNumber);
498         break;
499     }
500
501     case StrCat: {
502         forNode(node).setType(m_graph, SpecString);
503         break;
504     }
505         
506     case ArithAdd: {
507         JSValue left = forNode(node->child1()).value();
508         JSValue right = forNode(node->child2()).value();
509         switch (node->binaryUseKind()) {
510         case Int32Use:
511             if (left && right && left.isInt32() && right.isInt32()) {
512                 if (!shouldCheckOverflow(node->arithMode())) {
513                     setConstant(node, jsNumber(left.asInt32() + right.asInt32()));
514                     break;
515                 }
516                 JSValue result = jsNumber(left.asNumber() + right.asNumber());
517                 if (result.isInt32()) {
518                     setConstant(node, result);
519                     break;
520                 }
521             }
522             forNode(node).setType(SpecInt32Only);
523             break;
524         case Int52RepUse:
525             if (left && right && left.isAnyInt() && right.isAnyInt()) {
526                 JSValue result = jsNumber(left.asAnyInt() + right.asAnyInt());
527                 if (result.isAnyInt()) {
528                     setConstant(node, result);
529                     break;
530                 }
531             }
532             forNode(node).setType(SpecAnyInt);
533             break;
534         case DoubleRepUse:
535             if (left && right && left.isNumber() && right.isNumber()) {
536                 setConstant(node, jsDoubleNumber(left.asNumber() + right.asNumber()));
537                 break;
538             }
539             forNode(node).setType(
540                 typeOfDoubleSum(
541                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
542             break;
543         default:
544             RELEASE_ASSERT_NOT_REACHED();
545             break;
546         }
547         break;
548     }
549
550     case ArithClz32: {
551         JSValue operand = forNode(node->child1()).value();
552         if (std::optional<double> number = operand.toNumberFromPrimitive()) {
553             uint32_t value = toUInt32(*number);
554             setConstant(node, jsNumber(clz32(value)));
555             break;
556         }
557         forNode(node).setType(SpecInt32Only);
558         break;
559     }
560
561     case MakeRope: {
562         forNode(node).set(m_graph, m_vm.stringStructure.get());
563         break;
564     }
565             
566     case ArithSub: {
567         JSValue left = forNode(node->child1()).value();
568         JSValue right = forNode(node->child2()).value();
569         switch (node->binaryUseKind()) {
570         case Int32Use:
571             if (left && right && left.isInt32() && right.isInt32()) {
572                 if (!shouldCheckOverflow(node->arithMode())) {
573                     setConstant(node, jsNumber(left.asInt32() - right.asInt32()));
574                     break;
575                 }
576                 JSValue result = jsNumber(left.asNumber() - right.asNumber());
577                 if (result.isInt32()) {
578                     setConstant(node, result);
579                     break;
580                 }
581             }
582             forNode(node).setType(SpecInt32Only);
583             break;
584         case Int52RepUse:
585             if (left && right && left.isAnyInt() && right.isAnyInt()) {
586                 JSValue result = jsNumber(left.asAnyInt() - right.asAnyInt());
587                 if (result.isAnyInt() || !shouldCheckOverflow(node->arithMode())) {
588                     setConstant(node, result);
589                     break;
590                 }
591             }
592             forNode(node).setType(SpecAnyInt);
593             break;
594         case DoubleRepUse:
595             if (left && right && left.isNumber() && right.isNumber()) {
596                 setConstant(node, jsDoubleNumber(left.asNumber() - right.asNumber()));
597                 break;
598             }
599             forNode(node).setType(
600                 typeOfDoubleDifference(
601                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
602             break;
603         case UntypedUse:
604             clobberWorld(node->origin.semantic, clobberLimit);
605             forNode(node).setType(m_graph, SpecBytecodeNumber);
606             break;
607         default:
608             RELEASE_ASSERT_NOT_REACHED();
609             break;
610         }
611         break;
612     }
613         
614     case ArithNegate: {
615         JSValue child = forNode(node->child1()).value();
616         switch (node->child1().useKind()) {
617         case Int32Use:
618             if (child && child.isInt32()) {
619                 if (!shouldCheckOverflow(node->arithMode())) {
620                     setConstant(node, jsNumber(-child.asInt32()));
621                     break;
622                 }
623                 double doubleResult;
624                 if (shouldCheckNegativeZero(node->arithMode()))
625                     doubleResult = -child.asNumber();
626                 else
627                     doubleResult = 0 - child.asNumber();
628                 JSValue valueResult = jsNumber(doubleResult);
629                 if (valueResult.isInt32()) {
630                     setConstant(node, valueResult);
631                     break;
632                 }
633             }
634             forNode(node).setType(SpecInt32Only);
635             break;
636         case Int52RepUse:
637             if (child && child.isAnyInt()) {
638                 double doubleResult;
639                 if (shouldCheckNegativeZero(node->arithMode()))
640                     doubleResult = -child.asNumber();
641                 else
642                     doubleResult = 0 - child.asNumber();
643                 JSValue valueResult = jsNumber(doubleResult);
644                 if (valueResult.isAnyInt()) {
645                     setConstant(node, valueResult);
646                     break;
647                 }
648             }
649             forNode(node).setType(SpecAnyInt);
650             break;
651         case DoubleRepUse:
652             if (child && child.isNumber()) {
653                 setConstant(node, jsDoubleNumber(-child.asNumber()));
654                 break;
655             }
656             forNode(node).setType(
657                 typeOfDoubleNegation(
658                     forNode(node->child1()).m_type));
659             break;
660         default:
661             DFG_ASSERT(m_graph, node, node->child1().useKind() == UntypedUse);
662             forNode(node).setType(SpecBytecodeNumber);
663             break;
664         }
665         break;
666     }
667         
668     case ArithMul: {
669         JSValue left = forNode(node->child1()).value();
670         JSValue right = forNode(node->child2()).value();
671         switch (node->binaryUseKind()) {
672         case Int32Use:
673             if (left && right && left.isInt32() && right.isInt32()) {
674                 if (!shouldCheckOverflow(node->arithMode())) {
675                     setConstant(node, jsNumber(left.asInt32() * right.asInt32()));
676                     break;
677                 }
678                 double doubleResult = left.asNumber() * right.asNumber();
679                 if (!shouldCheckNegativeZero(node->arithMode()))
680                     doubleResult += 0; // Sanitizes zero.
681                 JSValue valueResult = jsNumber(doubleResult);
682                 if (valueResult.isInt32()) {
683                     setConstant(node, valueResult);
684                     break;
685                 }
686             }
687             forNode(node).setType(SpecInt32Only);
688             break;
689         case Int52RepUse:
690             if (left && right && left.isAnyInt() && right.isAnyInt()) {
691                 double doubleResult = left.asNumber() * right.asNumber();
692                 if (!shouldCheckNegativeZero(node->arithMode()))
693                     doubleResult += 0;
694                 JSValue valueResult = jsNumber(doubleResult);
695                 if (valueResult.isAnyInt()) {
696                     setConstant(node, valueResult);
697                     break;
698                 }
699             }
700             forNode(node).setType(SpecAnyInt);
701             break;
702         case DoubleRepUse:
703             if (left && right && left.isNumber() && right.isNumber()) {
704                 setConstant(node, jsDoubleNumber(left.asNumber() * right.asNumber()));
705                 break;
706             }
707             forNode(node).setType(
708                 typeOfDoubleProduct(
709                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
710             break;
711         case UntypedUse:
712             clobberWorld(node->origin.semantic, clobberLimit);
713             forNode(node).setType(m_graph, SpecBytecodeNumber);
714             break;
715         default:
716             RELEASE_ASSERT_NOT_REACHED();
717             break;
718         }
719         break;
720     }
721         
722     case ArithDiv: {
723         JSValue left = forNode(node->child1()).value();
724         JSValue right = forNode(node->child2()).value();
725         switch (node->binaryUseKind()) {
726         case Int32Use:
727             if (left && right && left.isInt32() && right.isInt32()) {
728                 double doubleResult = left.asNumber() / right.asNumber();
729                 if (!shouldCheckOverflow(node->arithMode()))
730                     doubleResult = toInt32(doubleResult);
731                 else if (!shouldCheckNegativeZero(node->arithMode()))
732                     doubleResult += 0; // Sanitizes zero.
733                 JSValue valueResult = jsNumber(doubleResult);
734                 if (valueResult.isInt32()) {
735                     setConstant(node, valueResult);
736                     break;
737                 }
738             }
739             forNode(node).setType(SpecInt32Only);
740             break;
741         case DoubleRepUse:
742             if (left && right && left.isNumber() && right.isNumber()) {
743                 setConstant(node, jsDoubleNumber(left.asNumber() / right.asNumber()));
744                 break;
745             }
746             forNode(node).setType(
747                 typeOfDoubleQuotient(
748                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
749             break;
750         case UntypedUse:
751             clobberWorld(node->origin.semantic, clobberLimit);
752             forNode(node).setType(m_graph, SpecBytecodeNumber);
753             break;
754         default:
755             RELEASE_ASSERT_NOT_REACHED();
756             break;
757         }
758         break;
759     }
760
761     case ArithMod: {
762         JSValue left = forNode(node->child1()).value();
763         JSValue right = forNode(node->child2()).value();
764         switch (node->binaryUseKind()) {
765         case Int32Use:
766             if (left && right && left.isInt32() && right.isInt32()) {
767                 double doubleResult = fmod(left.asNumber(), right.asNumber());
768                 if (!shouldCheckOverflow(node->arithMode()))
769                     doubleResult = toInt32(doubleResult);
770                 else if (!shouldCheckNegativeZero(node->arithMode()))
771                     doubleResult += 0; // Sanitizes zero.
772                 JSValue valueResult = jsNumber(doubleResult);
773                 if (valueResult.isInt32()) {
774                     setConstant(node, valueResult);
775                     break;
776                 }
777             }
778             forNode(node).setType(SpecInt32Only);
779             break;
780         case DoubleRepUse:
781             if (left && right && left.isNumber() && right.isNumber()) {
782                 setConstant(node, jsDoubleNumber(fmod(left.asNumber(), right.asNumber())));
783                 break;
784             }
785             forNode(node).setType(
786                 typeOfDoubleBinaryOp(
787                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
788             break;
789         default:
790             RELEASE_ASSERT_NOT_REACHED();
791             break;
792         }
793         break;
794     }
795
796     case ArithMin: {
797         JSValue left = forNode(node->child1()).value();
798         JSValue right = forNode(node->child2()).value();
799         switch (node->binaryUseKind()) {
800         case Int32Use:
801             if (left && right && left.isInt32() && right.isInt32()) {
802                 setConstant(node, jsNumber(std::min(left.asInt32(), right.asInt32())));
803                 break;
804             }
805             forNode(node).setType(SpecInt32Only);
806             break;
807         case DoubleRepUse:
808             if (left && right && left.isNumber() && right.isNumber()) {
809                 double a = left.asNumber();
810                 double b = right.asNumber();
811                 setConstant(node, jsDoubleNumber(a < b ? a : (b <= a ? b : a + b)));
812                 break;
813             }
814             forNode(node).setType(
815                 typeOfDoubleMinMax(
816                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
817             break;
818         default:
819             RELEASE_ASSERT_NOT_REACHED();
820             break;
821         }
822         break;
823     }
824             
825     case ArithMax: {
826         JSValue left = forNode(node->child1()).value();
827         JSValue right = forNode(node->child2()).value();
828         switch (node->binaryUseKind()) {
829         case Int32Use:
830             if (left && right && left.isInt32() && right.isInt32()) {
831                 setConstant(node, jsNumber(std::max(left.asInt32(), right.asInt32())));
832                 break;
833             }
834             forNode(node).setType(SpecInt32Only);
835             break;
836         case DoubleRepUse:
837             if (left && right && left.isNumber() && right.isNumber()) {
838                 double a = left.asNumber();
839                 double b = right.asNumber();
840                 setConstant(node, jsDoubleNumber(a > b ? a : (b >= a ? b : a + b)));
841                 break;
842             }
843             forNode(node).setType(
844                 typeOfDoubleMinMax(
845                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
846             break;
847         default:
848             RELEASE_ASSERT_NOT_REACHED();
849             break;
850         }
851         break;
852     }
853             
854     case ArithAbs: {
855         JSValue child = forNode(node->child1()).value();
856         switch (node->child1().useKind()) {
857         case Int32Use:
858             if (std::optional<double> number = child.toNumberFromPrimitive()) {
859                 JSValue result = jsNumber(fabs(*number));
860                 if (result.isInt32()) {
861                     setConstant(node, result);
862                     break;
863                 }
864             }
865             forNode(node).setType(SpecInt32Only);
866             break;
867         case DoubleRepUse:
868             if (std::optional<double> number = child.toNumberFromPrimitive()) {
869                 setConstant(node, jsDoubleNumber(fabs(*number)));
870                 break;
871             }
872             forNode(node).setType(typeOfDoubleAbs(forNode(node->child1()).m_type));
873             break;
874         default:
875             DFG_ASSERT(m_graph, node, node->child1().useKind() == UntypedUse);
876             forNode(node).setType(SpecFullNumber);
877             break;
878         }
879         break;
880     }
881
882     case ArithPow: {
883         JSValue childY = forNode(node->child2()).value();
884         if (childY && childY.isNumber()) {
885             if (!childY.asNumber()) {
886                 setConstant(node, jsDoubleNumber(1));
887                 break;
888             }
889
890             JSValue childX = forNode(node->child1()).value();
891             if (childX && childX.isNumber()) {
892                 setConstant(node, jsDoubleNumber(operationMathPow(childX.asNumber(), childY.asNumber())));
893                 break;
894             }
895         }
896         forNode(node).setType(typeOfDoublePow(forNode(node->child1()).m_type, forNode(node->child2()).m_type));
897         break;
898     }
899
900     case ArithRandom: {
901         forNode(node).setType(m_graph, SpecDoubleReal);
902         break;
903     }
904
905     case ArithRound:
906     case ArithFloor:
907     case ArithCeil:
908     case ArithTrunc: {
909         JSValue operand = forNode(node->child1()).value();
910         if (std::optional<double> number = operand.toNumberFromPrimitive()) {
911             double roundedValue = 0;
912             if (node->op() == ArithRound)
913                 roundedValue = jsRound(*number);
914             else if (node->op() == ArithFloor)
915                 roundedValue = floor(*number);
916             else if (node->op() == ArithCeil)
917                 roundedValue = ceil(*number);
918             else {
919                 ASSERT(node->op() == ArithTrunc);
920                 roundedValue = trunc(*number);
921             }
922
923             if (node->child1().useKind() == UntypedUse) {
924                 setConstant(node, jsNumber(roundedValue));
925                 break;
926             }
927             if (producesInteger(node->arithRoundingMode())) {
928                 int32_t roundedValueAsInt32 = static_cast<int32_t>(roundedValue);
929                 if (roundedValueAsInt32 == roundedValue) {
930                     if (shouldCheckNegativeZero(node->arithRoundingMode())) {
931                         if (roundedValueAsInt32 || !std::signbit(roundedValue)) {
932                             setConstant(node, jsNumber(roundedValueAsInt32));
933                             break;
934                         }
935                     } else {
936                         setConstant(node, jsNumber(roundedValueAsInt32));
937                         break;
938                     }
939                 }
940             } else {
941                 setConstant(node, jsDoubleNumber(roundedValue));
942                 break;
943             }
944         }
945         if (node->child1().useKind() == DoubleRepUse) {
946             if (producesInteger(node->arithRoundingMode()))
947                 forNode(node).setType(SpecInt32Only);
948             else if (node->child1().useKind() == DoubleRepUse)
949                 forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
950         } else {
951             DFG_ASSERT(m_graph, node, node->child1().useKind() == UntypedUse);
952             forNode(node).setType(SpecFullNumber);
953         }
954         break;
955     }
956             
957     case ArithSqrt:
958         executeDoubleUnaryOpEffects(node, sqrt);
959         break;
960
961     case ArithFRound:
962         executeDoubleUnaryOpEffects(node, [](double value) -> double { return static_cast<float>(value); });
963         break;
964         
965     case ArithSin:
966         executeDoubleUnaryOpEffects(node, sin);
967         break;
968     
969     case ArithCos:
970         executeDoubleUnaryOpEffects(node, cos);
971         break;
972
973     case ArithTan:
974         executeDoubleUnaryOpEffects(node, tan);
975         break;
976
977     case ArithLog:
978         executeDoubleUnaryOpEffects(node, log);
979         break;
980             
981     case LogicalNot: {
982         switch (booleanResult(node, forNode(node->child1()))) {
983         case DefinitelyTrue:
984             setConstant(node, jsBoolean(false));
985             break;
986         case DefinitelyFalse:
987             setConstant(node, jsBoolean(true));
988             break;
989         default:
990             forNode(node).setType(SpecBoolean);
991             break;
992         }
993         break;
994     }
995
996     case MapHash: {
997         if (JSValue key = forNode(node->child1()).value()) {
998             if (std::optional<uint32_t> hash = concurrentJSMapHash(key)) {
999                 // Although C++ code uses uint32_t for the hash, the closest type in DFG IR is Int32
1000                 // and that's what MapHash returns. So, we have to cast to int32_t to avoid large
1001                 // unsigned values becoming doubles. This casting between signed and unsigned
1002                 // happens in the assembly code we emit when we don't constant fold this node.
1003                 setConstant(node, jsNumber(static_cast<int32_t>(*hash)));
1004                 break;
1005             }
1006         }
1007         forNode(node).setType(SpecInt32Only);
1008         break;
1009     }
1010
1011     case ToLowerCase: {
1012         forNode(node).setType(m_graph, SpecString);
1013         break;
1014     }
1015
1016     case LoadFromJSMapBucket:
1017         forNode(node).makeHeapTop();
1018         break;
1019
1020     case GetMapBucket:
1021         forNode(node).setType(m_graph, SpecCellOther);
1022         break;
1023
1024     case IsNonEmptyMapBucket:
1025         forNode(node).setType(SpecBoolean);
1026         break;
1027
1028     case IsEmpty:
1029     case IsUndefined:
1030     case IsBoolean:
1031     case IsNumber:
1032     case IsObject:
1033     case IsObjectOrNull:
1034     case IsFunction:
1035     case IsCellWithType:
1036     case IsTypedArrayView: {
1037         AbstractValue child = forNode(node->child1());
1038         if (child.value()) {
1039             bool constantWasSet = true;
1040             switch (node->op()) {
1041             case IsCellWithType:
1042                 setConstant(node, jsBoolean(child.value().isCell() && child.value().asCell()->type() == node->queriedType()));
1043                 break;
1044             case IsUndefined:
1045                 setConstant(node, jsBoolean(
1046                     child.value().isCell()
1047                     ? child.value().asCell()->structure()->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
1048                     : child.value().isUndefined()));
1049                 break;
1050             case IsBoolean:
1051                 setConstant(node, jsBoolean(child.value().isBoolean()));
1052                 break;
1053             case IsNumber:
1054                 setConstant(node, jsBoolean(child.value().isNumber()));
1055                 break;
1056             case IsObject:
1057                 setConstant(node, jsBoolean(child.value().isObject()));
1058                 break;
1059             case IsObjectOrNull:
1060                 if (child.value().isObject()) {
1061                     JSObject* object = asObject(child.value());
1062                     if (object->type() == JSFunctionType)
1063                         setConstant(node, jsBoolean(false));
1064                     else if (!(object->inlineTypeFlags() & TypeOfShouldCallGetCallData))
1065                         setConstant(node, jsBoolean(!child.value().asCell()->structure()->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))));
1066                     else {
1067                         // FIXME: This could just call getCallData.
1068                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1069                         constantWasSet = false;
1070                     }
1071                 } else
1072                     setConstant(node, jsBoolean(child.value().isNull()));
1073                 break;
1074             case IsFunction:
1075                 if (child.value().isObject()) {
1076                     JSObject* object = asObject(child.value());
1077                     if (object->type() == JSFunctionType)
1078                         setConstant(node, jsBoolean(true));
1079                     else if (!(object->inlineTypeFlags() & TypeOfShouldCallGetCallData))
1080                         setConstant(node, jsBoolean(false));
1081                     else {
1082                         // FIXME: This could just call getCallData.
1083                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1084                         constantWasSet = false;
1085                     }
1086                 } else
1087                     setConstant(node, jsBoolean(false));
1088                 break;
1089             case IsEmpty:
1090                 setConstant(node, jsBoolean(child.value().isEmpty()));
1091                 break;
1092             case IsTypedArrayView:
1093                 setConstant(node, jsBoolean(child.value().isObject() && isTypedView(child.value().getObject()->classInfo(m_vm)->typedArrayStorageType)));
1094                 break;
1095             default:
1096                 constantWasSet = false;
1097                 break;
1098             }
1099             if (constantWasSet)
1100                 break;
1101         }
1102         
1103         // FIXME: This code should really use AbstractValue::isType() and
1104         // AbstractValue::couldBeType().
1105         // https://bugs.webkit.org/show_bug.cgi?id=146870
1106         
1107         bool constantWasSet = false;
1108         switch (node->op()) {
1109         case IsEmpty: {
1110             if (child.m_type && !(child.m_type & SpecEmpty)) {
1111                 setConstant(node, jsBoolean(false));
1112                 constantWasSet = true;
1113                 break;
1114             }
1115
1116             if (child.m_type && !(child.m_type & ~SpecEmpty)) {
1117                 setConstant(node, jsBoolean(true));
1118                 constantWasSet = true;
1119                 break;
1120             }
1121
1122             break;
1123         }
1124         case IsUndefined:
1125             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1126             // https://bugs.webkit.org/show_bug.cgi?id=144456
1127             
1128             if (!(child.m_type & (SpecOther | SpecObjectOther))) {
1129                 setConstant(node, jsBoolean(false));
1130                 constantWasSet = true;
1131                 break;
1132             }
1133             
1134             break;
1135         case IsBoolean:
1136             if (!(child.m_type & ~SpecBoolean)) {
1137                 setConstant(node, jsBoolean(true));
1138                 constantWasSet = true;
1139                 break;
1140             }
1141             
1142             if (!(child.m_type & SpecBoolean)) {
1143                 setConstant(node, jsBoolean(false));
1144                 constantWasSet = true;
1145                 break;
1146             }
1147             
1148             break;
1149         case IsNumber:
1150             if (!(child.m_type & ~SpecFullNumber)) {
1151                 setConstant(node, jsBoolean(true));
1152                 constantWasSet = true;
1153                 break;
1154             }
1155             
1156             if (!(child.m_type & SpecFullNumber)) {
1157                 setConstant(node, jsBoolean(false));
1158                 constantWasSet = true;
1159                 break;
1160             }
1161             
1162             break;
1163         case IsObject:
1164             if (!(child.m_type & ~SpecObject)) {
1165                 setConstant(node, jsBoolean(true));
1166                 constantWasSet = true;
1167                 break;
1168             }
1169             
1170             if (!(child.m_type & SpecObject)) {
1171                 setConstant(node, jsBoolean(false));
1172                 constantWasSet = true;
1173                 break;
1174             }
1175             
1176             break;
1177         case IsObjectOrNull:
1178             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1179             // https://bugs.webkit.org/show_bug.cgi?id=144456
1180             
1181             // These expressions are complicated to parse. A helpful way to parse this is that
1182             // "!(T & ~S)" means "T is a subset of S". Conversely, "!(T & S)" means "T is a
1183             // disjoint set from S". Things like "T - S" means that, provided that S is a
1184             // subset of T, it's the "set of all things in T but not in S". Things like "T | S"
1185             // mean the "union of T and S".
1186             
1187             // Is the child's type an object that isn't an other-object (i.e. object that could
1188             // have masquaredes-as-undefined traps) and isn't a function?  Then: we should fold
1189             // this to true.
1190             if (!(child.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1191                 setConstant(node, jsBoolean(true));
1192                 constantWasSet = true;
1193                 break;
1194             }
1195             
1196             // Is the child's type definitely not either of: an object that isn't a function,
1197             // or either undefined or null?  Then: we should fold this to false.  This means
1198             // for example that if it's any non-function object, including those that have
1199             // masquerades-as-undefined traps, then we don't fold. It also means we won't fold
1200             // if it's undefined-or-null, since the type bits don't distinguish between
1201             // undefined (which should fold to false) and null (which should fold to true).
1202             if (!(child.m_type & ((SpecObject - SpecFunction) | SpecOther))) {
1203                 setConstant(node, jsBoolean(false));
1204                 constantWasSet = true;
1205                 break;
1206             }
1207             
1208             break;
1209         case IsFunction:
1210             if (!(child.m_type & ~SpecFunction)) {
1211                 setConstant(node, jsBoolean(true));
1212                 constantWasSet = true;
1213                 break;
1214             }
1215             
1216             if (!(child.m_type & (SpecFunction | SpecObjectOther | SpecProxyObject))) {
1217                 setConstant(node, jsBoolean(false));
1218                 constantWasSet = true;
1219                 break;
1220             }
1221             break;
1222
1223         case IsCellWithType:
1224             if (!(child.m_type & ~node->speculatedTypeForQuery())) {
1225                 setConstant(node, jsBoolean(true));
1226                 constantWasSet = true;
1227                 break;
1228             }
1229             if (!(child.m_type & node->speculatedTypeForQuery())) {
1230                 setConstant(node, jsBoolean(false));
1231                 constantWasSet = true;
1232                 break;
1233             }
1234             break;
1235
1236         case IsTypedArrayView:
1237             if (!(child.m_type & ~SpecTypedArrayView)) {
1238                 setConstant(node, jsBoolean(true));
1239                 constantWasSet = true;
1240                 break;
1241             }
1242             if (!(child.m_type & SpecTypedArrayView)) {
1243                 setConstant(node, jsBoolean(false));
1244                 constantWasSet = true;
1245                 break;
1246             }
1247             break;
1248
1249         default:
1250             break;
1251         }
1252         if (constantWasSet)
1253             break;
1254         
1255         forNode(node).setType(SpecBoolean);
1256         break;
1257     }
1258
1259     case TypeOf: {
1260         JSValue child = forNode(node->child1()).value();
1261         AbstractValue& abstractChild = forNode(node->child1());
1262         if (child) {
1263             JSValue typeString = jsTypeStringForValue(m_vm, m_codeBlock->globalObjectFor(node->origin.semantic), child);
1264             setConstant(node, *m_graph.freeze(typeString));
1265             break;
1266         }
1267         
1268         if (isFullNumberSpeculation(abstractChild.m_type)) {
1269             setConstant(node, *m_graph.freeze(m_vm.smallStrings.numberString()));
1270             break;
1271         }
1272         
1273         if (isStringSpeculation(abstractChild.m_type)) {
1274             setConstant(node, *m_graph.freeze(m_vm.smallStrings.stringString()));
1275             break;
1276         }
1277
1278         // FIXME: We could use the masquerades-as-undefined watchpoint here.
1279         // https://bugs.webkit.org/show_bug.cgi?id=144456
1280         if (!(abstractChild.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1281             setConstant(node, *m_graph.freeze(m_vm.smallStrings.objectString()));
1282             break;
1283         }
1284         
1285         if (isFunctionSpeculation(abstractChild.m_type)) {
1286             setConstant(node, *m_graph.freeze(m_vm.smallStrings.functionString()));
1287             break;
1288         }
1289         
1290         if (isBooleanSpeculation(abstractChild.m_type)) {
1291             setConstant(node, *m_graph.freeze(m_vm.smallStrings.booleanString()));
1292             break;
1293         }
1294
1295         if (isSymbolSpeculation(abstractChild.m_type)) {
1296             setConstant(node, *m_graph.freeze(m_vm.smallStrings.symbolString()));
1297             break;
1298         }
1299
1300         forNode(node).setType(m_graph, SpecStringIdent);
1301         break;
1302     }
1303             
1304     case CompareLess:
1305     case CompareLessEq:
1306     case CompareGreater:
1307     case CompareGreaterEq:
1308     case CompareEq: {
1309         JSValue leftConst = forNode(node->child1()).value();
1310         JSValue rightConst = forNode(node->child2()).value();
1311         if (leftConst && rightConst) {
1312             if (leftConst.isNumber() && rightConst.isNumber()) {
1313                 double a = leftConst.asNumber();
1314                 double b = rightConst.asNumber();
1315                 switch (node->op()) {
1316                 case CompareLess:
1317                     setConstant(node, jsBoolean(a < b));
1318                     break;
1319                 case CompareLessEq:
1320                     setConstant(node, jsBoolean(a <= b));
1321                     break;
1322                 case CompareGreater:
1323                     setConstant(node, jsBoolean(a > b));
1324                     break;
1325                 case CompareGreaterEq:
1326                     setConstant(node, jsBoolean(a >= b));
1327                     break;
1328                 case CompareEq:
1329                     setConstant(node, jsBoolean(a == b));
1330                     break;
1331                 default:
1332                     RELEASE_ASSERT_NOT_REACHED();
1333                     break;
1334                 }
1335                 break;
1336             }
1337             
1338             if (leftConst.isString() && rightConst.isString()) {
1339                 const StringImpl* a = asString(leftConst)->tryGetValueImpl();
1340                 const StringImpl* b = asString(rightConst)->tryGetValueImpl();
1341                 if (a && b) {
1342                     bool result;
1343                     if (node->op() == CompareEq)
1344                         result = WTF::equal(a, b);
1345                     else if (node->op() == CompareLess)
1346                         result = codePointCompare(a, b) < 0;
1347                     else if (node->op() == CompareLessEq)
1348                         result = codePointCompare(a, b) <= 0;
1349                     else if (node->op() == CompareGreater)
1350                         result = codePointCompare(a, b) > 0;
1351                     else if (node->op() == CompareGreaterEq)
1352                         result = codePointCompare(a, b) >= 0;
1353                     else
1354                         RELEASE_ASSERT_NOT_REACHED();
1355                     setConstant(node, jsBoolean(result));
1356                     break;
1357                 }
1358             }
1359
1360             if (node->op() == CompareEq && leftConst.isSymbol() && rightConst.isSymbol()) {
1361                 setConstant(node, jsBoolean(asSymbol(leftConst) == asSymbol(rightConst)));
1362                 break;
1363             }
1364         }
1365         
1366         if (node->op() == CompareEq) {
1367             SpeculatedType leftType = forNode(node->child1()).m_type;
1368             SpeculatedType rightType = forNode(node->child2()).m_type;
1369             if (!valuesCouldBeEqual(leftType, rightType)) {
1370                 setConstant(node, jsBoolean(false));
1371                 break;
1372             }
1373
1374             if (leftType == SpecOther)
1375                 std::swap(leftType, rightType);
1376             if (rightType == SpecOther) {
1377                 // Undefined and Null are always equal when compared to eachother.
1378                 if (!(leftType & ~SpecOther)) {
1379                     setConstant(node, jsBoolean(true));
1380                     break;
1381                 }
1382
1383                 // Any other type compared to Null or Undefined is always false
1384                 // as long as the MasqueradesAsUndefined watchpoint is valid.
1385                 //
1386                 // MasqueradesAsUndefined only matters for SpecObjectOther, other
1387                 // cases are always "false".
1388                 if (!(leftType & (SpecObjectOther | SpecOther))) {
1389                     setConstant(node, jsBoolean(false));
1390                     break;
1391                 }
1392
1393                 if (!(leftType & SpecOther) && m_graph.masqueradesAsUndefinedWatchpointIsStillValid(node->origin.semantic)) {
1394                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1395                     m_graph.watchpoints().addLazily(globalObject->masqueradesAsUndefinedWatchpoint());
1396                     setConstant(node, jsBoolean(false));
1397                     break;
1398                 }
1399             }
1400         }
1401         
1402         if (node->child1() == node->child2()) {
1403             if (node->isBinaryUseKind(Int32Use) ||
1404                 node->isBinaryUseKind(Int52RepUse) ||
1405                 node->isBinaryUseKind(StringUse) ||
1406                 node->isBinaryUseKind(BooleanUse) ||
1407                 node->isBinaryUseKind(SymbolUse) ||
1408                 node->isBinaryUseKind(StringIdentUse) ||
1409                 node->isBinaryUseKind(ObjectUse) ||
1410                 node->isBinaryUseKind(ObjectUse, ObjectOrOtherUse) ||
1411                 node->isBinaryUseKind(ObjectOrOtherUse, ObjectUse)) {
1412                 switch (node->op()) {
1413                 case CompareLess:
1414                 case CompareGreater:
1415                     setConstant(node, jsBoolean(false));
1416                     break;
1417                 case CompareLessEq:
1418                 case CompareGreaterEq:
1419                 case CompareEq:
1420                     setConstant(node, jsBoolean(true));
1421                     break;
1422                 default:
1423                     DFG_CRASH(m_graph, node, "Unexpected node type");
1424                     break;
1425                 }
1426                 break;
1427             }
1428         }
1429         
1430         forNode(node).setType(SpecBoolean);
1431         break;
1432     }
1433             
1434     case CompareStrictEq: {
1435         Node* leftNode = node->child1().node();
1436         Node* rightNode = node->child2().node();
1437         JSValue left = forNode(leftNode).value();
1438         JSValue right = forNode(rightNode).value();
1439         if (left && right) {
1440             if (left.isString() && right.isString()) {
1441                 // We need this case because JSValue::strictEqual is otherwise too racy for
1442                 // string comparisons.
1443                 const StringImpl* a = asString(left)->tryGetValueImpl();
1444                 const StringImpl* b = asString(right)->tryGetValueImpl();
1445                 if (a && b) {
1446                     setConstant(node, jsBoolean(WTF::equal(a, b)));
1447                     break;
1448                 }
1449             } else {
1450                 setConstant(node, jsBoolean(JSValue::strictEqual(0, left, right)));
1451                 break;
1452             }
1453         }
1454         
1455         SpeculatedType leftLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(leftNode).m_type);
1456         SpeculatedType rightLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(rightNode).m_type);
1457         if (!(leftLUB & rightLUB)) {
1458             setConstant(node, jsBoolean(false));
1459             break;
1460         }
1461         
1462         if (node->child1() == node->child2()) {
1463             if (node->isBinaryUseKind(BooleanUse) ||
1464                 node->isBinaryUseKind(Int32Use) ||
1465                 node->isBinaryUseKind(Int52RepUse) ||
1466                 node->isBinaryUseKind(StringUse) ||
1467                 node->isBinaryUseKind(StringIdentUse) ||
1468                 node->isBinaryUseKind(SymbolUse) ||
1469                 node->isBinaryUseKind(ObjectUse) ||
1470                 node->isBinaryUseKind(MiscUse, UntypedUse) ||
1471                 node->isBinaryUseKind(UntypedUse, MiscUse) ||
1472                 node->isBinaryUseKind(StringIdentUse, NotStringVarUse) ||
1473                 node->isBinaryUseKind(NotStringVarUse, StringIdentUse) ||
1474                 node->isBinaryUseKind(StringUse, UntypedUse) ||
1475                 node->isBinaryUseKind(UntypedUse, StringUse)) {
1476                 setConstant(node, jsBoolean(true));
1477                 break;
1478             }
1479         }
1480
1481         forNode(node).setType(SpecBoolean);
1482         break;
1483     }
1484         
1485     case CompareEqPtr: {
1486         Node* childNode = node->child1().node();
1487         JSValue childValue = forNode(childNode).value();
1488         if (childValue) {
1489             setConstant(node, jsBoolean(childValue.isCell() && childValue.asCell() == node->cellOperand()->cell()));
1490             break;
1491         }
1492         
1493         forNode(node).setType(SpecBoolean);
1494         break;
1495     }
1496         
1497     case StringCharCodeAt:
1498         forNode(node).setType(SpecInt32Only);
1499         break;
1500         
1501     case StringFromCharCode:
1502         forNode(node).setType(m_graph, SpecString);
1503         break;
1504
1505     case StringCharAt:
1506         forNode(node).set(m_graph, m_vm.stringStructure.get());
1507         break;
1508             
1509     case GetByVal: {
1510         switch (node->arrayMode().type()) {
1511         case Array::SelectUsingPredictions:
1512         case Array::Unprofiled:
1513         case Array::SelectUsingArguments:
1514             RELEASE_ASSERT_NOT_REACHED();
1515             break;
1516         case Array::ForceExit:
1517             m_state.setIsValid(false);
1518             break;
1519         case Array::Undecided: {
1520             JSValue index = forNode(node->child2()).value();
1521             if (index && index.isInt32() && index.asInt32() >= 0) {
1522                 setConstant(node, jsUndefined());
1523                 break;
1524             }
1525             forNode(node).setType(SpecOther);
1526             break;
1527         }
1528         case Array::Generic:
1529             clobberWorld(node->origin.semantic, clobberLimit);
1530             forNode(node).makeHeapTop();
1531             break;
1532         case Array::String:
1533             if (node->arrayMode().isOutOfBounds()) {
1534                 // If the watchpoint was still valid we could totally set this to be
1535                 // SpecString | SpecOther. Except that we'd have to be careful. If we
1536                 // tested the watchpoint state here then it could change by the time
1537                 // we got to the backend. So to do this right, we'd have to get the
1538                 // fixup phase to check the watchpoint state and then bake into the
1539                 // GetByVal operation the fact that we're using a watchpoint, using
1540                 // something like Array::SaneChain (except not quite, because that
1541                 // implies an in-bounds access). None of this feels like it's worth it,
1542                 // so we're going with TOP for now. The same thing applies to
1543                 // clobbering the world.
1544                 clobberWorld(node->origin.semantic, clobberLimit);
1545                 forNode(node).makeHeapTop();
1546             } else
1547                 forNode(node).set(m_graph, m_vm.stringStructure.get());
1548             break;
1549         case Array::DirectArguments:
1550         case Array::ScopedArguments:
1551             forNode(node).makeHeapTop();
1552             break;
1553         case Array::Int32:
1554             if (node->arrayMode().isOutOfBounds()) {
1555                 clobberWorld(node->origin.semantic, clobberLimit);
1556                 forNode(node).makeHeapTop();
1557             } else
1558                 forNode(node).setType(SpecInt32Only);
1559             break;
1560         case Array::Double:
1561             if (node->arrayMode().isOutOfBounds()) {
1562                 clobberWorld(node->origin.semantic, clobberLimit);
1563                 forNode(node).makeHeapTop();
1564             } else if (node->arrayMode().isSaneChain())
1565                 forNode(node).setType(SpecBytecodeDouble);
1566             else
1567                 forNode(node).setType(SpecDoubleReal);
1568             break;
1569         case Array::Contiguous:
1570         case Array::ArrayStorage:
1571         case Array::SlowPutArrayStorage:
1572             if (node->arrayMode().isOutOfBounds())
1573                 clobberWorld(node->origin.semantic, clobberLimit);
1574             forNode(node).makeHeapTop();
1575             break;
1576         case Array::Int8Array:
1577             forNode(node).setType(SpecInt32Only);
1578             break;
1579         case Array::Int16Array:
1580             forNode(node).setType(SpecInt32Only);
1581             break;
1582         case Array::Int32Array:
1583             forNode(node).setType(SpecInt32Only);
1584             break;
1585         case Array::Uint8Array:
1586             forNode(node).setType(SpecInt32Only);
1587             break;
1588         case Array::Uint8ClampedArray:
1589             forNode(node).setType(SpecInt32Only);
1590             break;
1591         case Array::Uint16Array:
1592             forNode(node).setType(SpecInt32Only);
1593             break;
1594         case Array::Uint32Array:
1595             if (node->shouldSpeculateInt32())
1596                 forNode(node).setType(SpecInt32Only);
1597             else if (enableInt52() && node->shouldSpeculateAnyInt())
1598                 forNode(node).setType(SpecAnyInt);
1599             else
1600                 forNode(node).setType(SpecAnyIntAsDouble);
1601             break;
1602         case Array::Float32Array:
1603             forNode(node).setType(SpecFullDouble);
1604             break;
1605         case Array::Float64Array:
1606             forNode(node).setType(SpecFullDouble);
1607             break;
1608         default:
1609             RELEASE_ASSERT_NOT_REACHED();
1610             break;
1611         }
1612         break;
1613     }
1614             
1615     case PutByValDirect:
1616     case PutByVal:
1617     case PutByValAlias: {
1618         switch (node->arrayMode().modeForPut().type()) {
1619         case Array::ForceExit:
1620             m_state.setIsValid(false);
1621             break;
1622         case Array::Generic:
1623             clobberWorld(node->origin.semantic, clobberLimit);
1624             break;
1625         case Array::Int32:
1626             if (node->arrayMode().isOutOfBounds())
1627                 clobberWorld(node->origin.semantic, clobberLimit);
1628             break;
1629         case Array::Double:
1630             if (node->arrayMode().isOutOfBounds())
1631                 clobberWorld(node->origin.semantic, clobberLimit);
1632             break;
1633         case Array::Contiguous:
1634         case Array::ArrayStorage:
1635             if (node->arrayMode().isOutOfBounds())
1636                 clobberWorld(node->origin.semantic, clobberLimit);
1637             break;
1638         case Array::SlowPutArrayStorage:
1639             if (node->arrayMode().mayStoreToHole())
1640                 clobberWorld(node->origin.semantic, clobberLimit);
1641             break;
1642         default:
1643             break;
1644         }
1645         break;
1646     }
1647             
1648     case ArrayPush:
1649         clobberWorld(node->origin.semantic, clobberLimit);
1650         forNode(node).setType(SpecBytecodeNumber);
1651         break;
1652
1653     case ArraySlice: {
1654         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1655
1656         // FIXME: We could do better here if we prove that the
1657         // incoming value has only a single structure.
1658         RegisteredStructureSet structureSet;
1659         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithInt32)));
1660         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithContiguous)));
1661         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithDouble)));
1662
1663         forNode(node).set(m_graph, structureSet);
1664         break;
1665     }
1666             
1667     case ArrayPop:
1668         clobberWorld(node->origin.semantic, clobberLimit);
1669         forNode(node).makeHeapTop();
1670         break;
1671         
1672     case GetMyArgumentByVal:
1673     case GetMyArgumentByValOutOfBounds: {
1674         JSValue index = forNode(node->child2()).m_value;
1675         InlineCallFrame* inlineCallFrame = node->child1()->origin.semantic.inlineCallFrame;
1676
1677         if (index && index.isInt32()) {
1678             // This pretends to return TOP for accesses that are actually proven out-of-bounds because
1679             // that's the conservative thing to do. Otherwise we'd need to write more code to mark such
1680             // paths as unreachable, or to return undefined. We could implement that eventually.
1681             
1682             unsigned argumentIndex = index.asUInt32() + node->numberOfArgumentsToSkip();
1683             if (inlineCallFrame) {
1684                 if (argumentIndex < inlineCallFrame->arguments.size() - 1) {
1685                     forNode(node) = m_state.variables().operand(
1686                         virtualRegisterForArgument(argumentIndex + 1) + inlineCallFrame->stackOffset);
1687                     m_state.setFoundConstants(true);
1688                     break;
1689                 }
1690             } else {
1691                 if (argumentIndex < m_state.variables().numberOfArguments() - 1) {
1692                     forNode(node) = m_state.variables().argument(argumentIndex + 1);
1693                     m_state.setFoundConstants(true);
1694                     break;
1695                 }
1696             }
1697         }
1698         
1699         if (inlineCallFrame) {
1700             // We have a bound on the types even though it's random access. Take advantage of this.
1701             
1702             AbstractValue result;
1703             for (unsigned i = 1 + node->numberOfArgumentsToSkip(); i < inlineCallFrame->arguments.size(); ++i) {
1704                 result.merge(
1705                     m_state.variables().operand(
1706                         virtualRegisterForArgument(i) + inlineCallFrame->stackOffset));
1707             }
1708             
1709             if (node->op() == GetMyArgumentByValOutOfBounds)
1710                 result.merge(SpecOther);
1711             
1712             if (result.value())
1713                 m_state.setFoundConstants(true);
1714             
1715             forNode(node) = result;
1716             break;
1717         }
1718         
1719         forNode(node).makeHeapTop();
1720         break;
1721     }
1722             
1723     case RegExpExec:
1724         if (node->child2().useKind() == RegExpObjectUse
1725             && node->child3().useKind() == StringUse) {
1726             // This doesn't clobber the world since there are no conversions to perform.
1727         } else
1728             clobberWorld(node->origin.semantic, clobberLimit);
1729         if (JSValue globalObjectValue = forNode(node->child1()).m_value) {
1730             if (JSGlobalObject* globalObject = jsDynamicCast<JSGlobalObject*>(m_vm, globalObjectValue)) {
1731                 if (!globalObject->isHavingABadTime()) {
1732                     m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
1733                     Structure* structure = globalObject->regExpMatchesArrayStructure();
1734                     m_graph.registerStructure(structure);
1735                     forNode(node).set(m_graph, structure);
1736                     forNode(node).merge(SpecOther);
1737                     break;
1738                 }
1739             }
1740         }
1741         forNode(node).setType(m_graph, SpecOther | SpecArray);
1742         break;
1743
1744     case RegExpTest:
1745         if (node->child2().useKind() == RegExpObjectUse
1746             && node->child3().useKind() == StringUse) {
1747             // This doesn't clobber the world since there are no conversions to perform.
1748         } else
1749             clobberWorld(node->origin.semantic, clobberLimit);
1750         forNode(node).setType(SpecBoolean);
1751         break;
1752             
1753     case StringReplace:
1754     case StringReplaceRegExp:
1755         if (node->child1().useKind() == StringUse
1756             && node->child2().useKind() == RegExpObjectUse
1757             && node->child3().useKind() == StringUse) {
1758             // This doesn't clobber the world. It just reads and writes regexp state.
1759         } else
1760             clobberWorld(node->origin.semantic, clobberLimit);
1761         forNode(node).set(m_graph, m_vm.stringStructure.get());
1762         break;
1763
1764     case Jump:
1765         break;
1766             
1767     case Branch: {
1768         Node* child = node->child1().node();
1769         BooleanResult result = booleanResult(node, forNode(child));
1770         if (result == DefinitelyTrue) {
1771             m_state.setBranchDirection(TakeTrue);
1772             break;
1773         }
1774         if (result == DefinitelyFalse) {
1775             m_state.setBranchDirection(TakeFalse);
1776             break;
1777         }
1778         // FIXME: The above handles the trivial cases of sparse conditional
1779         // constant propagation, but we can do better:
1780         // We can specialize the source variable's value on each direction of
1781         // the branch.
1782         m_state.setBranchDirection(TakeBoth);
1783         break;
1784     }
1785         
1786     case Switch: {
1787         // Nothing to do for now.
1788         // FIXME: Do sparse conditional things.
1789         break;
1790     }
1791             
1792     case Return:
1793         m_state.setIsValid(false);
1794         break;
1795
1796     case TailCall:
1797     case DirectTailCall:
1798     case TailCallVarargs:
1799     case TailCallForwardVarargs:
1800         clobberWorld(node->origin.semantic, clobberLimit);
1801         m_state.setIsValid(false);
1802         break;
1803         
1804     case Throw:
1805     case ThrowStaticError:
1806         m_state.setIsValid(false);
1807         break;
1808             
1809     case ToPrimitive: {
1810         JSValue childConst = forNode(node->child1()).value();
1811         if (childConst && childConst.isNumber()) {
1812             setConstant(node, childConst);
1813             break;
1814         }
1815         
1816         ASSERT(node->child1().useKind() == UntypedUse);
1817         
1818         if (!(forNode(node->child1()).m_type & ~(SpecFullNumber | SpecBoolean | SpecString | SpecSymbol))) {
1819             m_state.setFoundConstants(true);
1820             forNode(node) = forNode(node->child1());
1821             break;
1822         }
1823         
1824         clobberWorld(node->origin.semantic, clobberLimit);
1825         
1826         forNode(node).setType(m_graph, SpecHeapTop & ~SpecObject);
1827         break;
1828     }
1829
1830     case ToNumber: {
1831         JSValue childConst = forNode(node->child1()).value();
1832         if (childConst && childConst.isNumber()) {
1833             setConstant(node, childConst);
1834             break;
1835         }
1836
1837         ASSERT(node->child1().useKind() == UntypedUse);
1838
1839         if (!(forNode(node->child1()).m_type & ~SpecBytecodeNumber)) {
1840             m_state.setFoundConstants(true);
1841             forNode(node) = forNode(node->child1());
1842             break;
1843         }
1844
1845         clobberWorld(node->origin.semantic, clobberLimit);
1846         forNode(node).setType(m_graph, SpecBytecodeNumber);
1847         break;
1848     }
1849         
1850     case ToString:
1851     case CallStringConstructor: {
1852         switch (node->child1().useKind()) {
1853         case StringObjectUse:
1854             // This also filters that the StringObject has the primordial StringObject
1855             // structure.
1856             filter(
1857                 node->child1(),
1858                 m_graph.registerStructure(m_graph.globalObjectFor(node->origin.semantic)->stringObjectStructure()));
1859             break;
1860         case StringOrStringObjectUse:
1861         case NotCellUse:
1862             break;
1863         case CellUse:
1864         case UntypedUse:
1865             clobberWorld(node->origin.semantic, clobberLimit);
1866             break;
1867         default:
1868             RELEASE_ASSERT_NOT_REACHED();
1869             break;
1870         }
1871         forNode(node).set(m_graph, m_vm.stringStructure.get());
1872         break;
1873     }
1874         
1875     case NewStringObject: {
1876         ASSERT(node->structure()->classInfo() == StringObject::info());
1877         forNode(node).set(m_graph, node->structure());
1878         break;
1879     }
1880             
1881     case NewArray:
1882         forNode(node).set(
1883             m_graph,
1884             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
1885         break;
1886
1887     case NewArrayWithSpread:
1888         if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
1889             // We've compiled assuming we're not having a bad time, so to be consistent
1890             // with StructureRegisterationPhase we must say we produce an original array
1891             // allocation structure.
1892             forNode(node).set(
1893                 m_graph,
1894                 m_graph.globalObjectFor(node->origin.semantic)->originalArrayStructureForIndexingType(ArrayWithContiguous));
1895         } else {
1896             forNode(node).set(
1897                 m_graph,
1898                 m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous));
1899         }
1900
1901         break;
1902
1903     case Spread:
1904         forNode(node).set(
1905             m_graph, m_vm.fixedArrayStructure.get());
1906         break;
1907         
1908     case NewArrayBuffer:
1909         forNode(node).set(
1910             m_graph,
1911             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
1912         break;
1913
1914     case NewArrayWithSize:
1915         forNode(node).setType(m_graph, SpecArray);
1916         break;
1917         
1918     case NewTypedArray:
1919         switch (node->child1().useKind()) {
1920         case Int32Use:
1921             break;
1922         case UntypedUse:
1923             clobberWorld(node->origin.semantic, clobberLimit);
1924             break;
1925         default:
1926             RELEASE_ASSERT_NOT_REACHED();
1927             break;
1928         }
1929         forNode(node).set(
1930             m_graph,
1931             m_graph.globalObjectFor(node->origin.semantic)->typedArrayStructureConcurrently(
1932                 node->typedArrayType()));
1933         break;
1934         
1935     case NewRegexp:
1936         forNode(node).set(m_graph, m_graph.globalObjectFor(node->origin.semantic)->regExpStructure());
1937         break;
1938             
1939     case ToThis: {
1940         AbstractValue& source = forNode(node->child1());
1941         AbstractValue& destination = forNode(node);
1942         bool strictMode = m_graph.executableFor(node->origin.semantic)->isStrictMode();
1943
1944         if (isToThisAnIdentity(strictMode, source)) {
1945             m_state.setFoundConstants(true);
1946             destination = source;
1947             break;
1948         }
1949
1950         if (strictMode)
1951             destination.makeHeapTop();
1952         else {
1953             destination = source;
1954             destination.merge(SpecObject);
1955         }
1956         break;
1957     }
1958
1959     case CreateThis: {
1960         // FIXME: We can fold this to NewObject if the incoming callee is a constant.
1961         forNode(node).setType(m_graph, SpecFinalObject);
1962         break;
1963     }
1964         
1965     case NewObject:
1966         ASSERT(!!node->structure().get());
1967         forNode(node).set(m_graph, node->structure());
1968         break;
1969
1970     case CallObjectConstructor: {
1971         AbstractValue& source = forNode(node->child1());
1972         AbstractValue& destination = forNode(node);
1973
1974         if (!(source.m_type & ~SpecObject)) {
1975             m_state.setFoundConstants(true);
1976             destination = source;
1977             break;
1978         }
1979
1980         forNode(node).setType(m_graph, SpecObject);
1981         break;
1982     }
1983
1984     case PhantomNewObject:
1985     case PhantomNewFunction:
1986     case PhantomNewGeneratorFunction:
1987     case PhantomNewAsyncFunction:
1988     case PhantomCreateActivation:
1989     case PhantomDirectArguments:
1990     case PhantomClonedArguments:
1991     case PhantomCreateRest:
1992     case PhantomSpread:
1993     case PhantomNewArrayWithSpread:
1994     case BottomValue:
1995         m_state.setDidClobber(true); // Prevent constant folding.
1996         // This claims to return bottom.
1997         break;
1998         
1999     case PutHint:
2000         break;
2001         
2002     case MaterializeNewObject: {
2003         forNode(node).set(m_graph, node->structureSet());
2004         break;
2005     }
2006
2007     case CreateActivation:
2008     case MaterializeCreateActivation:
2009         forNode(node).set(
2010             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->activationStructure());
2011         break;
2012         
2013     case CreateDirectArguments:
2014         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->directArgumentsStructure());
2015         break;
2016         
2017     case CreateScopedArguments:
2018         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->scopedArgumentsStructure());
2019         break;
2020         
2021     case CreateClonedArguments:
2022         if (!m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
2023             forNode(node).setType(m_graph, SpecObject);
2024             break;
2025         }
2026         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->clonedArgumentsStructure());
2027         break;
2028
2029     case NewGeneratorFunction:
2030         forNode(node).set(
2031             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->generatorFunctionStructure());
2032         break;
2033
2034     case NewAsyncFunction:
2035         forNode(node).set(
2036             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->asyncFunctionStructure());
2037         break;
2038
2039     case NewFunction:
2040         forNode(node).set(
2041             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->functionStructure());
2042         break;
2043         
2044     case GetCallee:
2045         if (FunctionExecutable* executable = jsDynamicCast<FunctionExecutable*>(m_vm, m_codeBlock->ownerExecutable())) {
2046             InferredValue* singleton = executable->singletonFunction();
2047             if (JSValue value = singleton->inferredValue()) {
2048                 m_graph.watchpoints().addLazily(singleton);
2049                 JSFunction* function = jsCast<JSFunction*>(value);
2050                 setConstant(node, *m_graph.freeze(function));
2051                 break;
2052             }
2053         }
2054         forNode(node).setType(m_graph, SpecFunction);
2055         break;
2056         
2057     case GetArgumentCountIncludingThis:
2058         forNode(node).setType(SpecInt32Only);
2059         break;
2060         
2061     case GetRestLength:
2062         forNode(node).setType(SpecInt32Only);
2063         break;
2064         
2065     case GetGetter: {
2066         JSValue base = forNode(node->child1()).m_value;
2067         if (base) {
2068             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
2069             if (!getterSetter->isGetterNull()) {
2070                 setConstant(node, *m_graph.freeze(getterSetter->getterConcurrently()));
2071                 break;
2072             }
2073         }
2074         
2075         forNode(node).setType(m_graph, SpecObject);
2076         break;
2077     }
2078         
2079     case GetSetter: {
2080         JSValue base = forNode(node->child1()).m_value;
2081         if (base) {
2082             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
2083             if (!getterSetter->isSetterNull()) {
2084                 setConstant(node, *m_graph.freeze(getterSetter->setterConcurrently()));
2085                 break;
2086             }
2087         }
2088         
2089         forNode(node).setType(m_graph, SpecObject);
2090         break;
2091     }
2092         
2093     case GetScope:
2094         if (JSValue base = forNode(node->child1()).m_value) {
2095             if (JSFunction* function = jsDynamicCast<JSFunction*>(m_vm, base)) {
2096                 setConstant(node, *m_graph.freeze(function->scope()));
2097                 break;
2098             }
2099         }
2100         forNode(node).setType(m_graph, SpecObjectOther);
2101         break;
2102
2103     case SkipScope: {
2104         JSValue child = forNode(node->child1()).value();
2105         if (child) {
2106             setConstant(node, *m_graph.freeze(JSValue(jsCast<JSScope*>(child.asCell())->next())));
2107             break;
2108         }
2109         forNode(node).setType(m_graph, SpecObjectOther);
2110         break;
2111     }
2112
2113     case GetGlobalObject: {
2114         JSValue child = forNode(node->child1()).value();
2115         if (child) {
2116             setConstant(node, *m_graph.freeze(JSValue(asObject(child)->globalObject())));
2117             break;
2118         }
2119
2120         if (forNode(node->child1()).m_structure.isFinite()) {
2121             JSGlobalObject* globalObject = nullptr;
2122             bool ok = true;
2123             forNode(node->child1()).m_structure.forEach(
2124                 [&] (RegisteredStructure structure) {
2125                     if (!globalObject)
2126                         globalObject = structure->globalObject();
2127                     else if (globalObject != structure->globalObject())
2128                         ok = false;
2129                 });
2130             if (globalObject && ok) {
2131                 setConstant(node, *m_graph.freeze(JSValue(globalObject)));
2132                 break;
2133             }
2134         }
2135
2136         forNode(node).setType(m_graph, SpecObjectOther);
2137         break;
2138     }
2139
2140     case GetClosureVar:
2141         if (JSValue value = m_graph.tryGetConstantClosureVar(forNode(node->child1()), node->scopeOffset())) {
2142             setConstant(node, *m_graph.freeze(value));
2143             break;
2144         }
2145         forNode(node).makeBytecodeTop();
2146         break;
2147             
2148     case PutClosureVar:
2149         break;
2150
2151     case GetRegExpObjectLastIndex:
2152         forNode(node).makeHeapTop();
2153         break;
2154
2155     case SetRegExpObjectLastIndex:
2156     case RecordRegExpCachedResult:
2157         break;
2158         
2159     case GetFromArguments:
2160         forNode(node).makeHeapTop();
2161         break;
2162         
2163     case PutToArguments:
2164         break;
2165
2166     case GetArgument:
2167         forNode(node).makeHeapTop();
2168         break;
2169
2170     case TryGetById:
2171         // FIXME: This should constant fold at least as well as the normal GetById case.
2172         // https://bugs.webkit.org/show_bug.cgi?id=156422
2173         forNode(node).makeHeapTop();
2174         break;
2175
2176     case GetById:
2177     case GetByIdFlush: {
2178         if (!node->prediction()) {
2179             m_state.setIsValid(false);
2180             break;
2181         }
2182         
2183         AbstractValue& value = forNode(node->child1());
2184         if (value.m_structure.isFinite()
2185             && (node->child1().useKind() == CellUse || !(value.m_type & ~SpecCell))) {
2186             UniquedStringImpl* uid = m_graph.identifiers()[node->identifierNumber()];
2187             GetByIdStatus status = GetByIdStatus::computeFor(value.m_structure.toStructureSet(), uid);
2188             if (status.isSimple()) {
2189                 // Figure out what the result is going to be - is it TOP, a constant, or maybe
2190                 // something more subtle?
2191                 AbstractValue result;
2192                 for (unsigned i = status.numVariants(); i--;) {
2193                     // This thing won't give us a variant that involves prototypes. If it did, we'd
2194                     // have more work to do here.
2195                     DFG_ASSERT(m_graph, node, status[i].conditionSet().isEmpty());
2196
2197                     result.merge(
2198                         m_graph.inferredValueForProperty(
2199                             value, uid, status[i].offset(), m_state.structureClobberState()));
2200                 }
2201                 m_state.setFoundConstants(true);
2202                 forNode(node) = result;
2203                 break;
2204             }
2205         }
2206
2207         clobberWorld(node->origin.semantic, clobberLimit);
2208         forNode(node).makeHeapTop();
2209         break;
2210     }
2211
2212     case GetByValWithThis:
2213     case GetByIdWithThis:
2214         clobberWorld(node->origin.semantic, clobberLimit);
2215         forNode(node).makeHeapTop();
2216         break;
2217             
2218     case GetArrayLength: {
2219         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2220             forNode(node->child1()).m_value, node->arrayMode());
2221         if (view) {
2222             setConstant(node, jsNumber(view->length()));
2223             break;
2224         }
2225         forNode(node).setType(SpecInt32Only);
2226         break;
2227     }
2228
2229     case DeleteById:
2230     case DeleteByVal: {
2231         // FIXME: This could decide if the delete will be successful based on the set of structures that
2232         // we get from our base value. https://bugs.webkit.org/show_bug.cgi?id=156611
2233         clobberWorld(node->origin.semantic, clobberLimit);
2234         forNode(node).setType(SpecBoolean);
2235         break;
2236     }
2237         
2238     case CheckStructure: {
2239         AbstractValue& value = forNode(node->child1());
2240
2241         const RegisteredStructureSet& set = node->structureSet();
2242         
2243         // It's interesting that we could have proven that the object has a larger structure set
2244         // that includes the set we're testing. In that case we could make the structure check
2245         // more efficient. We currently don't.
2246         
2247         if (value.m_structure.isSubsetOf(set))
2248             m_state.setFoundConstants(true);
2249
2250         SpeculatedType admittedTypes = SpecNone;
2251         switch (node->child1().useKind()) {
2252         case CellUse:
2253         case KnownCellUse:
2254             admittedTypes = SpecNone;
2255             break;
2256         case CellOrOtherUse:
2257             admittedTypes = SpecOther;
2258             break;
2259         default:
2260             DFG_CRASH(m_graph, node, "Bad use kind");
2261             break;
2262         }
2263         
2264         filter(value, set, admittedTypes);
2265         break;
2266     }
2267         
2268     case CheckStructureImmediate: {
2269         // FIXME: This currently can only reason about one structure at a time.
2270         // https://bugs.webkit.org/show_bug.cgi?id=136988
2271         
2272         AbstractValue& value = forNode(node->child1());
2273         const RegisteredStructureSet& set = node->structureSet();
2274         
2275         if (value.value()) {
2276             if (Structure* structure = jsDynamicCast<Structure*>(m_vm, value.value())) {
2277                 if (set.contains(m_graph.registerStructure(structure))) {
2278                     m_state.setFoundConstants(true);
2279                     break;
2280                 }
2281             }
2282             m_state.setIsValid(false);
2283             break;
2284         }
2285         
2286         if (m_phiChildren) {
2287             bool allGood = true;
2288             m_phiChildren->forAllTransitiveIncomingValues(
2289                 node,
2290                 [&] (Node* incoming) {
2291                     if (Structure* structure = incoming->dynamicCastConstant<Structure*>(m_vm)) {
2292                         if (set.contains(m_graph.registerStructure(structure)))
2293                             return;
2294                     }
2295                     allGood = false;
2296                 });
2297             if (allGood) {
2298                 m_state.setFoundConstants(true);
2299                 break;
2300             }
2301         }
2302             
2303         if (RegisteredStructure structure = set.onlyStructure()) {
2304             filterByValue(node->child1(), *m_graph.freeze(structure.get()));
2305             break;
2306         }
2307         
2308         // Aw shucks, we can't do anything!
2309         break;
2310     }
2311         
2312     case PutStructure:
2313         if (!forNode(node->child1()).m_structure.isClear()) {
2314             if (forNode(node->child1()).m_structure.onlyStructure() == node->transition()->next)
2315                 m_state.setFoundConstants(true);
2316             else {
2317                 observeTransition(
2318                     clobberLimit, node->transition()->previous, node->transition()->next);
2319                 forNode(node->child1()).changeStructure(m_graph, node->transition()->next);
2320             }
2321         }
2322         break;
2323     case GetButterfly:
2324     case AllocatePropertyStorage:
2325     case ReallocatePropertyStorage:
2326     case NukeStructureAndSetButterfly:
2327         // FIXME: We don't model the fact that the structureID is nuked, simply because currently
2328         // nobody would currently benefit from having that information. But it's a bug nonetheless.
2329         forNode(node).clear(); // The result is not a JS value.
2330         break;
2331     case CheckDOM: {
2332         JSValue constant = forNode(node->child1()).value();
2333         if (constant) {
2334             if (constant.isCell() && constant.asCell()->inherits(m_vm, node->classInfo())) {
2335                 m_state.setFoundConstants(true);
2336                 ASSERT(constant);
2337                 break;
2338             }
2339         }
2340
2341         AbstractValue& value = forNode(node->child1());
2342
2343         if (value.m_structure.isSubClassOf(node->classInfo()))
2344             m_state.setFoundConstants(true);
2345
2346         filterClassInfo(value, node->classInfo());
2347         break;
2348     }
2349     case CallDOMGetter: {
2350         CallDOMGetterData* callDOMGetterData = node->callDOMGetterData();
2351         DOMJIT::CallDOMGetterPatchpoint* patchpoint = callDOMGetterData->patchpoint;
2352         if (patchpoint->effect.writes)
2353             clobberWorld(node->origin.semantic, clobberLimit);
2354         forNode(node).setType(m_graph, callDOMGetterData->domJIT->resultType());
2355         break;
2356     }
2357     case CallDOM: {
2358         const DOMJIT::Signature* signature = node->signature();
2359         if (signature->effect.writes)
2360             clobberWorld(node->origin.semantic, clobberLimit);
2361         forNode(node).setType(m_graph, signature->result);
2362         break;
2363     }
2364     case CheckArray: {
2365         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2366             m_state.setFoundConstants(true);
2367             break;
2368         }
2369         switch (node->arrayMode().type()) {
2370         case Array::String:
2371             filter(node->child1(), SpecString);
2372             break;
2373         case Array::Int32:
2374         case Array::Double:
2375         case Array::Contiguous:
2376         case Array::Undecided:
2377         case Array::ArrayStorage:
2378         case Array::SlowPutArrayStorage:
2379             break;
2380         case Array::DirectArguments:
2381             filter(node->child1(), SpecDirectArguments);
2382             break;
2383         case Array::ScopedArguments:
2384             filter(node->child1(), SpecScopedArguments);
2385             break;
2386         case Array::Int8Array:
2387             filter(node->child1(), SpecInt8Array);
2388             break;
2389         case Array::Int16Array:
2390             filter(node->child1(), SpecInt16Array);
2391             break;
2392         case Array::Int32Array:
2393             filter(node->child1(), SpecInt32Array);
2394             break;
2395         case Array::Uint8Array:
2396             filter(node->child1(), SpecUint8Array);
2397             break;
2398         case Array::Uint8ClampedArray:
2399             filter(node->child1(), SpecUint8ClampedArray);
2400             break;
2401         case Array::Uint16Array:
2402             filter(node->child1(), SpecUint16Array);
2403             break;
2404         case Array::Uint32Array:
2405             filter(node->child1(), SpecUint32Array);
2406             break;
2407         case Array::Float32Array:
2408             filter(node->child1(), SpecFloat32Array);
2409             break;
2410         case Array::Float64Array:
2411             filter(node->child1(), SpecFloat64Array);
2412             break;
2413         case Array::AnyTypedArray:
2414             filter(node->child1(), SpecTypedArrayView);
2415             break;
2416         default:
2417             RELEASE_ASSERT_NOT_REACHED();
2418             break;
2419         }
2420         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2421         break;
2422     }
2423     case Arrayify: {
2424         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2425             m_state.setFoundConstants(true);
2426             break;
2427         }
2428         ASSERT(node->arrayMode().conversion() == Array::Convert);
2429         clobberStructures(clobberLimit);
2430         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2431         break;
2432     }
2433     case ArrayifyToStructure: {
2434         AbstractValue& value = forNode(node->child1());
2435         if (value.m_structure.isSubsetOf(RegisteredStructureSet(node->structure())))
2436             m_state.setFoundConstants(true);
2437         clobberStructures(clobberLimit);
2438         
2439         // We have a bunch of options of how to express the abstract set at this point. Let set S
2440         // be the set of structures that the value had before clobbering and assume that all of
2441         // them are watchable. The new value should be the least expressible upper bound of the
2442         // intersection of "values that currently have structure = node->structure()" and "values
2443         // that have structure in S plus any structure transition-reachable from S". Assume that
2444         // node->structure() is not in S but it is transition-reachable from S. Then we would
2445         // like to say that the result is "values that have structure = node->structure() until
2446         // we invalidate", but there is no way to express this using the AbstractValue syntax. So
2447         // we must choose between:
2448         //
2449         // 1) "values that currently have structure = node->structure()". This is a valid
2450         //    superset of the value that we really want, and it's specific enough to satisfy the
2451         //    preconditions of the array access that this is guarding. It's also specific enough
2452         //    to allow relevant optimizations in the case that we didn't have a contradiction
2453         //    like in this example. Notice that in the abscence of any contradiction, this result
2454         //    is precise rather than being a conservative LUB.
2455         //
2456         // 2) "values that currently hava structure in S plus any structure transition-reachable
2457         //    from S". This is also a valid superset of the value that we really want, but it's
2458         //    not specific enough to satisfy the preconditions of the array access that this is
2459         //    guarding - so playing such shenanigans would preclude us from having assertions on
2460         //    the typing preconditions of any array accesses. This would also not be a desirable
2461         //    answer in the absence of a contradiction.
2462         //
2463         // Note that it's tempting to simply say that the resulting value is BOTTOM because of
2464         // the contradiction. That would be wrong, since we haven't hit an invalidation point,
2465         // yet.
2466         value.set(m_graph, node->structure());
2467         break;
2468     }
2469     case GetIndexedPropertyStorage: {
2470         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2471             forNode(node->child1()).m_value, node->arrayMode());
2472         if (view)
2473             m_state.setFoundConstants(true);
2474         forNode(node).clear();
2475         break;
2476     }
2477     case ConstantStoragePointer: {
2478         forNode(node).clear();
2479         break; 
2480     }
2481         
2482     case GetTypedArrayByteOffset: {
2483         JSArrayBufferView* view = m_graph.tryGetFoldableView(forNode(node->child1()).m_value);
2484         if (view) {
2485             setConstant(node, jsNumber(view->byteOffset()));
2486             break;
2487         }
2488         forNode(node).setType(SpecInt32Only);
2489         break;
2490     }
2491         
2492     case GetByOffset: {
2493         StorageAccessData& data = node->storageAccessData();
2494         UniquedStringImpl* uid = m_graph.identifiers()[data.identifierNumber];
2495
2496         // FIXME: The part of this that handles inferred property types relies on AI knowing the structure
2497         // right now. That's probably not optimal. In some cases, we may perform an optimization (usually
2498         // by something other than AI, maybe by CSE for example) that obscures AI's view of the structure
2499         // at the point where GetByOffset runs. Currently, when that happens, we'll have to rely entirely
2500         // on the type that ByteCodeParser was able to prove.
2501         AbstractValue value = m_graph.inferredValueForProperty(
2502             forNode(node->child2()), uid, data.offset, m_state.structureClobberState());
2503
2504         // It's possible that the type that ByteCodeParser came up with is better.
2505         AbstractValue typeFromParsing;
2506         typeFromParsing.set(m_graph, data.inferredType, m_state.structureClobberState());
2507         value.filter(typeFromParsing);
2508
2509         // If we decide that there does not exist any value that this can return, then it's probably
2510         // because the compilation was already invalidated.
2511         if (value.isClear())
2512             m_state.setIsValid(false);
2513
2514         forNode(node) = value;
2515         if (value.m_value)
2516             m_state.setFoundConstants(true);
2517         break;
2518     }
2519         
2520     case GetGetterSetterByOffset: {
2521         StorageAccessData& data = node->storageAccessData();
2522         JSValue result = m_graph.tryGetConstantProperty(forNode(node->child2()), data.offset);
2523         if (result && jsDynamicCast<GetterSetter*>(m_vm, result)) {
2524             setConstant(node, *m_graph.freeze(result));
2525             break;
2526         }
2527         
2528         forNode(node).set(m_graph, m_graph.globalObjectFor(node->origin.semantic)->getterSetterStructure());
2529         break;
2530     }
2531         
2532     case MultiGetByOffset: {
2533         // This code will filter the base value in a manner that is possibly different (either more
2534         // or less precise) than the way it would be filtered if this was strength-reduced to a
2535         // CheckStructure. This is fine. It's legal for different passes over the code to prove
2536         // different things about the code, so long as all of them are sound. That even includes
2537         // one guy proving that code should never execute (due to a contradiction) and another guy
2538         // not finding that contradiction. If someone ever proved that there would be a
2539         // contradiction then there must always be a contradiction even if subsequent passes don't
2540         // realize it. This is the case here.
2541         
2542         // Ordinarily you have to be careful with calling setFoundConstants()
2543         // because of the effect on compile times, but this node is FTL-only.
2544         m_state.setFoundConstants(true);
2545         
2546         UniquedStringImpl* uid = m_graph.identifiers()[node->multiGetByOffsetData().identifierNumber];
2547
2548         AbstractValue base = forNode(node->child1());
2549         RegisteredStructureSet baseSet;
2550         AbstractValue result;
2551         for (const MultiGetByOffsetCase& getCase : node->multiGetByOffsetData().cases) {
2552             RegisteredStructureSet set = getCase.set();
2553             set.filter(base);
2554             if (set.isEmpty())
2555                 continue;
2556             baseSet.merge(set);
2557
2558             switch (getCase.method().kind()) {
2559             case GetByOffsetMethod::Constant: {
2560                 AbstractValue thisResult;
2561                 thisResult.set(
2562                     m_graph,
2563                     *getCase.method().constant(),
2564                     m_state.structureClobberState());
2565                 result.merge(thisResult);
2566                 break;
2567             }
2568
2569             case GetByOffsetMethod::Load: {
2570                 result.merge(
2571                     m_graph.inferredValueForProperty(
2572                         set, uid, m_state.structureClobberState()));
2573                 break;
2574             }
2575
2576             default: {
2577                 result.makeHeapTop();
2578                 break;
2579             } }
2580         }
2581         
2582         if (forNode(node->child1()).changeStructure(m_graph, baseSet) == Contradiction)
2583             m_state.setIsValid(false);
2584         
2585         forNode(node) = result;
2586         break;
2587     }
2588             
2589     case PutByOffset: {
2590         break;
2591     }
2592         
2593     case MultiPutByOffset: {
2594         RegisteredStructureSet newSet;
2595         TransitionVector transitions;
2596         
2597         // Ordinarily you have to be careful with calling setFoundConstants()
2598         // because of the effect on compile times, but this node is FTL-only.
2599         m_state.setFoundConstants(true);
2600         
2601         AbstractValue base = forNode(node->child1());
2602         AbstractValue originalValue = forNode(node->child2());
2603         AbstractValue resultingValue;
2604         
2605         for (unsigned i = node->multiPutByOffsetData().variants.size(); i--;) {
2606             const PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
2607             RegisteredStructureSet thisSet = *m_graph.addStructureSet(variant.oldStructure());
2608             thisSet.filter(base);
2609             if (thisSet.isEmpty())
2610                 continue;
2611
2612             AbstractValue thisValue = originalValue;
2613             thisValue.filter(m_graph, variant.requiredType());
2614             resultingValue.merge(thisValue);
2615             
2616             if (variant.kind() == PutByIdVariant::Transition) {
2617                 RegisteredStructure newStructure = m_graph.registerStructure(variant.newStructure());
2618                 if (thisSet.onlyStructure() != newStructure) {
2619                     transitions.append(
2620                         Transition(m_graph.registerStructure(variant.oldStructureForTransition()), newStructure));
2621                 } // else this is really a replace.
2622                 newSet.add(newStructure);
2623             } else {
2624                 ASSERT(variant.kind() == PutByIdVariant::Replace);
2625                 newSet.merge(thisSet);
2626             }
2627         }
2628         
2629         observeTransitions(clobberLimit, transitions);
2630         if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2631             m_state.setIsValid(false);
2632         forNode(node->child2()) = resultingValue;
2633         if (!!originalValue && !resultingValue)
2634             m_state.setIsValid(false);
2635         break;
2636     }
2637         
2638     case GetExecutable: {
2639         JSValue value = forNode(node->child1()).value();
2640         if (value) {
2641             JSFunction* function = jsDynamicCast<JSFunction*>(m_vm, value);
2642             if (function) {
2643                 setConstant(node, *m_graph.freeze(function->executable()));
2644                 break;
2645             }
2646         }
2647         forNode(node).setType(m_graph, SpecCellOther);
2648         break;
2649     }
2650     
2651     case CheckCell: {
2652         JSValue value = forNode(node->child1()).value();
2653         if (value == node->cellOperand()->value()) {
2654             m_state.setFoundConstants(true);
2655             ASSERT(value);
2656             break;
2657         }
2658         filterByValue(node->child1(), *node->cellOperand());
2659         break;
2660     }
2661
2662     case CheckNotEmpty: {
2663         AbstractValue& value = forNode(node->child1());
2664         if (!(value.m_type & SpecEmpty)) {
2665             m_state.setFoundConstants(true);
2666             break;
2667         }
2668         
2669         filter(value, ~SpecEmpty);
2670         break;
2671     }
2672
2673     case CheckStringIdent: {
2674         AbstractValue& value = forNode(node->child1());
2675         UniquedStringImpl* uid = node->uidOperand();
2676         ASSERT(!(value.m_type & ~SpecStringIdent)); // Edge filtering should have already ensured this.
2677
2678         JSValue childConstant = value.value();
2679         if (childConstant) {
2680             ASSERT(childConstant.isString());
2681             if (asString(childConstant)->tryGetValueImpl() == uid) {
2682                 m_state.setFoundConstants(true);
2683                 break;
2684             }
2685         }
2686
2687         filter(value, SpecStringIdent);
2688         break;
2689     }
2690
2691     case CheckInBounds: {
2692         JSValue left = forNode(node->child1()).value();
2693         JSValue right = forNode(node->child2()).value();
2694         if (left && right && left.isInt32() && right.isInt32()
2695             && static_cast<uint32_t>(left.asInt32()) < static_cast<uint32_t>(right.asInt32())) {
2696             m_state.setFoundConstants(true);
2697             break;
2698         }
2699         break;
2700     }
2701         
2702     case PutById:
2703     case PutByIdFlush:
2704     case PutByIdDirect: {
2705         AbstractValue& value = forNode(node->child1());
2706         if (value.m_structure.isFinite()) {
2707             PutByIdStatus status = PutByIdStatus::computeFor(
2708                 m_graph.globalObjectFor(node->origin.semantic),
2709                 value.m_structure.toStructureSet(),
2710                 m_graph.identifiers()[node->identifierNumber()],
2711                 node->op() == PutByIdDirect);
2712
2713             if (status.isSimple()) {
2714                 RegisteredStructureSet newSet;
2715                 TransitionVector transitions;
2716                 
2717                 for (unsigned i = status.numVariants(); i--;) {
2718                     const PutByIdVariant& variant = status[i];
2719                     if (variant.kind() == PutByIdVariant::Transition) {
2720                         RegisteredStructure newStructure = m_graph.registerStructure(variant.newStructure());
2721                         transitions.append(
2722                             Transition(
2723                                 m_graph.registerStructure(variant.oldStructureForTransition()), newStructure));
2724                         newSet.add(newStructure);
2725                     } else {
2726                         ASSERT(variant.kind() == PutByIdVariant::Replace);
2727                         newSet.merge(*m_graph.addStructureSet(variant.oldStructure()));
2728                     }
2729                 }
2730                 
2731                 if (status.numVariants() == 1 || isFTL(m_graph.m_plan.mode))
2732                     m_state.setFoundConstants(true);
2733                 
2734                 observeTransitions(clobberLimit, transitions);
2735                 if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2736                     m_state.setIsValid(false);
2737                 break;
2738             }
2739         }
2740         
2741         clobberWorld(node->origin.semantic, clobberLimit);
2742         break;
2743     }
2744
2745     case PutByValWithThis:
2746     case PutByIdWithThis:
2747         clobberWorld(node->origin.semantic, clobberLimit);
2748         break;
2749
2750     case PutGetterById:
2751     case PutSetterById:
2752     case PutGetterSetterById:
2753     case PutGetterByVal:
2754     case PutSetterByVal: {
2755         clobberWorld(node->origin.semantic, clobberLimit);
2756         break;
2757     }
2758
2759     case DefineDataProperty:
2760     case DefineAccessorProperty:
2761         clobberWorld(node->origin.semantic, clobberLimit);
2762         break;
2763         
2764     case In: {
2765         // FIXME: We can determine when the property definitely exists based on abstract
2766         // value information.
2767         clobberWorld(node->origin.semantic, clobberLimit);
2768         forNode(node).setType(SpecBoolean);
2769         break;
2770     }
2771
2772     case HasOwnProperty: {
2773         clobberWorld(node->origin.semantic, clobberLimit);
2774         forNode(node).setType(SpecBoolean);
2775         break;
2776     }
2777             
2778     case GetEnumerableLength: {
2779         forNode(node).setType(SpecInt32Only);
2780         break;
2781     }
2782     case HasGenericProperty: {
2783         forNode(node).setType(SpecBoolean);
2784         break;
2785     }
2786     case HasStructureProperty: {
2787         forNode(node).setType(SpecBoolean);
2788         break;
2789     }
2790     case HasIndexedProperty: {
2791         ArrayMode mode = node->arrayMode();
2792         switch (mode.type()) {
2793         case Array::Int32:
2794         case Array::Double:
2795         case Array::Contiguous:
2796         case Array::ArrayStorage: {
2797             break;
2798         }
2799         default: {
2800             clobberWorld(node->origin.semantic, clobberLimit);
2801             break;
2802         }
2803         }
2804         forNode(node).setType(SpecBoolean);
2805         break;
2806     }
2807     case GetDirectPname: {
2808         clobberWorld(node->origin.semantic, clobberLimit);
2809         forNode(node).makeHeapTop();
2810         break;
2811     }
2812     case GetPropertyEnumerator: {
2813         forNode(node).setType(m_graph, SpecCell);
2814         break;
2815     }
2816     case GetEnumeratorStructurePname: {
2817         forNode(node).setType(m_graph, SpecString | SpecOther);
2818         break;
2819     }
2820     case GetEnumeratorGenericPname: {
2821         forNode(node).setType(m_graph, SpecString | SpecOther);
2822         break;
2823     }
2824     case ToIndexString: {
2825         forNode(node).setType(m_graph, SpecString);
2826         break;
2827     }
2828
2829     case GetGlobalVar:
2830         forNode(node).makeHeapTop();
2831         break;
2832
2833     case GetGlobalLexicalVariable:
2834         forNode(node).makeBytecodeTop();
2835         break;
2836
2837     case GetDynamicVar:
2838         clobberWorld(node->origin.semantic, clobberLimit);
2839         forNode(node).makeBytecodeTop();
2840         break;
2841
2842     case PutDynamicVar:
2843         clobberWorld(node->origin.semantic, clobberLimit);
2844         break;
2845
2846     case ResolveScope:
2847         clobberWorld(node->origin.semantic, clobberLimit);
2848         forNode(node).setType(m_graph, SpecObject);
2849         break;
2850         
2851     case PutGlobalVariable:
2852     case NotifyWrite:
2853         break;
2854             
2855     case OverridesHasInstance:
2856         forNode(node).setType(SpecBoolean);
2857         break;
2858             
2859     case InstanceOf:
2860         // Sadly, we don't propagate the fact that we've done InstanceOf
2861         forNode(node).setType(SpecBoolean);
2862         break;
2863
2864     case InstanceOfCustom:
2865         clobberWorld(node->origin.semantic, clobberLimit);
2866         forNode(node).setType(SpecBoolean);
2867         break;
2868             
2869     case Phi:
2870         RELEASE_ASSERT(m_graph.m_form == SSA);
2871         forNode(node) = forNode(NodeFlowProjection(node, NodeFlowProjection::Shadow));
2872         // The state of this node would have already been decided, but it may have become a
2873         // constant, in which case we'd like to know.
2874         if (forNode(node).m_value)
2875             m_state.setFoundConstants(true);
2876         break;
2877         
2878     case Upsilon: {
2879         NodeFlowProjection shadow(node->phi(), NodeFlowProjection::Shadow);
2880         if (shadow.isStillValid()) {
2881             m_state.createValueForNode(shadow);
2882             forNode(shadow) = forNode(node->child1());
2883         }
2884         break;
2885     }
2886         
2887     case Flush:
2888     case PhantomLocal:
2889         break;
2890             
2891     case Call:
2892     case TailCallInlinedCaller:
2893     case Construct:
2894     case CallVarargs:
2895     case CallForwardVarargs:
2896     case TailCallVarargsInlinedCaller:
2897     case ConstructVarargs:
2898     case ConstructForwardVarargs:
2899     case TailCallForwardVarargsInlinedCaller:
2900     case CallEval:
2901     case DirectCall:
2902     case DirectConstruct:
2903     case DirectTailCallInlinedCaller:
2904         clobberWorld(node->origin.semantic, clobberLimit);
2905         forNode(node).makeHeapTop();
2906         break;
2907
2908     case ForceOSRExit:
2909     case CheckBadCell:
2910         m_state.setIsValid(false);
2911         break;
2912         
2913     case InvalidationPoint:
2914         forAllValues(clobberLimit, AbstractValue::observeInvalidationPointFor);
2915         m_state.setStructureClobberState(StructuresAreWatched);
2916         break;
2917
2918     case CheckTraps:
2919     case LogShadowChickenPrologue:
2920     case LogShadowChickenTail:
2921         break;
2922
2923     case ProfileType:
2924     case ProfileControlFlow:
2925     case Phantom:
2926     case CountExecution:
2927     case CheckTierUpInLoop:
2928     case CheckTierUpAtReturn:
2929     case CheckTypeInfoFlags:
2930         break;
2931
2932     case ParseInt: {
2933         AbstractValue value = forNode(node->child1());
2934         if (value.m_type && !(value.m_type & ~SpecInt32Only)) {
2935             JSValue radix;
2936             if (!node->child2())
2937                 radix = jsNumber(0);
2938             else
2939                 radix = forNode(node->child2()).m_value;
2940
2941             if (radix.isNumber()
2942                 && (radix.asNumber() == 0 || radix.asNumber() == 10)) {
2943                 m_state.setFoundConstants(true);
2944                 forNode(node).setType(SpecInt32Only);
2945                 break;
2946             }
2947         }
2948
2949         if (node->child1().useKind() == UntypedUse)
2950             clobberWorld(node->origin.semantic, clobberLimit);
2951         forNode(node).setType(m_graph, SpecBytecodeNumber);
2952         break;
2953     }
2954
2955     case CreateRest:
2956         if (!m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
2957             // This means we're already having a bad time.
2958             clobberWorld(node->origin.semantic, clobberLimit);
2959             forNode(node).setType(m_graph, SpecArray);
2960             break;
2961         }
2962         forNode(node).set(
2963             m_graph,
2964             m_graph.globalObjectFor(node->origin.semantic)->restParameterStructure());
2965         break;
2966             
2967     case Check: {
2968         // Simplify out checks that don't actually do checking.
2969         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
2970             Edge edge = node->children.child(i);
2971             if (!edge)
2972                 break;
2973             if (edge.isProved() || edge.willNotHaveCheck()) {
2974                 m_state.setFoundConstants(true);
2975                 break;
2976             }
2977         }
2978         break;
2979     }
2980
2981     case SetFunctionName: {
2982         clobberWorld(node->origin.semantic, clobberLimit);
2983         break;
2984     }
2985
2986     case StoreBarrier:
2987     case FencedStoreBarrier: {
2988         filter(node->child1(), SpecCell);
2989         break;
2990     }
2991         
2992     case CheckTierUpAndOSREnter:
2993     case LoopHint:
2994     case ZombieHint:
2995     case ExitOK:
2996         break;
2997
2998     case Unreachable:
2999         // It may be that during a previous run of AI we proved that something was unreachable, but
3000         // during this run of AI we forget that it's unreachable. AI's proofs don't have to get
3001         // monotonically stronger over time. So, we don't assert that AI doesn't reach the
3002         // Unreachable. We have no choice but to take our past proof at face value. Otherwise we'll
3003         // crash whenever AI fails to be as powerful on run K as it was on run K-1.
3004         m_state.setIsValid(false);
3005         break;
3006         
3007     case LastNodeType:
3008     case ArithIMul:
3009     case FiatInt52:
3010         DFG_CRASH(m_graph, node, "Unexpected node type");
3011         break;
3012     }
3013     
3014     return m_state.isValid();
3015 }
3016
3017 template<typename AbstractStateType>
3018 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned indexInBlock)
3019 {
3020     return executeEffects(indexInBlock, m_state.block()->at(indexInBlock));
3021 }
3022
3023 template<typename AbstractStateType>
3024 bool AbstractInterpreter<AbstractStateType>::execute(unsigned indexInBlock)
3025 {
3026     Node* node = m_state.block()->at(indexInBlock);
3027
3028     startExecuting();
3029     executeEdges(node);
3030     return executeEffects(indexInBlock, node);
3031 }
3032
3033 template<typename AbstractStateType>
3034 bool AbstractInterpreter<AbstractStateType>::execute(Node* node)
3035 {
3036     startExecuting();
3037     executeEdges(node);
3038     return executeEffects(UINT_MAX, node);
3039 }
3040
3041 template<typename AbstractStateType>
3042 void AbstractInterpreter<AbstractStateType>::clobberWorld(
3043     const CodeOrigin&, unsigned clobberLimit)
3044 {
3045     clobberStructures(clobberLimit);
3046 }