Commit e40b1b42 authored by dusan.m.milosavljevic's avatar dusan.m.milosavljevic Committed by Commit bot

MIPS: [turbofan] Optimize fpu compares with zero literal.

TEST=
BUG=

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

Cr-Commit-Position: refs/heads/master@{#31426}
parent 7e5d3309
......@@ -54,6 +54,18 @@ class MipsOperandConverter final : public InstructionOperandConverter {
return ToDoubleRegister(op);
}
DoubleRegister InputOrZeroDoubleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputDoubleRegister(index);
}
DoubleRegister InputOrZeroSingleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputSingleRegister(index);
}
Operand InputImmediate(size_t index) {
Constant constant = ToConstant(instr_->InputAt(index));
switch (constant.type()) {
......@@ -932,14 +944,24 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpS, branch->condition);
}
__ BranchF32(tlabel, NULL, cc, i.InputSingleRegister(0),
i.InputSingleRegister(1));
FPURegister left = i.InputOrZeroSingleRegister(0);
FPURegister right = i.InputOrZeroSingleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF32(tlabel, NULL, cc, left, right);
} else if (instr->arch_opcode() == kMipsCmpD) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpD, branch->condition);
}
__ BranchF64(tlabel, NULL, cc, i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF64(tlabel, NULL, cc, left, right);
} else {
PrintF("AssembleArchBranch Unimplemented arch_opcode: %d\n",
instr->arch_opcode());
......@@ -1051,8 +1073,12 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
return;
} else if (instr->arch_opcode() == kMipsCmpD ||
instr->arch_opcode() == kMipsCmpS) {
FPURegister left = i.InputDoubleRegister(0);
FPURegister right = i.InputDoubleRegister(1);
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
bool predicate;
FPUCondition cc = FlagsConditionToConditionCmpFPU(predicate, condition);
if (!IsMipsArchVariant(kMips32r6)) {
......
......@@ -802,10 +802,14 @@ static void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
void VisitFloat32Compare(InstructionSelector* selector, Node* node,
FlagsContinuation* cont) {
MipsOperandGenerator g(selector);
Node* left = node->InputAt(0);
Node* right = node->InputAt(1);
VisitCompare(selector, kMipsCmpS, g.UseRegister(left), g.UseRegister(right),
cont);
Float32BinopMatcher m(node);
InstructionOperand lhs, rhs;
lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
: g.UseRegister(m.left().node());
rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
: g.UseRegister(m.right().node());
VisitCompare(selector, kMipsCmpS, lhs, rhs, cont);
}
......@@ -813,10 +817,14 @@ void VisitFloat32Compare(InstructionSelector* selector, Node* node,
void VisitFloat64Compare(InstructionSelector* selector, Node* node,
FlagsContinuation* cont) {
MipsOperandGenerator g(selector);
Node* left = node->InputAt(0);
Node* right = node->InputAt(1);
VisitCompare(selector, kMipsCmpD, g.UseRegister(left), g.UseRegister(right),
cont);
Float64BinopMatcher m(node);
InstructionOperand lhs, rhs;
lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
: g.UseRegister(m.left().node());
rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
: g.UseRegister(m.right().node());
VisitCompare(selector, kMipsCmpD, lhs, rhs, cont);
}
......
......@@ -53,6 +53,18 @@ class MipsOperandConverter final : public InstructionOperandConverter {
return ToDoubleRegister(op);
}
DoubleRegister InputOrZeroDoubleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputDoubleRegister(index);
}
DoubleRegister InputOrZeroSingleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputSingleRegister(index);
}
Operand InputImmediate(size_t index) {
Constant constant = ToConstant(instr_->InputAt(index));
switch (constant.type()) {
......@@ -1010,14 +1022,24 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpS, branch->condition);
}
__ BranchF32(tlabel, NULL, cc, i.InputSingleRegister(0),
i.InputSingleRegister(1));
FPURegister left = i.InputOrZeroSingleRegister(0);
FPURegister right = i.InputOrZeroSingleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF32(tlabel, NULL, cc, left, right);
} else if (instr->arch_opcode() == kMips64CmpD) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpD, branch->condition);
}
__ BranchF64(tlabel, NULL, cc, i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF64(tlabel, NULL, cc, left, right);
} else {
PrintF("AssembleArchBranch Unimplemented arch_opcode: %d\n",
instr->arch_opcode());
......@@ -1130,8 +1152,12 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
return;
} else if (instr->arch_opcode() == kMips64CmpD ||
instr->arch_opcode() == kMips64CmpS) {
FPURegister left = i.InputDoubleRegister(0);
FPURegister right = i.InputDoubleRegister(1);
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
bool predicate;
FPUCondition cc = FlagsConditionToConditionCmpFPU(predicate, condition);
if (kArchVariant != kMips64r6) {
......
......@@ -996,10 +996,14 @@ static void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
void VisitFloat32Compare(InstructionSelector* selector, Node* node,
FlagsContinuation* cont) {
Mips64OperandGenerator g(selector);
Node* left = node->InputAt(0);
Node* right = node->InputAt(1);
VisitCompare(selector, kMips64CmpS, g.UseRegister(left), g.UseRegister(right),
cont);
Float32BinopMatcher m(node);
InstructionOperand lhs, rhs;
lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
: g.UseRegister(m.left().node());
rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
: g.UseRegister(m.right().node());
VisitCompare(selector, kMips64CmpS, lhs, rhs, cont);
}
......@@ -1007,10 +1011,14 @@ void VisitFloat32Compare(InstructionSelector* selector, Node* node,
void VisitFloat64Compare(InstructionSelector* selector, Node* node,
FlagsContinuation* cont) {
Mips64OperandGenerator g(selector);
Node* left = node->InputAt(0);
Node* right = node->InputAt(1);
VisitCompare(selector, kMips64CmpD, g.UseRegister(left), g.UseRegister(right),
cont);
Float64BinopMatcher m(node);
InstructionOperand lhs, rhs;
lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
: g.UseRegister(m.left().node());
rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
: g.UseRegister(m.right().node());
VisitCompare(selector, kMips64CmpD, lhs, rhs, cont);
}
......
......@@ -1625,6 +1625,8 @@ const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
Register scratch1, Label* found);
bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
private:
void CallCFunctionHelper(Register function,
int num_reg_arguments,
......
......@@ -1719,6 +1719,8 @@ const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
Register scratch1, Label* found);
bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
private:
void CallCFunctionHelper(Register function,
int num_reg_arguments,
......
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