Commit 4acca5ba authored by Mythri's avatar Mythri Committed by Commit Bot

[Interpreter] Inline feedback collection in relational compare bytecode handlers.

This is the last in the series of simplifying the logic to collect feedback
in compare bytecode handlers. This cl inlines the type feedback collection
for the relational compare (lessthan, lessthan or equal, greater than,
gerater than or equal) bytecode handlers.

Bug: v8:4280
Change-Id: I4a896c9cbe5628c76785882c0632bfa07b18b099
Reviewed-on: https://chromium-review.googlesource.com/500309Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45296}
parent 5ce6090d
...@@ -6983,7 +6983,8 @@ void CodeStubAssembler::GotoUnlessNumberLessThan(Node* lhs, Node* rhs, ...@@ -6983,7 +6983,8 @@ void CodeStubAssembler::GotoUnlessNumberLessThan(Node* lhs, Node* rhs,
Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
Node* lhs, Node* rhs, Node* lhs, Node* rhs,
Node* context) { Node* context,
Variable* var_type_feedback) {
Label return_true(this), return_false(this), end(this); Label return_true(this), return_false(this), end(this);
VARIABLE(result, MachineRepresentation::kTagged); VARIABLE(result, MachineRepresentation::kTagged);
...@@ -6996,8 +6997,14 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -6996,8 +6997,14 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
// conversions. // conversions.
VARIABLE(var_lhs, MachineRepresentation::kTagged, lhs); VARIABLE(var_lhs, MachineRepresentation::kTagged, lhs);
VARIABLE(var_rhs, MachineRepresentation::kTagged, rhs); VARIABLE(var_rhs, MachineRepresentation::kTagged, rhs);
Variable* loop_vars[2] = {&var_lhs, &var_rhs}; VariableList loop_variable_list({&var_lhs, &var_rhs}, zone());
Label loop(this, 2, loop_vars); if (var_type_feedback != nullptr) {
// Initialize the type feedback to None. The current feedback is combined
// with the previous feedback.
var_type_feedback->Bind(SmiConstant(CompareOperationFeedback::kNone));
loop_variable_list.Add(var_type_feedback, zone());
}
Label loop(this, loop_variable_list);
Goto(&loop); Goto(&loop);
BIND(&loop); BIND(&loop);
{ {
...@@ -7018,6 +7025,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7018,6 +7025,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_rhsissmi); BIND(&if_rhsissmi);
{ {
// Both {lhs} and {rhs} are Smi, so just perform a fast Smi comparison. // Both {lhs} and {rhs} are Smi, so just perform a fast Smi comparison.
if (var_type_feedback != nullptr) {
CombineFeedback(var_type_feedback,
SmiConstant(CompareOperationFeedback::kSignedSmall));
}
switch (mode) { switch (mode) {
case kLessThan: case kLessThan:
BranchIfSmiLessThan(lhs, rhs, &return_true, &return_false); BranchIfSmiLessThan(lhs, rhs, &return_true, &return_false);
...@@ -7047,6 +7058,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7047,6 +7058,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
{ {
// Convert the {lhs} and {rhs} to floating point values, and // Convert the {lhs} and {rhs} to floating point values, and
// perform a floating point comparison. // perform a floating point comparison.
if (var_type_feedback != nullptr) {
CombineFeedback(var_type_feedback,
SmiConstant(CompareOperationFeedback::kNumber));
}
var_fcmp_lhs.Bind(SmiToFloat64(lhs)); var_fcmp_lhs.Bind(SmiToFloat64(lhs));
var_fcmp_rhs.Bind(LoadHeapNumberValue(rhs)); var_fcmp_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fcmp); Goto(&do_fcmp);
...@@ -7054,6 +7069,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7054,6 +7069,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_rhsisnotnumber); BIND(&if_rhsisnotnumber);
{ {
// The {rhs} is not a HeapNumber and {lhs} is an Smi.
if (var_type_feedback != nullptr) {
var_type_feedback->Bind(
SmiConstant(CompareOperationFeedback::kAny));
}
// Convert the {rhs} to a Number; we don't need to perform the // Convert the {rhs} to a Number; we don't need to perform the
// dedicated ToPrimitive(rhs, hint Number) operation, as the // dedicated ToPrimitive(rhs, hint Number) operation, as the
// ToNumber(rhs) will by itself already invoke ToPrimitive with // ToNumber(rhs) will by itself already invoke ToPrimitive with
...@@ -7084,6 +7104,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7084,6 +7104,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
{ {
// Convert the {lhs} and {rhs} to floating point values, and // Convert the {lhs} and {rhs} to floating point values, and
// perform a floating point comparison. // perform a floating point comparison.
if (var_type_feedback != nullptr) {
CombineFeedback(var_type_feedback,
SmiConstant(CompareOperationFeedback::kNumber));
}
var_fcmp_lhs.Bind(LoadHeapNumberValue(lhs)); var_fcmp_lhs.Bind(LoadHeapNumberValue(lhs));
var_fcmp_rhs.Bind(SmiToFloat64(rhs)); var_fcmp_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fcmp); Goto(&do_fcmp);
...@@ -7091,6 +7115,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7091,6 +7115,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_lhsisnotnumber); BIND(&if_lhsisnotnumber);
{ {
// The {lhs} is not a HeapNumber and {rhs} is an Smi.
if (var_type_feedback != nullptr) {
var_type_feedback->Bind(
SmiConstant(CompareOperationFeedback::kAny));
}
// Convert the {lhs} to a Number; we don't need to perform the // Convert the {lhs} to a Number; we don't need to perform the
// dedicated ToPrimitive(lhs, hint Number) operation, as the // dedicated ToPrimitive(lhs, hint Number) operation, as the
// ToNumber(lhs) will by itself already invoke ToPrimitive with // ToNumber(lhs) will by itself already invoke ToPrimitive with
...@@ -7121,6 +7150,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7121,6 +7150,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
{ {
// Convert the {lhs} and {rhs} to floating point values, and // Convert the {lhs} and {rhs} to floating point values, and
// perform a floating point comparison. // perform a floating point comparison.
if (var_type_feedback != nullptr) {
CombineFeedback(var_type_feedback,
SmiConstant(CompareOperationFeedback::kNumber));
}
var_fcmp_lhs.Bind(LoadHeapNumberValue(lhs)); var_fcmp_lhs.Bind(LoadHeapNumberValue(lhs));
var_fcmp_rhs.Bind(LoadHeapNumberValue(rhs)); var_fcmp_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fcmp); Goto(&do_fcmp);
...@@ -7128,6 +7161,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7128,6 +7161,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_rhsisnotnumber); BIND(&if_rhsisnotnumber);
{ {
// The {rhs} is not a HeapNumber and {lhs} is a HeapNumber.
if (var_type_feedback != nullptr) {
var_type_feedback->Bind(
SmiConstant(CompareOperationFeedback::kAny));
}
// Convert the {rhs} to a Number; we don't need to perform // Convert the {rhs} to a Number; we don't need to perform
// dedicated ToPrimitive(rhs, hint Number) operation, as the // dedicated ToPrimitive(rhs, hint Number) operation, as the
// ToNumber(rhs) will by itself already invoke ToPrimitive with // ToNumber(rhs) will by itself already invoke ToPrimitive with
...@@ -7162,6 +7200,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7162,6 +7200,10 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_rhsisstring); BIND(&if_rhsisstring);
{ {
// Both {lhs} and {rhs} are strings. // Both {lhs} and {rhs} are strings.
if (var_type_feedback != nullptr) {
CombineFeedback(var_type_feedback,
SmiConstant(CompareOperationFeedback::kString));
}
switch (mode) { switch (mode) {
case kLessThan: case kLessThan:
result.Bind(CallStub(CodeFactory::StringLessThan(isolate()), result.Bind(CallStub(CodeFactory::StringLessThan(isolate()),
...@@ -7191,6 +7233,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7191,6 +7233,11 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_rhsisnotstring); BIND(&if_rhsisnotstring);
{ {
// The {lhs} is a String and {rhs} is not a String.
if (var_type_feedback != nullptr) {
var_type_feedback->Bind(
SmiConstant(CompareOperationFeedback::kAny));
}
// The {lhs} is a String, while {rhs} is neither a Number nor a // The {lhs} is a String, while {rhs} is neither a Number nor a
// String, so we need to call ToPrimitive(rhs, hint Number) if // String, so we need to call ToPrimitive(rhs, hint Number) if
// {rhs} is a receiver or ToNumber(lhs) and ToNumber(rhs) in the // {rhs} is a receiver or ToNumber(lhs) and ToNumber(rhs) in the
...@@ -7223,6 +7270,41 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode, ...@@ -7223,6 +7270,41 @@ Node* CodeStubAssembler::RelationalComparison(RelationalComparisonMode mode,
BIND(&if_lhsisnotstring); BIND(&if_lhsisnotstring);
{ {
if (var_type_feedback != nullptr) {
// The {lhs} is not an Smi, HeapNumber or String and {rhs} is not
// an Smi: collect NumberOrOddball feedback if {lhs} is an Oddball
// and {rhs} is either a HeapNumber or Oddball.
Label collect_any_feedback(this), collect_oddball_feedback(this),
collect_feedback_done(this);
GotoIfNot(
Word32Equal(lhs_instance_type, Int32Constant(ODDBALL_TYPE)),
&collect_any_feedback);
Node* rhs_instance_type = LoadMapInstanceType(rhs_map);
GotoIf(Word32Equal(rhs_instance_type,
Int32Constant(HEAP_NUMBER_TYPE)),
&collect_oddball_feedback);
Branch(
Word32Equal(rhs_instance_type, Int32Constant(ODDBALL_TYPE)),
&collect_oddball_feedback, &collect_any_feedback);
BIND(&collect_oddball_feedback);
{
CombineFeedback(
var_type_feedback,
SmiConstant(CompareOperationFeedback::kNumberOrOddball));
Goto(&collect_feedback_done);
}
BIND(&collect_any_feedback);
{
var_type_feedback->Bind(
SmiConstant(CompareOperationFeedback::kAny));
Goto(&collect_feedback_done);
}
BIND(&collect_feedback_done);
}
// The {lhs} is neither a Number nor a String, so we need to call // The {lhs} is neither a Number nor a String, so we need to call
// ToPrimitive(lhs, hint Number) if {lhs} is a receiver or // ToPrimitive(lhs, hint Number) if {lhs} is a receiver or
// ToNumber(lhs) and ToNumber(rhs) in the other cases. // ToNumber(lhs) and ToNumber(rhs) in the other cases.
......
...@@ -1351,7 +1351,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -1351,7 +1351,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
}; };
Node* RelationalComparison(RelationalComparisonMode mode, Node* lhs, Node* RelationalComparison(RelationalComparisonMode mode, Node* lhs,
Node* rhs, Node* context); Node* rhs, Node* context,
Variable* var_type_feedback = nullptr);
void BranchIfNumericRelationalComparison(RelationalComparisonMode mode, void BranchIfNumericRelationalComparison(RelationalComparisonMode mode,
Node* lhs, Node* rhs, Label* if_true, Node* lhs, Node* rhs, Label* if_true,
......
This diff is collapsed.
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