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(
TNode<Object> target, SloppyTNode<Object> new_target,
TNode<FixedDoubleArray> elements, TNode<Int32T> length,
TNode<Int32T> args_count, TNode<Context> context, TNode<Int32T> kind) {
Label if_done(this);
const ElementsKind new_kind = PACKED_ELEMENTS;
const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER;
......@@ -247,25 +248,30 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TNode<FixedArray> new_elements = CAST(AllocateFixedArray(
new_kind, intptr_length, CodeStubAssembler::kAllowLargeObjectAllocation));
Branch(Word32Equal(kind, Int32Constant(HOLEY_DOUBLE_ELEMENTS)),
[=] {
[&] {
// Fill the FixedArray with pointers to HeapObjects.
CopyFixedArrayElements(HOLEY_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
Goto(&if_done);
},
[=] {
[&] {
CopyFixedArrayElements(PACKED_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
Goto(&if_done);
});
if (new_target == nullptr) {
Callable callable = CodeFactory::CallVarargs(isolate());
TailCallStub(callable, context, target, args_count, new_elements, length);
} else {
Callable callable = CodeFactory::ConstructVarargs(isolate());
TailCallStub(callable, context, target, new_target, args_count,
new_elements, length);
BIND(&if_done);
{
if (new_target == nullptr) {
Callable callable = CodeFactory::CallVarargs(isolate());
TailCallStub(callable, context, target, args_count, new_elements, length);
} else {
Callable callable = CodeFactory::ConstructVarargs(isolate());
TailCallStub(callable, context, target, new_target, args_count,
new_elements, length);
}
}
}
......
......@@ -9910,62 +9910,59 @@ void CodeStubAssembler::BranchIfNumberRelationalComparison(
TVARIABLE(Float64T, var_left_float);
TVARIABLE(Float64T, var_right_float);
Label if_left_smi(this), if_left_not_smi(this);
Branch(TaggedIsSmi(left), &if_left_smi, &if_left_not_smi);
BIND(&if_left_smi);
{
TNode<Smi> smi_left = CAST(left);
Label if_right_not_smi(this);
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi);
{
TNode<Smi> smi_right = CAST(right);
// Both {left} and {right} are Smi, so just perform a fast Smi comparison.
switch (op) {
case Operation::kLessThan:
BranchIfSmiLessThan(smi_left, smi_right, if_true, if_false);
break;
case Operation::kLessThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_left, smi_right, if_true, if_false);
break;
case Operation::kGreaterThan:
BranchIfSmiLessThan(smi_right, smi_left, if_true, if_false);
break;
case Operation::kGreaterThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_right, smi_left, if_true, if_false);
break;
default:
UNREACHABLE();
}
}
BIND(&if_right_not_smi);
{
CSA_ASSERT(this, IsHeapNumber(right));
var_left_float = SmiToFloat64(smi_left);
var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison);
}
}
BIND(&if_left_not_smi);
{
CSA_ASSERT(this, IsHeapNumber(left));
var_left_float = LoadHeapNumberValue(left);
Label if_right_not_smi(this);
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi);
var_right_float = SmiToFloat64(right);
Goto(&do_float_comparison);
BIND(&if_right_not_smi);
{
CSA_ASSERT(this, IsHeapNumber(right));
var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison);
}
}
Branch(TaggedIsSmi(left),
[&] {
TNode<Smi> smi_left = CAST(left);
Branch(TaggedIsSmi(right),
[&] {
TNode<Smi> smi_right = CAST(right);
// Both {left} and {right} are Smi, so just perform a fast
// Smi comparison.
switch (op) {
case Operation::kLessThan:
BranchIfSmiLessThan(smi_left, smi_right, if_true,
if_false);
break;
case Operation::kLessThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_left, smi_right, if_true,
if_false);
break;
case Operation::kGreaterThan:
BranchIfSmiLessThan(smi_right, smi_left, if_true,
if_false);
break;
case Operation::kGreaterThanOrEqual:
BranchIfSmiLessThanOrEqual(smi_right, smi_left, if_true,
if_false);
break;
default:
UNREACHABLE();
}
},
[&] {
CSA_ASSERT(this, IsHeapNumber(right));
var_left_float = SmiToFloat64(smi_left);
var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison);
});
},
[&] {
CSA_ASSERT(this, IsHeapNumber(left));
var_left_float = LoadHeapNumberValue(left);
Branch(TaggedIsSmi(right),
[&] {
var_right_float = SmiToFloat64(right);
Goto(&do_float_comparison);
},
[&] {
CSA_ASSERT(this, IsHeapNumber(right));
var_right_float = LoadHeapNumberValue(right);
Goto(&do_float_comparison);
});
});
BIND(&do_float_comparison);
{
......
......@@ -1392,19 +1392,16 @@ void CodeAssembler::Branch(TNode<BoolT> condition,
return constant ? true_body() : false_body();
}
Label vtrue(this), vfalse(this), end(this);
Label vtrue(this), vfalse(this);
Branch(condition, &vtrue, &vfalse);
Bind(&vtrue);
{
true_body();
Goto(&end);
}
Bind(&vfalse);
{
false_body();
Goto(&end);
}
Bind(&end);
}
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