[turbofan] Improve constant-folding for typeof.

Especially support constant-folding typeof for detectable and
undetectable receivers.

BUG=v8:5267,v8:5270
R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2646743002
Cr-Commit-Position: refs/heads/master@{#42494}
This commit is contained in:
bmeurer 2017-01-19 02:26:17 -08:00 committed by Commit bot
parent 7682837501
commit c9a980d59a
2 changed files with 60 additions and 56 deletions

View File

@ -861,18 +861,15 @@ Reduction JSTypedLowering::ReduceJSTypeOf(Node* node) {
return Replace(jsgraph()->Constant(f->string_string())); return Replace(jsgraph()->Constant(f->string_string()));
} else if (type->Is(Type::Symbol())) { } else if (type->Is(Type::Symbol())) {
return Replace(jsgraph()->Constant(f->symbol_string())); return Replace(jsgraph()->Constant(f->symbol_string()));
} else if (type->Is(Type::Union(Type::Undefined(), Type::OtherUndetectable(), } else if (type->Is(Type::OtherUndetectableOrUndefined())) {
graph()->zone()))) {
return Replace(jsgraph()->Constant(f->undefined_string())); return Replace(jsgraph()->Constant(f->undefined_string()));
} else if (type->Is(Type::Null())) { } else if (type->Is(Type::NonCallableOrNull())) {
return Replace(jsgraph()->Constant(f->object_string())); return Replace(jsgraph()->Constant(f->object_string()));
} else if (type->Is(Type::Function())) { } else if (type->Is(Type::Function())) {
return Replace(jsgraph()->Constant(f->function_string())); return Replace(jsgraph()->Constant(f->function_string()));
} else if (type->IsHeapConstant()) { } else if (type->IsHeapConstant()) {
return Replace(jsgraph()->Constant( return Replace(jsgraph()->Constant(
Object::TypeOf(isolate(), type->AsHeapConstant()->Value()))); Object::TypeOf(isolate(), type->AsHeapConstant()->Value())));
} else if (type->IsOtherNumberConstant()) {
return Replace(jsgraph()->Constant(f->number_string()));
} }
return NoChange(); return NoChange();

View File

