From e034c1ad9c44b146cd9b4fed54a900b2e4845976 Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Fri, 31 Aug 2018 16:19:59 +0200 Subject: [PATCH] [turbofan] ToNumeric(x) does ToNumber(x) for all non-BigInt primitives. We can safely lower ToNumeric(x) to ToNumber(x) as long as we can guarantee that x is any primitive except BigInt (as ToNumeric would return that unchanged while ToNumber will throw). Bug: v8:8015 Change-Id: I66573cc204c7c919095ca7598a027fabef7d71a8 Reviewed-on: https://chromium-review.googlesource.com/1199665 Reviewed-by: Maya Lekova Commit-Queue: Benedikt Meurer Cr-Commit-Position: refs/heads/master@{#55556} --- src/compiler/js-typed-lowering.cc | 4 ++-- src/compiler/types.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc index 32134acf2b..f8ef95d826 100644 --- a/src/compiler/js-typed-lowering.cc +++ b/src/compiler/js-typed-lowering.cc @@ -1026,8 +1026,8 @@ Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { Reduction JSTypedLowering::ReduceJSToNumeric(Node* node) { Node* const input = NodeProperties::GetValueInput(node, 0); Type const input_type = NodeProperties::GetType(input); - if (input_type.Is(Type::Number())) { - // ToNumeric(x:number) => ToNumber(x) + if (input_type.Is(Type::NonBigIntPrimitive())) { + // ToNumeric(x:primitive\bigint) => ToNumber(x) NodeProperties::ChangeOp(node, javascript()->ToNumber()); Reduction const reduction = ReduceJSToNumber(node); return reduction.Changed() ? reduction : Changed(node); diff --git a/src/compiler/types.h b/src/compiler/types.h index d27f6e3e75..8c0ad3d6c5 100644 --- a/src/compiler/types.h +++ b/src/compiler/types.h @@ -169,7 +169,8 @@ namespace compiler { kNumber | kNullOrUndefined | kBoolean) \ V(PlainPrimitive, kNumber | kString | kBoolean | \ kNullOrUndefined) \ - V(Primitive, kSymbol | kBigInt | kPlainPrimitive) \ + V(NonBigIntPrimitive, kSymbol | kPlainPrimitive) \ + V(Primitive, kBigInt | kNonBigIntPrimitive) \ V(OtherUndetectableOrUndefined, kOtherUndetectable | kUndefined) \ V(Proxy, kCallableProxy | kOtherProxy) \ V(ArrayOrOtherObject, kArray | kOtherObject) \