Commit 75cc8352 authored by epertoso's avatar epertoso Committed by Commit bot

[turbofan] Fixes the code generation for branches on x64 when the condition is Word64Equal.

Before:

REX.W cmpq r9,r8
setzl r8l
movzxbl r8,r8
REX.W cmpq r8,0x0
jz 185

After:

REX.W cmpq r9,r8
jnz 149

Review URL: https://codereview.chromium.org/1677503002

Cr-Commit-Position: refs/heads/master@{#33784}
parent 563539a3
...@@ -1431,24 +1431,24 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, ...@@ -1431,24 +1431,24 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
FlagsContinuation cont(kNotEqual, tbranch, fbranch); FlagsContinuation cont(kNotEqual, tbranch, fbranch);
// Try to combine with comparisons against 0 by simply inverting the branch.
while (CanCover(user, value) && value->opcode() == IrOpcode::kWord32Equal) {
Int32BinopMatcher m(value);
if (m.right().Is(0)) {
user = value;
value = m.left().node();
cont.Negate();
} else {
break;
}
}
// Try to combine the branch with a comparison. // Try to combine the branch with a comparison.
if (CanCover(user, value)) { while (CanCover(user, value)) {
switch (value->opcode()) { switch (value->opcode()) {
case IrOpcode::kWord32Equal: case IrOpcode::kWord32Equal:
case IrOpcode::kWord64Equal: {
Int64BinopMatcher m(value);
if (m.right().Is(0)) {
user = value;
value = m.left().node();
cont.Negate();
continue;
}
cont.OverwriteAndNegateIfEqual(kEqual); cont.OverwriteAndNegateIfEqual(kEqual);
return VisitWordCompare(this, value, kX64Cmp32, &cont); return VisitWordCompare(
this, value,
value->opcode() == IrOpcode::kWord64Equal ? kX64Cmp : kX64Cmp32,
&cont);
}
case IrOpcode::kInt32LessThan: case IrOpcode::kInt32LessThan:
cont.OverwriteAndNegateIfEqual(kSignedLessThan); cont.OverwriteAndNegateIfEqual(kSignedLessThan);
return VisitWordCompare(this, value, kX64Cmp32, &cont); return VisitWordCompare(this, value, kX64Cmp32, &cont);
...@@ -1461,27 +1461,6 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, ...@@ -1461,27 +1461,6 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
case IrOpcode::kUint32LessThanOrEqual: case IrOpcode::kUint32LessThanOrEqual:
cont.OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); cont.OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
return VisitWordCompare(this, value, kX64Cmp32, &cont); return VisitWordCompare(this, value, kX64Cmp32, &cont);
case IrOpcode::kWord64Equal: {
cont.OverwriteAndNegateIfEqual(kEqual);
Int64BinopMatcher m(value);
if (m.right().Is(0)) {
// Try to combine the branch with a comparison.
Node* const user = m.node();
Node* const value = m.left().node();
if (CanCover(user, value)) {
switch (value->opcode()) {
case IrOpcode::kInt64Sub:
return VisitWord64Compare(this, value, &cont);
case IrOpcode::kWord64And:
return VisitWordCompare(this, value, kX64Test, &cont);
default:
break;
}
}
return VisitCompareZero(this, value, kX64Cmp, &cont);
}
return VisitWord64Compare(this, value, &cont);
}
case IrOpcode::kInt64LessThan: case IrOpcode::kInt64LessThan:
cont.OverwriteAndNegateIfEqual(kSignedLessThan); cont.OverwriteAndNegateIfEqual(kSignedLessThan);
return VisitWord64Compare(this, value, &cont); return VisitWord64Compare(this, value, &cont);
...@@ -1551,9 +1530,16 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, ...@@ -1551,9 +1530,16 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
return VisitWordCompare(this, value, kX64Test32, &cont); return VisitWordCompare(this, value, kX64Test32, &cont);
case IrOpcode::kWord64And: case IrOpcode::kWord64And:
return VisitWordCompare(this, value, kX64Test, &cont); return VisitWordCompare(this, value, kX64Test, &cont);
case IrOpcode::kLoad:
if (LoadRepresentationOf(value->op()).representation() ==
MachineRepresentation::kWord64) {
return VisitCompareZero(this, value, kX64Cmp, &cont);
}
break;
default: default:
break; 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.
......
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