Commit 159ffcc0 authored by bmeurer's avatar bmeurer Committed by Commit bot

[crankshaft] Make sure +x is as fast as Number(x).

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/1704833002

Cr-Commit-Position: refs/heads/master@{#34057}
parent 0d595bb0
......@@ -2958,6 +2958,8 @@ Maybe<HConstant*> HConstant::CopyToTruncatedNumber(Isolate* isolate,
res = new (zone) HConstant(std::numeric_limits<double>::quiet_NaN());
} else if (handle->IsNull()) {
res = new(zone) HConstant(0);
} else if (handle->IsString()) {
res = new(zone) HConstant(String::ToNumber(Handle<String>::cast(handle)));
}
return res != NULL ? Just(res) : Nothing<HConstant*>();
}
......
......@@ -2057,6 +2057,21 @@ HValue* HGraphBuilder::BuildNumberToString(HValue* object, Type* type) {
}
HValue* HGraphBuilder::BuildToNumber(HValue* input, Type* input_type) {
if (input->type().IsTaggedNumber() || input_type->Is(Type::Number())) {
return input;
}
Callable callable = CodeFactory::ToNumber(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HCallWithDescriptor* instr =
Add<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
instr->set_type(HType::TaggedNumber());
return instr;
}
HValue* HGraphBuilder::BuildToObject(HValue* receiver) {
NoObservableSideEffectsScope scope(this);
......@@ -11138,6 +11153,16 @@ HValue* HGraphBuilder::BuildBinaryOperation(Token::Value op, HValue* left,
allocation_mode.feedback_site());
}
// Special case for +x here.
if (op == Token::MUL) {
if (left->EqualsInteger32Constant(1)) {
return BuildToNumber(right, right_type);
}
if (right->EqualsInteger32Constant(1)) {
return BuildToNumber(left, left_type);
}
}
if (graph()->info()->IsStub()) {
left = EnforceNumberType(left, left_type);
right = EnforceNumberType(right, right_type);
......@@ -12362,16 +12387,14 @@ void HOptimizedGraphBuilder::GenerateToNumber(CallRuntime* call) {
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
Callable callable = CodeFactory::ToNumber(isolate());
HValue* input = Pop();
if (input->type().IsTaggedNumber()) {
return ast_context()->ReturnValue(input);
} else {
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HInstruction* result =
New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
return ast_context()->ReturnInstruction(result, call->id());
Type* input_type = Type::Any();
HValue* result = BuildToNumber(input, input_type);
if (result->HasObservableSideEffects()) {
if (!ast_context()->IsEffect()) Push(result);
Add<HSimulate>(call->id(), REMOVABLE_SIMULATE);
if (!ast_context()->IsEffect()) result = Pop();
}
return ast_context()->ReturnValue(result);
}
......
......@@ -1321,6 +1321,7 @@ class HGraphBuilder {
bool is_jsarray);
HValue* BuildNumberToString(HValue* object, Type* type);
HValue* BuildToNumber(HValue* input, Type* input_type);
HValue* BuildToObject(HValue* receiver);
void BuildJSObjectCheck(HValue* receiver,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment