Commit 3d5d99ff authored by Darius M's avatar Darius M Committed by V8 LUCI CQ

[compiler] let InstructionSelector duplicate branch conditions

Bug: v8:12484
Change-Id: I44c2028efadbd70e7711f01d107995e0462f05d4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3477094Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Darius Mercadier <dmercadier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79239}
parent 3e2b9a31
...@@ -2403,6 +2403,28 @@ void VisitAtomicCompareExchange(InstructionSelector* selector, Node* node, ...@@ -2403,6 +2403,28 @@ void VisitAtomicCompareExchange(InstructionSelector* selector, Node* node,
selector->Emit(code, arraysize(outputs), outputs, arraysize(inputs), inputs); selector->Emit(code, arraysize(outputs), outputs, arraysize(inputs), inputs);
} }
// Used instead of CanCover in VisitWordCompareZero: even if CanCover(user,
// node) returns false, if |node| is a comparison, then it does not require any
// registers, and can thus be covered by |user|.
bool CanCoverForCompareZero(InstructionSelector* selector, Node* user,
Node* node) {
if (selector->CanCover(user, node)) {
return true;
}
// Checking if |node| is a comparison. If so, it doesn't required any
// registers, and, as such, it can always be covered by |user|.
switch (node->opcode()) {
#define CHECK_CMP_OP(op) \
case IrOpcode::k##op: \
return true;
MACHINE_COMPARE_BINOP_LIST(CHECK_CMP_OP)
#undef CHECK_CMP_OP
default:
break;
}
return false;
}
} // namespace } // namespace
// Shared routine for word comparison against zero. // Shared routine for word comparison against zero.
...@@ -2418,7 +2440,7 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value, ...@@ -2418,7 +2440,7 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value,
cont->Negate(); cont->Negate();
} }
if (CanCover(user, value)) { if (CanCoverForCompareZero(this, user, value)) {
switch (value->opcode()) { switch (value->opcode()) {
case IrOpcode::kWord32Equal: case IrOpcode::kWord32Equal:
cont->OverwriteAndNegateIfEqual(kEqual); cont->OverwriteAndNegateIfEqual(kEqual);
...@@ -2438,7 +2460,7 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value, ...@@ -2438,7 +2460,7 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value,
case IrOpcode::kWord64Equal: { case IrOpcode::kWord64Equal: {
cont->OverwriteAndNegateIfEqual(kEqual); cont->OverwriteAndNegateIfEqual(kEqual);
Int64BinopMatcher m(value); Int64BinopMatcher m(value);
if (m.right().Is(0)) { if (m.right().Is(0) && CanCover(user, value)) {
// Try to combine the branch with a comparison. // Try to combine the branch with a comparison.
Node* const eq_user = m.node(); Node* const eq_user = m.node();
Node* const eq_value = m.left().node(); Node* const eq_value = m.left().node();
...@@ -2548,7 +2570,6 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value, ...@@ -2548,7 +2570,6 @@ void InstructionSelector::VisitWordCompareZero(Node* user, Node* value,
break; break;
} }
} }
// Branch could not be combined with a compare, emit compare against 0. // Branch could not be combined with a compare, emit compare against 0.
VisitCompareZero(this, user, value, kX64Cmp32, cont); VisitCompareZero(this, user, value, kX64Cmp32, cont);
} }
......
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