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