[turbofan] Refactor the compare-zero folding in instruction selector.
Review-Url: https://codereview.chromium.org/2475433005 Cr-Commit-Position: refs/heads/master@{#40721}
This commit is contained in:
parent
e7aa6f91b3
commit
9b308dcaf5
@ -1876,21 +1876,22 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
|
||||
// Shared routine for word comparisons against zero.
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
while (selector->CanCover(user, value)) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (value->opcode() == IrOpcode::kWord32Equal &&
|
||||
selector->CanCover(user, value)) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
@ -1974,7 +1975,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (user->opcode() == IrOpcode::kWord32Equal) {
|
||||
|
@ -2353,21 +2353,22 @@ void VisitFloat64Compare(InstructionSelector* selector, Node* node,
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
Arm64OperandGenerator g(selector);
|
||||
while (selector->CanCover(user, value)) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (value->opcode() == IrOpcode::kWord32Equal &&
|
||||
selector->CanCover(user, value)) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWord32Compare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWord32Compare(selector, value, cont);
|
||||
@ -2505,7 +2506,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Branch could not be combined with a compare, compare against 0 and branch.
|
||||
|
@ -1393,22 +1393,22 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
|
||||
// Shared routine for word comparison with zero.
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
// Try to combine the branch with a comparison.
|
||||
while (selector->CanCover(user, value)) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (value->opcode() == IrOpcode::kWord32Equal &&
|
||||
selector->CanCover(user, value)) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Try to combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
@ -1474,7 +1474,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Continuation could not be combined with a compare, emit compare against 0.
|
||||
|
@ -387,6 +387,7 @@ class FlagsContinuation final {
|
||||
void Overwrite(FlagsCondition condition) { condition_ = condition; }
|
||||
|
||||
void OverwriteAndNegateIfEqual(FlagsCondition condition) {
|
||||
DCHECK(condition_ == kEqual || condition_ == kNotEqual);
|
||||
bool negate = condition_ == kEqual;
|
||||
condition_ = condition;
|
||||
if (negate) Negate();
|
||||
|
@ -1416,21 +1416,22 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
|
||||
// Shared routine for word comparisons against zero.
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
while (selector->CanCover(user, value)) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (value->opcode() == IrOpcode::kWord32Equal &&
|
||||
selector->CanCover(user, value)) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWordCompare(selector, value, cont);
|
||||
@ -1494,7 +1495,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Continuation could not be combined with a compare, emit compare against 0.
|
||||
|
@ -2037,21 +2037,30 @@ void EmitWordCompareZero(InstructionSelector* selector, Node* value,
|
||||
// Shared routine for word comparisons against zero.
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (selector->CanCover(user, value)) {
|
||||
if (value->opcode() == IrOpcode::kWord32Equal) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
} else if (value->opcode() == IrOpcode::kWord64Equal) {
|
||||
Int64BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWord32Compare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWord32Compare(selector, value, cont);
|
||||
@ -2064,19 +2073,9 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
case IrOpcode::kUint32LessThanOrEqual:
|
||||
cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
|
||||
return VisitWord32Compare(selector, value, cont);
|
||||
case IrOpcode::kWord64Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int64BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord64Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWord64Compare(selector, value, cont);
|
||||
}
|
||||
case IrOpcode::kInt64LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWord64Compare(selector, value, cont);
|
||||
@ -2147,7 +2146,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Continuation could not be combined with a compare, emit compare against 0.
|
||||
|
@ -1869,21 +1869,22 @@ void VisitFloat64Compare(InstructionSelector* selector, Node* node,
|
||||
// Shared routine for word comparison against zero.
|
||||
void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
Node* value, FlagsContinuation* cont) {
|
||||
while (selector->CanCover(user, value)) {
|
||||
// Try to combine with comparisons against 0 by simply inverting the branch.
|
||||
while (value->opcode() == IrOpcode::kWord32Equal &&
|
||||
selector->CanCover(user, value)) {
|
||||
Int32BinopMatcher m(value);
|
||||
if (!m.right().Is(0)) break;
|
||||
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
}
|
||||
|
||||
if (selector->CanCover(user, value)) {
|
||||
switch (value->opcode()) {
|
||||
case IrOpcode::kWord32Equal: {
|
||||
// Combine with comparisons against 0 by simply inverting the
|
||||
// continuation.
|
||||
Int32BinopMatcher m(value);
|
||||
if (m.right().Is(0)) {
|
||||
user = value;
|
||||
value = m.left().node();
|
||||
cont->Negate();
|
||||
continue;
|
||||
}
|
||||
case IrOpcode::kWord32Equal:
|
||||
cont->OverwriteAndNegateIfEqual(kEqual);
|
||||
return VisitWordCompare(selector, value, kX64Cmp32, cont);
|
||||
}
|
||||
case IrOpcode::kInt32LessThan:
|
||||
cont->OverwriteAndNegateIfEqual(kSignedLessThan);
|
||||
return VisitWordCompare(selector, value, kX64Cmp32, cont);
|
||||
@ -1992,7 +1993,6 @@ void VisitWordCompareZero(InstructionSelector* selector, Node* user,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Branch could not be combined with a compare, emit compare against 0.
|
||||
|
Loading…
Reference in New Issue
Block a user