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,25 +248,30 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs( ...@@ -247,25 +248,30 @@ 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);
}); });
if (new_target == nullptr) { BIND(&if_done);
Callable callable = CodeFactory::CallVarargs(isolate()); {
TailCallStub(callable, context, target, args_count, new_elements, length); if (new_target == nullptr) {
} else { Callable callable = CodeFactory::CallVarargs(isolate());
Callable callable = CodeFactory::ConstructVarargs(isolate()); TailCallStub(callable, context, target, args_count, new_elements, length);
TailCallStub(callable, context, target, new_target, args_count, } else {
new_elements, length); Callable callable = CodeFactory::ConstructVarargs(isolate());
TailCallStub(callable, context, target, new_target, args_count,
new_elements, length);
}
} }
} }
......
...@@ -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); [&] {
TNode<Smi> smi_left = CAST(left);
BIND(&if_left_smi);
{ Branch(TaggedIsSmi(right),
TNode<Smi> smi_left = CAST(left); [&] {
TNode<Smi> smi_right = CAST(right);
Label if_right_not_smi(this);
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi); // Both {left} and {right} are Smi, so just perform a fast
{ // Smi comparison.
TNode<Smi> smi_right = CAST(right); switch (op) {
case Operation::kLessThan:
// Both {left} and {right} are Smi, so just perform a fast Smi comparison. BranchIfSmiLessThan(smi_left, smi_right, if_true,
switch (op) { if_false);
case Operation::kLessThan: break;
BranchIfSmiLessThan(smi_left, smi_right, if_true, if_false); case Operation::kLessThanOrEqual:
break; BranchIfSmiLessThanOrEqual(smi_left, smi_right, if_true,
case Operation::kLessThanOrEqual: 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,
BranchIfSmiLessThan(smi_right, smi_left, if_true, if_false); 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,
break; if_false);
default: break;
UNREACHABLE(); default:
} 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));
{ var_left_float = LoadHeapNumberValue(left);
CSA_ASSERT(this, IsHeapNumber(left));
var_left_float = LoadHeapNumberValue(left); Branch(TaggedIsSmi(right),
[&] {
Label if_right_not_smi(this); var_right_float = SmiToFloat64(right);
GotoIfNot(TaggedIsSmi(right), &if_right_not_smi); Goto(&do_float_comparison);
var_right_float = SmiToFloat64(right); },
Goto(&do_float_comparison); [&] {
CSA_ASSERT(this, IsHeapNumber(right));
BIND(&if_right_not_smi); var_right_float = LoadHeapNumberValue(right);
{ Goto(&do_float_comparison);
CSA_ASSERT(this, IsHeapNumber(right)); });
var_right_float = LoadHeapNumberValue(right); });
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