diff options
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/X86/PeepholeOptimizer.cpp | 33 | ||||
-rw-r--r-- | lib/Target/X86/Printer.cpp | 67 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 67 | ||||
-rw-r--r-- | lib/Target/X86/X86CodeEmitter.cpp | 22 | ||||
-rw-r--r-- | lib/Target/X86/X86PeepholeOpt.cpp | 33 | ||||
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 10 |
6 files changed, 120 insertions, 112 deletions
diff --git a/lib/Target/X86/PeepholeOptimizer.cpp b/lib/Target/X86/PeepholeOptimizer.cpp index 89008aeeca..6d07ec502a 100644 --- a/lib/Target/X86/PeepholeOptimizer.cpp +++ b/lib/Target/X86/PeepholeOptimizer.cpp @@ -67,15 +67,35 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, // immediate despite the fact that the operands are 16 or 32 bits. Because // this can save three bytes of code size (and icache space), we want to // shrink them if possible. + case X86::IMULri16: case X86::IMULri32: + assert(MI->getNumOperands() == 3 && "These should all have 3 operands!"); + if (MI->getOperand(2).isImmediate()) { + int Val = MI->getOperand(2).getImmedValue(); + // If the value is the same when signed extended from 8 bits... + if (Val == (signed int)(signed char)Val) { + unsigned Opcode; + switch (MI->getOpcode()) { + default: assert(0 && "Unknown opcode value!"); + case X86::IMULri16: Opcode = X86::IMULri16b; break; + case X86::IMULri32: Opcode = X86::IMULri32b; break; + } + unsigned R0 = MI->getOperand(0).getReg(); + unsigned R1 = MI->getOperand(1).getReg(); + *I = BuildMI(Opcode, 2, R0).addReg(R1).addZImm((char)Val); + delete MI; + return true; + } + } + return false; + case X86::ADDri16: case X86::ADDri32: case X86::SUBri16: case X86::SUBri32: - case X86::IMULri16: case X86::IMULri32: case X86::ANDri16: case X86::ANDri32: case X86::ORri16: case X86::ORri32: case X86::XORri16: case X86::XORri32: - assert(MI->getNumOperands() == 3 && "These should all have 3 operands!"); - if (MI->getOperand(2).isImmediate()) { - int Val = MI->getOperand(2).getImmedValue(); + assert(MI->getNumOperands() == 2 && "These should all have 2 operands!"); + if (MI->getOperand(1).isImmediate()) { + int Val = MI->getOperand(1).getImmedValue(); // If the value is the same when signed extended from 8 bits... if (Val == (signed int)(signed char)Val) { unsigned Opcode; @@ -85,8 +105,6 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, case X86::ADDri32: Opcode = X86::ADDri32b; break; case X86::SUBri16: Opcode = X86::SUBri16b; break; case X86::SUBri32: Opcode = X86::SUBri32b; break; - case X86::IMULri16: Opcode = X86::IMULri16b; break; - case X86::IMULri32: Opcode = X86::IMULri32b; break; case X86::ANDri16: Opcode = X86::ANDri16b; break; case X86::ANDri32: Opcode = X86::ANDri32b; break; case X86::ORri16: Opcode = X86::ORri16b; break; @@ -95,8 +113,7 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, case X86::XORri32: Opcode = X86::XORri32b; break; } unsigned R0 = MI->getOperand(0).getReg(); - unsigned R1 = MI->getOperand(1).getReg(); - *I = BuildMI(Opcode, 2, R0).addReg(R1).addZImm((char)Val); + *I = BuildMI(Opcode, 1, R0, MOTy::UseAndDef).addZImm((char)Val); delete MI; return true; } diff --git a/lib/Target/X86/Printer.cpp b/lib/Target/X86/Printer.cpp index 7cd4573ff6..c410d8bed7 100644 --- a/lib/Target/X86/Printer.cpp +++ b/lib/Target/X86/Printer.cpp @@ -609,35 +609,31 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { return; } case X86II::MRMDestReg: { - // There are two acceptable forms of MRMDestReg instructions, those with 2, - // 3 and 4 operands: + // There are three forms of MRMDestReg instructions, those with 2 + // or 3 operands: // - // 2 Operands: this is for things like mov that do not read a second input + // 2 Operands: this is for things like mov that do not read a + // second input. // - // 3 Operands: in this form, the first two registers (the destination, and - // the first operand) should be the same, post register allocation. The 3rd - // operand is an additional input. This should be for things like add - // instructions. + // 2 Operands: two address instructions which def&use the first + // argument and use the second as input. // - // 4 Operands: This form is for instructions which are 3 operands forms, but - // have a constant argument as well. + // 3 Operands: in this form, two address instructions are the same + // as in 2 but have a constant argument as well. // bool isTwoAddr = TII.isTwoAddrInstr(Opcode); assert(MI->getOperand(0).isRegister() && (MI->getNumOperands() == 2 || - (isTwoAddr && MI->getOperand(1).isRegister() && - MI->getOperand(0).getReg() == MI->getOperand(1).getReg() && - (MI->getNumOperands() == 3 || - (MI->getNumOperands() == 4 && MI->getOperand(3).isImmediate())))) + (MI->getNumOperands() == 3 && MI->getOperand(2).isImmediate())) && "Bad format for MRMDestReg!"); O << TII.getName(MI->getOpCode()) << " "; printOp(MI->getOperand(0)); O << ", "; - printOp(MI->getOperand(1+isTwoAddr)); - if (MI->getNumOperands() == 4) { + printOp(MI->getOperand(1)); + if (MI->getNumOperands() == 3) { O << ", "; - printOp(MI->getOperand(3)); + printOp(MI->getOperand(2)); } O << "\n"; return; @@ -659,40 +655,35 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { } case X86II::MRMSrcReg: { - // There are three forms that are acceptable for MRMSrcReg instructions, - // those with 3 and 2 operands: + // There are three forms that are acceptable for MRMSrcReg + // instructions, those with 2 or 3 operands: // - // 3 Operands: in this form, the last register (the second input) is the - // ModR/M input. The first two operands should be the same, post register - // allocation. This is for things like: add r32, r/m32 + // 2 Operands: this is for things like mov that do not read a + // second input. + // + // 2 Operands: in this form, the last register is the ModR/M + // input. The first operand is a def&use. This is for things + // like: add r32, r/m32 // // 3 Operands: in this form, we can have 'INST R1, R2, imm', which is used // for instructions like the IMULri instructions. // - // 2 Operands: this is for things like mov that do not read a second input // assert(MI->getOperand(0).isRegister() && MI->getOperand(1).isRegister() && - (MI->getNumOperands() == 2 || - (MI->getNumOperands() == 3 && - (MI->getOperand(2).isRegister() || - MI->getOperand(2).isImmediate()))) + (MI->getNumOperands() == 2 || + (MI->getNumOperands() == 3 && + (MI->getOperand(2).isImmediate()))) && "Bad format for MRMSrcReg!"); - if (MI->getNumOperands() == 3 && !MI->getOperand(2).isImmediate() && - MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) - O << "**"; O << TII.getName(MI->getOpCode()) << " "; printOp(MI->getOperand(0)); - - // If this is IMULri* instructions, print the non-two-address operand. - if (MI->getNumOperands() == 3 && MI->getOperand(2).isImmediate()) { - O << ", "; - printOp(MI->getOperand(1)); - } - O << ", "; - printOp(MI->getOperand(MI->getNumOperands()-1)); + printOp(MI->getOperand(1)); + if (MI->getNumOperands() == 3) { + O << ", "; + printOp(MI->getOperand(2)); + } O << "\n"; return; } @@ -705,7 +696,7 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { (MI->getNumOperands() == 1+4 && isMem(MI, 1)) || (MI->getNumOperands() == 2+4 && MI->getOperand(1).isRegister() && isMem(MI, 2)) - && "Bad format for MRMDestReg!"); + && "Bad format for MRMSrcMem!"); if (MI->getNumOperands() == 2+4 && MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) O << "**"; diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 7cd4573ff6..c410d8bed7 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -609,35 +609,31 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { return; } case X86II::MRMDestReg: { - // There are two acceptable forms of MRMDestReg instructions, those with 2, - // 3 and 4 operands: + // There are three forms of MRMDestReg instructions, those with 2 + // or 3 operands: // - // 2 Operands: this is for things like mov that do not read a second input + // 2 Operands: this is for things like mov that do not read a + // second input. // - // 3 Operands: in this form, the first two registers (the destination, and - // the first operand) should be the same, post register allocation. The 3rd - // operand is an additional input. This should be for things like add - // instructions. + // 2 Operands: two address instructions which def&use the first + // argument and use the second as input. // - // 4 Operands: This form is for instructions which are 3 operands forms, but - // have a constant argument as well. + // 3 Operands: in this form, two address instructions are the same + // as in 2 but have a constant argument as well. // bool isTwoAddr = TII.isTwoAddrInstr(Opcode); assert(MI->getOperand(0).isRegister() && (MI->getNumOperands() == 2 || - (isTwoAddr && MI->getOperand(1).isRegister() && - MI->getOperand(0).getReg() == MI->getOperand(1).getReg() && - (MI->getNumOperands() == 3 || - (MI->getNumOperands() == 4 && MI->getOperand(3).isImmediate())))) + (MI->getNumOperands() == 3 && MI->getOperand(2).isImmediate())) && "Bad format for MRMDestReg!"); O << TII.getName(MI->getOpCode()) << " "; printOp(MI->getOperand(0)); O << ", "; - printOp(MI->getOperand(1+isTwoAddr)); - if (MI->getNumOperands() == 4) { + printOp(MI->getOperand(1)); + if (MI->getNumOperands() == 3) { O << ", "; - printOp(MI->getOperand(3)); + printOp(MI->getOperand(2)); } O << "\n"; return; @@ -659,40 +655,35 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { } case X86II::MRMSrcReg: { - // There are three forms that are acceptable for MRMSrcReg instructions, - // those with 3 and 2 operands: + // There are three forms that are acceptable for MRMSrcReg + // instructions, those with 2 or 3 operands: // - // 3 Operands: in this form, the last register (the second input) is the - // ModR/M input. The first two operands should be the same, post register - // allocation. This is for things like: add r32, r/m32 + // 2 Operands: this is for things like mov that do not read a + // second input. + // + // 2 Operands: in this form, the last register is the ModR/M + // input. The first operand is a def&use. This is for things + // like: add r32, r/m32 // // 3 Operands: in this form, we can have 'INST R1, R2, imm', which is used // for instructions like the IMULri instructions. // - // 2 Operands: this is for things like mov that do not read a second input // assert(MI->getOperand(0).isRegister() && MI->getOperand(1).isRegister() && - (MI->getNumOperands() == 2 || - (MI->getNumOperands() == 3 && - (MI->getOperand(2).isRegister() || - MI->getOperand(2).isImmediate()))) + (MI->getNumOperands() == 2 || + (MI->getNumOperands() == 3 && + (MI->getOperand(2).isImmediate()))) && "Bad format for MRMSrcReg!"); - if (MI->getNumOperands() == 3 && !MI->getOperand(2).isImmediate() && - MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) - O << "**"; O << TII.getName(MI->getOpCode()) << " "; printOp(MI->getOperand(0)); - - // If this is IMULri* instructions, print the non-two-address operand. - if (MI->getNumOperands() == 3 && MI->getOperand(2).isImmediate()) { - O << ", "; - printOp(MI->getOperand(1)); - } - O << ", "; - printOp(MI->getOperand(MI->getNumOperands()-1)); + printOp(MI->getOperand(1)); + if (MI->getNumOperands() == 3) { + O << ", "; + printOp(MI->getOperand(2)); + } O << "\n"; return; } @@ -705,7 +696,7 @@ void Printer::printMachineInstruction(const MachineInstr *MI) { (MI->getNumOperands() == 1+4 && isMem(MI, 1)) || (MI->getNumOperands() == 2+4 && MI->getOperand(1).isRegister() && isMem(MI, 2)) - && "Bad format for MRMDestReg!"); + && "Bad format for MRMSrcMem!"); if (MI->getNumOperands() == 2+4 && MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) O << "**"; diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp index 13e9d762f5..516f1d2725 100644 --- a/lib/Target/X86/X86CodeEmitter.cpp +++ b/lib/Target/X86/X86CodeEmitter.cpp @@ -548,10 +548,10 @@ void Emitter::emitInstruction(MachineInstr &MI) { case X86II::MRMDestReg: { MCE.emitByte(BaseOpcode); - MachineOperand &SrcOp = MI.getOperand(1+II->isTwoAddrInstr(Opcode)); - emitRegModRMByte(MI.getOperand(0).getReg(), getX86RegNum(SrcOp.getReg())); - if (MI.getNumOperands() == 4) - emitConstant(MI.getOperand(3).getImmedValue(), sizeOfPtr(Desc)); + emitRegModRMByte(MI.getOperand(0).getReg(), + getX86RegNum(MI.getOperand(1).getReg())); + if (MI.getNumOperands() == 3) + emitConstant(MI.getOperand(2).getImmedValue(), sizeOfPtr(Desc)); break; } case X86II::MRMDestMem: @@ -562,18 +562,10 @@ void Emitter::emitInstruction(MachineInstr &MI) { case X86II::MRMSrcReg: MCE.emitByte(BaseOpcode); - if (MI.getNumOperands() == 2) { - emitRegModRMByte(MI.getOperand(MI.getNumOperands()-1).getReg(), - getX86RegNum(MI.getOperand(0).getReg())); - } else if (MI.getOperand(2).isImmediate()) { - emitRegModRMByte(MI.getOperand(1).getReg(), - getX86RegNum(MI.getOperand(0).getReg())); - + emitRegModRMByte(MI.getOperand(1).getReg(), + getX86RegNum(MI.getOperand(0).getReg())); + if (MI.getNumOperands() == 3) emitConstant(MI.getOperand(2).getImmedValue(), sizeOfPtr(Desc)); - } else { - emitRegModRMByte(MI.getOperand(2).getReg(), - getX86RegNum(MI.getOperand(0).getReg())); - } break; case X86II::MRMSrcMem: diff --git a/lib/Target/X86/X86PeepholeOpt.cpp b/lib/Target/X86/X86PeepholeOpt.cpp index 89008aeeca..6d07ec502a 100644 --- a/lib/Target/X86/X86PeepholeOpt.cpp +++ b/lib/Target/X86/X86PeepholeOpt.cpp @@ -67,15 +67,35 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, // immediate despite the fact that the operands are 16 or 32 bits. Because // this can save three bytes of code size (and icache space), we want to // shrink them if possible. + case X86::IMULri16: case X86::IMULri32: + assert(MI->getNumOperands() == 3 && "These should all have 3 operands!"); + if (MI->getOperand(2).isImmediate()) { + int Val = MI->getOperand(2).getImmedValue(); + // If the value is the same when signed extended from 8 bits... + if (Val == (signed int)(signed char)Val) { + unsigned Opcode; + switch (MI->getOpcode()) { + default: assert(0 && "Unknown opcode value!"); + case X86::IMULri16: Opcode = X86::IMULri16b; break; + case X86::IMULri32: Opcode = X86::IMULri32b; break; + } + unsigned R0 = MI->getOperand(0).getReg(); + unsigned R1 = MI->getOperand(1).getReg(); + *I = BuildMI(Opcode, 2, R0).addReg(R1).addZImm((char)Val); + delete MI; + return true; + } + } + return false; + case X86::ADDri16: case X86::ADDri32: case X86::SUBri16: case X86::SUBri32: - case X86::IMULri16: case X86::IMULri32: case X86::ANDri16: case X86::ANDri32: case X86::ORri16: case X86::ORri32: case X86::XORri16: case X86::XORri32: - assert(MI->getNumOperands() == 3 && "These should all have 3 operands!"); - if (MI->getOperand(2).isImmediate()) { - int Val = MI->getOperand(2).getImmedValue(); + assert(MI->getNumOperands() == 2 && "These should all have 2 operands!"); + if (MI->getOperand(1).isImmediate()) { + int Val = MI->getOperand(1).getImmedValue(); // If the value is the same when signed extended from 8 bits... if (Val == (signed int)(signed char)Val) { unsigned Opcode; @@ -85,8 +105,6 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, case X86::ADDri32: Opcode = X86::ADDri32b; break; case X86::SUBri16: Opcode = X86::SUBri16b; break; case X86::SUBri32: Opcode = X86::SUBri32b; break; - case X86::IMULri16: Opcode = X86::IMULri16b; break; - case X86::IMULri32: Opcode = X86::IMULri32b; break; case X86::ANDri16: Opcode = X86::ANDri16b; break; case X86::ANDri32: Opcode = X86::ANDri32b; break; case X86::ORri16: Opcode = X86::ORri16b; break; @@ -95,8 +113,7 @@ bool PH::PeepholeOptimize(MachineBasicBlock &MBB, case X86::XORri32: Opcode = X86::XORri32b; break; } unsigned R0 = MI->getOperand(0).getReg(); - unsigned R1 = MI->getOperand(1).getReg(); - *I = BuildMI(Opcode, 2, R0).addReg(R1).addZImm((char)Val); + *I = BuildMI(Opcode, 1, R0, MOTy::UseAndDef).addZImm((char)Val); delete MI; return true; } diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 0e8b889ad8..9b362be8c5 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -110,10 +110,10 @@ int X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF, Amount = (Amount+Align-1)/Align*Align; if (Old->getOpcode() == X86::ADJCALLSTACKDOWN) { - New=BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(Amount); + New=BuildMI(X86::SUBri32, 1, X86::ESP, MOTy::UseAndDef).addZImm(Amount); } else { assert(Old->getOpcode() == X86::ADJCALLSTACKUP); - New=BuildMI(X86::ADDri32, 2, X86::ESP).addReg(X86::ESP).addZImm(Amount); + New=BuildMI(X86::ADDri32, 1, X86::ESP, MOTy::UseAndDef).addZImm(Amount); } } } @@ -181,7 +181,7 @@ int X86RegisterInfo::emitPrologue(MachineFunction &MF) const { int EBPOffset = MFI->getObjectOffset(MFI->getObjectIndexEnd()-1)+4; if (NumBytes) { // adjust stack pointer: ESP -= numbytes - MI= BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); + MI= BuildMI(X86::SUBri32, 1, X86::ESP, MOTy::UseAndDef).addZImm(NumBytes); MBBI = MBB.insert(MBBI, MI)+1; } @@ -215,7 +215,7 @@ int X86RegisterInfo::emitPrologue(MachineFunction &MF) const { if (NumBytes) { // adjust stack pointer: ESP -= numbytes - MI= BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); + MI= BuildMI(X86::SUBri32, 1, X86::ESP, MOTy::UseAndDef).addZImm(NumBytes); MBB.insert(MBBI, MI); } } @@ -248,7 +248,7 @@ int X86RegisterInfo::emitEpilogue(MachineFunction &MF, unsigned NumBytes = MFI->getStackSize(); if (NumBytes) { // adjust stack pointer back: ESP += numbytes - MI =BuildMI(X86::ADDri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); + MI =BuildMI(X86::ADDri32, 1, X86::ESP, MOTy::UseAndDef).addZImm(NumBytes); MBBI = 1+MBB.insert(MBBI, MI); } } |