@ -128,57 +128,64 @@ namespace compiler {
V(OtherInternal, 1u << 24) \ V(OtherInternal, 1u << 24) \
V(ExternalPointer, 1u << 25) \ V(ExternalPointer, 1u << 25) \
\ \
V(Signed31, kUnsigned30 | kNegative31) \ V(Signed31, kUnsigned30 | kNegative31) \
V(Signed32, kSigned31 | kOtherUnsigned31 | kOtherSigned32) \ V(Signed32, kSigned31 | kOtherUnsigned31 | \
V(Signed32OrMinusZero, kSigned32 | kMinusZero) \ kOtherSigned32) \
V(Signed32OrMinusZeroOrNaN, kSigned32 | kMinusZero | kNaN) \ V(Signed32OrMinusZero, kSigned32 | kMinusZero) \
V(Negative32, kNegative31 | kOtherSigned32) \ V(Signed32OrMinusZeroOrNaN, kSigned32 | kMinusZero | kNaN) \
V(Unsigned31, kUnsigned30 | kOtherUnsigned31) \ V(Negative32, kNegative31 | kOtherSigned32) \
V(Unsigned32, kUnsigned30 | kOtherUnsigned31 | \ V(Unsigned31, kUnsigned30 | kOtherUnsigned31) \
kOtherUnsigned32) \ V(Unsigned32, kUnsigned30 | kOtherUnsigned31 | \
V(Unsigned32OrMinusZero, kUnsigned32 | kMinusZero) \ kOtherUnsigned32) \
V(Unsigned32OrMinusZeroOrNaN, kUnsigned32 | kMinusZero | kNaN) \ V(Unsigned32OrMinusZero, kUnsigned32 | kMinusZero) \
V(Integral32, kSigned32 | kUnsigned32) \ V(Unsigned32OrMinusZeroOrNaN, kUnsigned32 | kMinusZero | kNaN) \
V(Integral32OrMinusZeroOrNaN, kIntegral32 | kMinusZero | kNaN) \ V(Integral32, kSigned32 | kUnsigned32) \
V(PlainNumber, kIntegral32 | kOtherNumber) \ V(Integral32OrMinusZeroOrNaN, kIntegral32 | kMinusZero | kNaN) \
V(OrderedNumber, kPlainNumber | kMinusZero) \ V(PlainNumber, kIntegral32 | kOtherNumber) \
V(MinusZeroOrNaN, kMinusZero | kNaN) \ V(OrderedNumber, kPlainNumber | kMinusZero) \
V(Number, kOrderedNumber | kNaN) \ V(MinusZeroOrNaN, kMinusZero | kNaN) \
V(String, kInternalizedString | kOtherString) \ V(Number, kOrderedNumber | kNaN) \
V(UniqueName, kSymbol | kInternalizedString) \ V(String, kInternalizedString | kOtherString) \
V(Name, kSymbol | kString) \ V(UniqueName, kSymbol | kInternalizedString) \
V(BooleanOrNumber, kBoolean | kNumber) \ V(Name, kSymbol | kString) \
V(BooleanOrNullOrNumber, kBooleanOrNumber | kNull) \ V(BooleanOrNumber, kBoolean | kNumber) \
V(BooleanOrNullOrUndefined, kBoolean | kNull | kUndefined) \ V(BooleanOrNullOrNumber, kBooleanOrNumber | kNull) \
V(NullOrNumber, kNull | kNumber) \ V(BooleanOrNullOrUndefined, kBoolean | kNull | kUndefined) \
V(NullOrUndefined, kNull | kUndefined) \ V(NullOrNumber, kNull | kNumber) \
V(Undetectable, kNullOrUndefined | kOtherUndetectable) \ V(NullOrUndefined, kNull | kUndefined) \
V(NumberOrOddball, kNumber | kNullOrUndefined | kBoolean | kHole) \ V(Undetectable, kNullOrUndefined | kOtherUndetectable) \
V(NumberOrSimdOrString, kNumber | kSimd | kString) \ V(NumberOrOddball, kNumber | kNullOrUndefined | kBoolean | \
V(NumberOrString, kNumber | kString) \ kHole) \
V(NumberOrUndefined, kNumber | kUndefined) \ V(NumberOrSimdOrString, kNumber | kSimd | kString) \
V(PlainPrimitive, kNumberOrString | kBoolean | kNullOrUndefined) \ V(NumberOrString, kNumber | kString) \
V(Primitive, kSymbol | kSimd | kPlainPrimitive) \ V(NumberOrUndefined, kNumber | kUndefined) \
V(Proxy, kCallableProxy | kOtherProxy) \ V(PlainPrimitive, kNumberOrString | kBoolean | \
V(Callable, kFunction | kBoundFunction | kOtherCallable | \ kNullOrUndefined) \
kCallableProxy | kOtherUndetectable) \ V(Primitive, kSymbol | kSimd | kPlainPrimitive) \
V(DetectableObject, kFunction | kBoundFunction | kOtherCallable | \ V(OtherUndetectableOrUndefined, kOtherUndetectable | kUndefined) \
kOtherObject) \ V(Proxy, kCallableProxy | kOtherProxy) \
V(DetectableReceiver, kDetectableObject | kProxy) \ V(Callable, kFunction | kBoundFunction | \
V(DetectableReceiverOrNull, kDetectableReceiver | kNull) \ kOtherCallable | kCallableProxy | \
V(Object, kDetectableObject | kOtherUndetectable) \ kOtherUndetectable) \
V(Receiver, kObject | kProxy) \ V(NonCallable, kOtherObject | kOtherProxy) \
V(ReceiverOrUndefined, kReceiver | kUndefined) \ V(NonCallableOrNull, kNonCallable | kNull) \
V(ReceiverOrNullOrUndefined, kReceiver | kNull | kUndefined) \ V(DetectableObject, kFunction | kBoundFunction | \
V(StringOrReceiver, kString | kReceiver) \ kOtherCallable | kOtherObject) \
V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \ V(DetectableReceiver, kDetectableObject | kProxy) \
kReceiver) \ V(DetectableReceiverOrNull, kDetectableReceiver | kNull) \
V(NonStringUniqueOrHole, kBoolean | kHole | kNull | kReceiver | \ V(Object, kDetectableObject | kOtherUndetectable) \
kSymbol | kUndefined) \ V(Receiver, kObject | kProxy) \
V(Internal, kHole | kExternalPointer | kOtherInternal) \ V(ReceiverOrUndefined, kReceiver | kUndefined) \
V(NonInternal, kPrimitive | kReceiver) \ V(ReceiverOrNullOrUndefined, kReceiver | kNull | kUndefined) \
V(NonNumber, kUnique | kString | kInternal) \ V(StringOrReceiver, kString | kReceiver) \
V(Any, 0xfffffffeu) V(Unique, kBoolean | kUniqueName | kNull | \
kUndefined | kReceiver) \
V(NonStringUniqueOrHole, kBoolean | kHole | kNull | kReceiver | \
kSymbol | kUndefined) \
V(Internal, kHole | kExternalPointer | kOtherInternal) \
V(NonInternal, kPrimitive | kReceiver) \
V(NonNumber, kUnique | kString | kInternal) \
V(Any, 0xfffffffeu)
// clang-format on // clang-format on