Commit 9f4f582b authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Don't canonicalize results of Math double operations.

For Math builtins that likely yield double results, i.e. Math.sin,
Math.cos and friends, don't bother trying to canonicalize the result
to Smi. The rationale behind this is that other parts of V8 use the
HeapNumber representation as a hint to assume that certain values
should be represented as double (i.e. for the array elements kind
and for double field tracking). This way the chance that we make
the ideal decision early on is better.

For Math.abs we establish the contract that if the input value is a
Smi, then we try hard to return a Smi (doesn't work for minimal Smi
value), otherwise we preserve the HeapNumberness of the input.

Same for the generic Add, Subtract, Multiply, etc. code stubs.

R=yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2451973003
Cr-Commit-Position: refs/heads/master@{#40573}
parent 1f6f345d
This diff is collapsed.
......@@ -935,7 +935,7 @@ void Builtins::Generate_Add(CodeStubAssembler* assembler) {
Node* lhs_value = var_fadd_lhs.value();
Node* rhs_value = var_fadd_rhs.value();
Node* value = assembler->Float64Add(lhs_value, rhs_value);
Node* result = assembler->ChangeFloat64ToTagged(value);
Node* result = assembler->AllocateHeapNumberWithValue(value);
var_result.Bind(result);
assembler->Goto(&end);
}
......@@ -1114,7 +1114,7 @@ void Builtins::Generate_Subtract(CodeStubAssembler* assembler) {
Node* lhs_value = var_fsub_lhs.value();
Node* rhs_value = var_fsub_rhs.value();
Node* value = assembler->Float64Sub(lhs_value, rhs_value);
var_result.Bind(assembler->ChangeFloat64ToTagged(value));
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&end);
}
assembler->Bind(&end);
......@@ -1266,7 +1266,7 @@ void Builtins::Generate_Multiply(CodeStubAssembler* assembler) {
{
Node* value =
assembler->Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
Node* result = assembler->ChangeFloat64ToTagged(value);
Node* result = assembler->AllocateHeapNumberWithValue(value);
var_result.Bind(result);
assembler->Goto(&return_result);
}
......@@ -1486,7 +1486,7 @@ void Builtins::Generate_Divide(CodeStubAssembler* assembler) {
{
Node* value = assembler->Float64Div(var_dividend_float64.value(),
var_divisor_float64.value());
var_result.Bind(assembler->ChangeFloat64ToTagged(value));
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&end);
}
assembler->Bind(&end);
......@@ -1644,7 +1644,7 @@ void Builtins::Generate_Modulus(CodeStubAssembler* assembler) {
{
Node* value = assembler->Float64Mod(var_dividend_float64.value(),
var_divisor_float64.value());
var_result.Bind(assembler->ChangeFloat64ToTagged(value));
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&return_result);
}
......
......@@ -523,7 +523,7 @@ Node* CodeStubAssembler::SmiMul(Node* a, Node* b) {
var_lhs_float64.Bind(SmiToFloat64(a));
var_rhs_float64.Bind(SmiToFloat64(b));
Node* value = Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
Node* result = ChangeFloat64ToTagged(value);
Node* result = AllocateHeapNumberWithValue(value);
var_result.Bind(result);
Goto(&return_result);
}
......@@ -8398,7 +8398,7 @@ compiler::Node* CodeStubAssembler::NumberInc(compiler::Node* value) {
Node* finc_value = var_finc_value.value();
Node* one = Float64Constant(1.0);
Node* finc_result = Float64Add(finc_value, one);
var_result.Bind(ChangeFloat64ToTagged(finc_result));
var_result.Bind(AllocateHeapNumberWithValue(finc_result));
Goto(&end);
}
......
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