Reviewers: Sven Panne,
Description:
[x86] Generate test reg,reg instead of cmp reg,0.
The instruction sequence is shorter and saves decoding bandwidth.
[email protected]
Please review this at https://codereview.chromium.org/916543004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+33, -3 lines):
M src/compiler/ia32/code-generator-ia32.cc
M src/compiler/x64/code-generator-x64.cc
Index: src/compiler/ia32/code-generator-ia32.cc
diff --git a/src/compiler/ia32/code-generator-ia32.cc
b/src/compiler/ia32/code-generator-ia32.cc
index
d20848918d30aad46f247217479f0e6b9e39544c..e54a85415797ebbf94808e2cc552cc5c5a86dbba
100644
--- a/src/compiler/ia32/code-generator-ia32.cc
+++ b/src/compiler/ia32/code-generator-ia32.cc
@@ -167,6 +167,11 @@ bool HasImmediateInput(Instruction* instr, int index) {
}
+bool HasRegisterInput(Instruction* instr, int index) {
+ return instr->InputAt(index)->IsRegister();
+}
+
+
class OutOfLineLoadInteger FINAL : public OutOfLineCode {
public:
OutOfLineLoadInteger(CodeGenerator* gen, Register result)
@@ -351,7 +356,11 @@ void
CodeGenerator::AssembleArchInstruction(Instruction* instr) {
break;
case kIA32Cmp:
if (HasImmediateInput(instr, 1)) {
- __ cmp(i.InputOperand(0), i.InputImmediate(1));
+ if (HasRegisterInput(instr, 0) && i.InputInt32(1) == 0) {
+ __ test(i.InputRegister(0), i.InputRegister(0));
+ } else {
+ __ cmp(i.InputOperand(0), i.InputImmediate(1));
+ }
} else {
__ cmp(i.InputRegister(0), i.InputOperand(1));
}
Index: src/compiler/x64/code-generator-x64.cc
diff --git a/src/compiler/x64/code-generator-x64.cc
b/src/compiler/x64/code-generator-x64.cc
index
973bbd1ef06bb794d153701c380eeae63b2c4057..8966fff01c60fe73d9737410bfa604a17aa138e4
100644
--- a/src/compiler/x64/code-generator-x64.cc
+++ b/src/compiler/x64/code-generator-x64.cc
@@ -210,6 +210,27 @@ class OutOfLineTruncateDoubleToI FINAL : public
OutOfLineCode {
} while (0)
+#define ASSEMBLE_CMP(cmp_instr, test_instr) \
+ do { \
+ if (HasImmediateInput(instr, 1)) { \
+ if (instr->InputAt(0)->IsRegister()) { \
+ if (i.InputInt32(1) == 0) { \
+ __ test_instr(i.InputRegister(0), i.InputRegister(0)); \
+ } else { \
+ __ cmp_instr(i.InputRegister(0), i.InputImmediate(1)); \
+ } \
+ } else { \
+ __ cmp_instr(i.InputOperand(0), i.InputImmediate(1)); \
+ } \
+ } else { \
+ if (instr->InputAt(1)->IsRegister()) { \
+ __ cmp_instr(i.InputRegister(0), i.InputRegister(1)); \
+ } else { \
+ __ cmp_instr(i.InputRegister(0), i.InputOperand(1)); \
+ } \
+ } \
+ } while (0)
+
#define ASSEMBLE_MULT(asm_instr) \
do { \
if (HasImmediateInput(instr, 1)) { \
@@ -588,10 +609,10 @@ void
CodeGenerator::AssembleArchInstruction(Instruction* instr) {
ASSEMBLE_BINOP(andq);
break;
case kX64Cmp32:
- ASSEMBLE_BINOP(cmpl);
+ ASSEMBLE_CMP(cmpl, testl);
break;
case kX64Cmp:
- ASSEMBLE_BINOP(cmpq);
+ ASSEMBLE_CMP(cmpq, testq);
break;
case kX64Test32:
ASSEMBLE_BINOP(testl);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.