Commit 81837c34 authored by Kanghua Yu's avatar Kanghua Yu Committed by Commit Bot

[csa] Apply constant folding to BranchIfNumberRelationalComparison

This CL refactors the CodeAssembler::Branch(condition, true_body, false_body)
which was introduced by https://crrev.com/c/1175488, and this reduces snapshot by 864 bytes.

Change-Id: Ifde7d6f39bd7f265e71fef5bdcc6e69d8ab5be85
Reviewed-on: https://chromium-review.googlesource.com/1175488Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Kanghua Yu <kanghua.yu@intel.com>
Cr-Commit-Position: refs/heads/master@{#55179}
parent 43fff26f
...@@ -237,6 +237,7 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs( ...@@ -237,6 +237,7 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TNode<Object> target, SloppyTNode<Object> new_target, TNode<Object> target, SloppyTNode<Object> new_target,
TNode<FixedDoubleArray> elements, TNode<Int32T> length, TNode<FixedDoubleArray> elements, TNode<Int32T> length,
TNode<Int32T> args_count, TNode<Context> context, TNode<Int32T> kind) { TNode<Int32T> args_count, TNode<Context> context, TNode<Int32T> kind) {
Label if_done(this);
const ElementsKind new_kind = PACKED_ELEMENTS; const ElementsKind new_kind = PACKED_ELEMENTS;
const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER; const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER;
...@@ -247,18 +248,22 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs( ...@@ -247,18 +248,22 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TNode<FixedArray> new_elements = CAST(AllocateFixedArray( TNode<FixedArray> new_elements = CAST(AllocateFixedArray(
new_kind, intptr_length, CodeStubAssembler::kAllowLargeObjectAllocation)); new_kind, intptr_length, CodeStubAssembler::kAllowLargeObjectAllocation));
Branch(Word32Equal(kind, Int32Constant(HOLEY_DOUBLE_ELEMENTS)), Branch(Word32Equal(kind, Int32Constant(HOLEY_DOUBLE_ELEMENTS)),
[=] { [&] {
// Fill the FixedArray with pointers to HeapObjects. // Fill the FixedArray with pointers to HeapObjects.
CopyFixedArrayElements(HOLEY_DOUBLE_ELEMENTS, elements, new_kind, CopyFixedArrayElements(HOLEY_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length, new_elements, intptr_length, intptr_length,
barrier_mode); barrier_mode);
Goto(&if_done);
}, },
[=] { [&] {
CopyFixedArrayElements(PACKED_DOUBLE_ELEMENTS, elements, new_kind, CopyFixedArrayElements(PACKED_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length, new_elements, intptr_length, intptr_length,
barrier_mode); barrier_mode);
Goto(&if_done);
}); });
BIND(&if_done);
{
if (new_target == nullptr) { if (new_target == nullptr) {
Callable callable = CodeFactory::CallVarargs(isolate()); Callable callable = CodeFactory::CallVarargs(isolate());
TailCallStub(callable, context, target, args_count, new_elements, length); TailCallStub(callable, context, target, args_count, new_elements, length);
...@@ -267,6 +272,7 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs( ...@@ -267,6 +272,7 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TailCallStub(callable, context, target, new_target, args_count, TailCallStub(callable, context, target, new_target, args_count,
new_elements, length); new_elements, length);
} }
}
} }
void CallOrConstructBuiltinsAssembler::CallOrConstructWithSpread( void CallOrConstructBuiltinsAssembler::CallOrConstructWithSpread(
......
...@@ -9910,62 +9910,59 @@ void CodeStubAssembler::BranchIfNumberRelationalComparison( ...@@ -9910,62 +9910,59 @@ void CodeStubAssembler::BranchIfNumberRelationalComparison(
TVARIABLE(Float64T, var_left_float); TVARIABLE(Float64T, var_left_float);
TVARIABLE(Float64T, var_right_float); TVARIABLE(Float64T, var_right_float);
Label if_left_smi(this), if_left_not_smi(this); Branch(TaggedIsSmi(left),
Branch(TaggedIsSmi(left), &if_left_smi, &if_left_not_smi); [&] {
BIND(&if_left_smi);
{
TNode<Smi> smi_left = CAST(left); TNode<Smi> smi_left = CAST(left);
Label if_right_not_smi(this); Branch(TaggedIsSmi(right),
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi); [&] {
{
TNode<Smi> smi_right = CAST(right); TNode<Smi> smi_right = CAST(right);
// Both {left} and {right} are Smi, so just perform a fast Smi comparison. // Both {left} and {right} are Smi, so just perform a fast
// Smi comparison.
switch (op) { switch (op) {
case Operation::kLessThan: case Operation::kLessThan:
BranchIfSmiLessThan(smi_left, smi_right, if_true, if_false); BranchIfSmiLessThan(smi_left, smi_right, if_true,
if_false);
break; break;
case Operation::kLessThanOrEqual: case Operation::kLessThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_left, smi_right, if_true, if_false); BranchIfSmiLessThanOrEqual(smi_left, smi_right, if_true,
if_false);
break; break;
case Operation::kGreaterThan: case Operation::kGreaterThan:
BranchIfSmiLessThan(smi_right, smi_left, if_true, if_false); BranchIfSmiLessThan(smi_right, smi_left, if_true,
if_false);
break; break;
case Operation::kGreaterThanOrEqual: case Operation::kGreaterThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_right, smi_left, if_true, if_false); BranchIfSmiLessThanOrEqual(smi_right, smi_left, if_true,
if_false);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} },
BIND(&if_right_not_smi); [&] {
{
CSA_ASSERT(this, IsHeapNumber(right)); CSA_ASSERT(this, IsHeapNumber(right));
var_left_float = SmiToFloat64(smi_left); var_left_float = SmiToFloat64(smi_left);
var_right_float = LoadHeapNumberValue(right); var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison); Goto(&do_float_comparison);
} });
} },
[&] {
BIND(&if_left_not_smi);
{
CSA_ASSERT(this, IsHeapNumber(left)); CSA_ASSERT(this, IsHeapNumber(left));
var_left_float = LoadHeapNumberValue(left); var_left_float = LoadHeapNumberValue(left);
Label if_right_not_smi(this); Branch(TaggedIsSmi(right),
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi); [&] {
var_right_float = SmiToFloat64(right); var_right_float = SmiToFloat64(right);
Goto(&do_float_comparison); Goto(&do_float_comparison);
},
BIND(&if_right_not_smi); [&] {
{
CSA_ASSERT(this, IsHeapNumber(right)); CSA_ASSERT(this, IsHeapNumber(right));
var_right_float = LoadHeapNumberValue(right); var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison); Goto(&do_float_comparison);
} });
} });
BIND(&do_float_comparison); BIND(&do_float_comparison);
{ {
......
...@@ -1392,19 +1392,16 @@ void CodeAssembler::Branch(TNode<BoolT> condition, ...@@ -1392,19 +1392,16 @@ void CodeAssembler::Branch(TNode<BoolT> condition,
return constant ? true_body() : false_body(); return constant ? true_body() : false_body();
} }
Label vtrue(this), vfalse(this), end(this); Label vtrue(this), vfalse(this);
Branch(condition, &vtrue, &vfalse); Branch(condition, &vtrue, &vfalse);
Bind(&vtrue); Bind(&vtrue);
{ {
true_body(); true_body();
Goto(&end);
} }
Bind(&vfalse); Bind(&vfalse);
{ {
false_body(); false_body();
Goto(&end);
} }
Bind(&end);
} }
void CodeAssembler::Switch(Node* index, Label* default_label, void CodeAssembler::Switch(Node* index, Label* default_label,
......
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