2002-11-23 06:42:50 +08:00
|
|
|
//===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===//
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
2003-01-15 06:00:31 +08:00
|
|
|
// This file contains the X86 implementation of the TargetInstrInfo class.
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-10-30 05:05:24 +08:00
|
|
|
#include "X86InstrInfo.h"
|
2002-12-03 13:42:53 +08:00
|
|
|
#include "X86.h"
|
2006-05-31 05:45:53 +08:00
|
|
|
#include "X86GenInstrInfo.inc"
|
2005-01-02 10:37:07 +08:00
|
|
|
#include "X86InstrBuilder.h"
|
2006-05-31 05:45:53 +08:00
|
|
|
#include "X86Subtarget.h"
|
|
|
|
#include "X86TargetMachine.h"
|
2007-09-07 12:06:50 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2003-05-24 08:09:50 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2007-12-31 12:13:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2006-12-02 05:52:41 +08:00
|
|
|
#include "llvm/CodeGen/LiveVariables.h"
|
2007-09-25 09:57:46 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2003-11-12 06:41:34 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-05-31 05:45:53 +08:00
|
|
|
X86InstrInfo::X86InstrInfo(X86TargetMachine &tm)
|
2008-01-01 09:03:04 +08:00
|
|
|
: TargetInstrInfoImpl(X86Insts, array_lengthof(X86Insts)),
|
2006-09-08 14:48:29 +08:00
|
|
|
TM(tm), RI(tm, *this) {
|
2002-10-26 06:55:53 +08:00
|
|
|
}
|
|
|
|
|
2003-12-29 01:35:08 +08:00
|
|
|
bool X86InstrInfo::isMoveInstr(const MachineInstr& MI,
|
|
|
|
unsigned& sourceReg,
|
|
|
|
unsigned& destReg) const {
|
|
|
|
MachineOpCode oc = MI.getOpcode();
|
2006-09-08 14:48:29 +08:00
|
|
|
if (oc == X86::MOV8rr || oc == X86::MOV16rr ||
|
|
|
|
oc == X86::MOV32rr || oc == X86::MOV64rr ||
|
2006-05-08 16:01:26 +08:00
|
|
|
oc == X86::MOV16to16_ || oc == X86::MOV32to32_ ||
|
2007-07-05 05:07:47 +08:00
|
|
|
oc == X86::MOV_Fp3232 || oc == X86::MOVSSrr || oc == X86::MOVSDrr ||
|
|
|
|
oc == X86::MOV_Fp3264 || oc == X86::MOV_Fp6432 || oc == X86::MOV_Fp6464 ||
|
2006-02-17 06:45:17 +08:00
|
|
|
oc == X86::FsMOVAPSrr || oc == X86::FsMOVAPDrr ||
|
2006-03-21 15:09:35 +08:00
|
|
|
oc == X86::MOVAPSrr || oc == X86::MOVAPDrr ||
|
2006-04-04 04:53:28 +08:00
|
|
|
oc == X86::MOVSS2PSrr || oc == X86::MOVSD2PDrr ||
|
2007-03-09 06:09:11 +08:00
|
|
|
oc == X86::MOVPS2SSrr || oc == X86::MOVPD2SDrr ||
|
2007-04-25 05:17:46 +08:00
|
|
|
oc == X86::MMX_MOVD64rr || oc == X86::MMX_MOVQ64rr) {
|
2007-04-25 15:12:14 +08:00
|
|
|
assert(MI.getNumOperands() >= 2 &&
|
2003-12-29 01:35:08 +08:00
|
|
|
MI.getOperand(0).isRegister() &&
|
|
|
|
MI.getOperand(1).isRegister() &&
|
|
|
|
"invalid register-register move instruction");
|
2004-02-14 05:01:20 +08:00
|
|
|
sourceReg = MI.getOperand(1).getReg();
|
|
|
|
destReg = MI.getOperand(0).getReg();
|
2003-12-29 01:35:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-31 17:38:47 +08:00
|
|
|
|
2006-02-03 04:12:32 +08:00
|
|
|
unsigned X86InstrInfo::isLoadFromStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case X86::MOV8rm:
|
|
|
|
case X86::MOV16rm:
|
2006-05-11 15:33:49 +08:00
|
|
|
case X86::MOV16_rm:
|
2006-02-03 04:12:32 +08:00
|
|
|
case X86::MOV32rm:
|
2006-05-11 15:33:49 +08:00
|
|
|
case X86::MOV32_rm:
|
2006-09-08 14:48:29 +08:00
|
|
|
case X86::MOV64rm:
|
2007-07-05 05:07:47 +08:00
|
|
|
case X86::LD_Fp64m:
|
2006-02-03 04:12:32 +08:00
|
|
|
case X86::MOVSSrm:
|
|
|
|
case X86::MOVSDrm:
|
2006-04-19 00:44:51 +08:00
|
|
|
case X86::MOVAPSrm:
|
|
|
|
case X86::MOVAPDrm:
|
2007-04-03 14:00:37 +08:00
|
|
|
case X86::MMX_MOVD64rm:
|
|
|
|
case X86::MMX_MOVQ64rm:
|
2007-12-31 07:10:15 +08:00
|
|
|
if (MI->getOperand(1).isFI() && MI->getOperand(2).isImm() &&
|
|
|
|
MI->getOperand(3).isReg() && MI->getOperand(4).isImm() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm() == 1 &&
|
2006-02-03 04:12:32 +08:00
|
|
|
MI->getOperand(3).getReg() == 0 &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(4).getImm() == 0) {
|
2007-12-31 07:10:15 +08:00
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2006-02-03 04:12:32 +08:00
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned X86InstrInfo::isStoreToStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case X86::MOV8mr:
|
|
|
|
case X86::MOV16mr:
|
2006-05-11 15:33:49 +08:00
|
|
|
case X86::MOV16_mr:
|
2006-02-03 04:12:32 +08:00
|
|
|
case X86::MOV32mr:
|
2006-05-11 15:33:49 +08:00
|
|
|
case X86::MOV32_mr:
|
2006-09-08 14:48:29 +08:00
|
|
|
case X86::MOV64mr:
|
2007-07-05 05:07:47 +08:00
|
|
|
case X86::ST_FpP64m:
|
2006-02-03 04:12:32 +08:00
|
|
|
case X86::MOVSSmr:
|
|
|
|
case X86::MOVSDmr:
|
2006-04-19 00:44:51 +08:00
|
|
|
case X86::MOVAPSmr:
|
|
|
|
case X86::MOVAPDmr:
|
2007-04-03 14:00:37 +08:00
|
|
|
case X86::MMX_MOVD64mr:
|
|
|
|
case X86::MMX_MOVQ64mr:
|
2007-04-04 07:48:32 +08:00
|
|
|
case X86::MMX_MOVNTQmr:
|
2007-12-31 07:10:15 +08:00
|
|
|
if (MI->getOperand(0).isFI() && MI->getOperand(1).isImm() &&
|
|
|
|
MI->getOperand(2).isReg() && MI->getOperand(3).isImm() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(1).getImm() == 1 &&
|
2006-02-03 04:38:12 +08:00
|
|
|
MI->getOperand(2).getReg() == 0 &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(3).getImm() == 0) {
|
2007-12-31 07:10:15 +08:00
|
|
|
FrameIndex = MI->getOperand(0).getIndex();
|
2006-02-03 04:12:32 +08:00
|
|
|
return MI->getOperand(4).getReg();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 07:58:46 +08:00
|
|
|
bool X86InstrInfo::isReallyTriviallyReMaterializable(MachineInstr *MI) const {
|
2007-06-15 04:50:44 +08:00
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case X86::MOV8rm:
|
|
|
|
case X86::MOV16rm:
|
|
|
|
case X86::MOV16_rm:
|
|
|
|
case X86::MOV32rm:
|
|
|
|
case X86::MOV32_rm:
|
|
|
|
case X86::MOV64rm:
|
2007-07-05 05:07:47 +08:00
|
|
|
case X86::LD_Fp64m:
|
2007-06-15 04:50:44 +08:00
|
|
|
case X86::MOVSSrm:
|
|
|
|
case X86::MOVSDrm:
|
|
|
|
case X86::MOVAPSrm:
|
|
|
|
case X86::MOVAPDrm:
|
|
|
|
case X86::MMX_MOVD64rm:
|
|
|
|
case X86::MMX_MOVQ64rm:
|
2007-06-19 09:48:05 +08:00
|
|
|
// Loads from constant pools are trivially rematerializable.
|
2007-06-15 04:50:44 +08:00
|
|
|
return MI->getOperand(1).isRegister() && MI->getOperand(2).isImmediate() &&
|
|
|
|
MI->getOperand(3).isRegister() && MI->getOperand(4).isConstantPoolIndex() &&
|
|
|
|
MI->getOperand(1).getReg() == 0 &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm() == 1 &&
|
2007-06-15 04:50:44 +08:00
|
|
|
MI->getOperand(3).getReg() == 0;
|
|
|
|
}
|
2007-06-26 08:48:07 +08:00
|
|
|
// All other instructions marked M_REMATERIALIZABLE are always trivially
|
|
|
|
// rematerializable.
|
|
|
|
return true;
|
2007-06-15 04:50:44 +08:00
|
|
|
}
|
|
|
|
|
2007-12-30 11:18:58 +08:00
|
|
|
/// isDefinedInEntryBlock - Goes through the entry block to see if the given
|
|
|
|
/// virtual register is indeed defined in the entry block.
|
|
|
|
///
|
|
|
|
bool X86InstrInfo::isDefinedInEntryBlock(const MachineBasicBlock &Entry,
|
|
|
|
unsigned VReg) const {
|
|
|
|
assert(MRegisterInfo::isVirtualRegister(VReg) &&
|
|
|
|
"Map only holds virtual registers!");
|
|
|
|
MachineInstrMap.grow(VReg);
|
|
|
|
if (MachineInstrMap[VReg]) return true;
|
|
|
|
|
|
|
|
MachineBasicBlock::const_iterator I = Entry.begin(), E = Entry.end();
|
|
|
|
|
|
|
|
for (; I != E; ++I) {
|
|
|
|
const MachineInstr &MI = *I;
|
|
|
|
unsigned NumOps = MI.getNumOperands();
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumOps; ++i) {
|
|
|
|
const MachineOperand &MO = MI.getOperand(i);
|
|
|
|
|
|
|
|
if(MO.isRegister() && MO.isDef() &&
|
|
|
|
MRegisterInfo::isVirtualRegister(MO.getReg()) &&
|
|
|
|
MO.getReg() == VReg) {
|
|
|
|
MachineInstrMap[VReg] = &MI;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-12-18 07:07:56 +08:00
|
|
|
/// isReallySideEffectFree - If the M_MAY_HAVE_SIDE_EFFECTS flag is set, this
|
|
|
|
/// method is called to determine if the specific instance of this instruction
|
|
|
|
/// has side effects. This is useful in cases of instructions, like loads, which
|
|
|
|
/// generally always have side effects. A load from a constant pool doesn't have
|
|
|
|
/// side effects, though. So we need to differentiate it from the general case.
|
|
|
|
bool X86InstrInfo::isReallySideEffectFree(MachineInstr *MI) const {
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
2007-12-30 11:18:58 +08:00
|
|
|
case X86::MOV32rm:
|
|
|
|
if (MI->getOperand(1).isRegister()) {
|
|
|
|
unsigned Reg = MI->getOperand(1).getReg();
|
|
|
|
|
|
|
|
// Loads from global addresses which aren't redefined in the function are
|
|
|
|
// side effect free.
|
|
|
|
if (MRegisterInfo::isVirtualRegister(Reg) &&
|
|
|
|
isDefinedInEntryBlock(MI->getParent()->getParent()->front(), Reg) &&
|
|
|
|
MI->getOperand(2).isImmediate() &&
|
|
|
|
MI->getOperand(3).isRegister() &&
|
|
|
|
MI->getOperand(4).isGlobalAddress() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm() == 1 &&
|
2007-12-30 11:18:58 +08:00
|
|
|
MI->getOperand(3).getReg() == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2007-12-18 07:07:56 +08:00
|
|
|
case X86::MOV8rm:
|
|
|
|
case X86::MOV16rm:
|
|
|
|
case X86::MOV16_rm:
|
|
|
|
case X86::MOV32_rm:
|
|
|
|
case X86::MOV64rm:
|
|
|
|
case X86::LD_Fp64m:
|
|
|
|
case X86::MOVSSrm:
|
|
|
|
case X86::MOVSDrm:
|
|
|
|
case X86::MOVAPSrm:
|
|
|
|
case X86::MOVAPDrm:
|
|
|
|
case X86::MMX_MOVD64rm:
|
|
|
|
case X86::MMX_MOVQ64rm:
|
|
|
|
// Loads from constant pools have no side effects
|
2007-12-30 11:18:58 +08:00
|
|
|
return MI->getOperand(1).isRegister() &&
|
|
|
|
MI->getOperand(2).isImmediate() &&
|
|
|
|
MI->getOperand(3).isRegister() &&
|
|
|
|
MI->getOperand(4).isConstantPoolIndex() &&
|
2007-12-18 07:07:56 +08:00
|
|
|
MI->getOperand(1).getReg() == 0 &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm() == 1 &&
|
2007-12-18 07:07:56 +08:00
|
|
|
MI->getOperand(3).getReg() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other instances of these instructions are presumed to have side
|
|
|
|
// effects.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-05 16:04:01 +08:00
|
|
|
/// hasLiveCondCodeDef - True if MI has a condition code def, e.g. EFLAGS, that
|
|
|
|
/// is not marked dead.
|
|
|
|
static bool hasLiveCondCodeDef(MachineInstr *MI) {
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MI->getOperand(i);
|
|
|
|
if (MO.isRegister() && MO.isDef() &&
|
|
|
|
MO.getReg() == X86::EFLAGS && !MO.isDead()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-02 10:37:07 +08:00
|
|
|
/// convertToThreeAddress - This method must be implemented by targets that
|
|
|
|
/// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
|
|
|
|
/// may be able to convert a two-address instruction into a true
|
|
|
|
/// three-address instruction on demand. This allows the X86 target (for
|
|
|
|
/// example) to convert ADD and SHL instructions into LEA instructions if they
|
|
|
|
/// would require register copies due to two-addressness.
|
|
|
|
///
|
|
|
|
/// This method returns a null pointer if the transformation cannot be
|
|
|
|
/// performed, otherwise it returns the new instruction.
|
|
|
|
///
|
2006-12-02 05:52:41 +08:00
|
|
|
MachineInstr *
|
|
|
|
X86InstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
|
|
|
|
MachineBasicBlock::iterator &MBBI,
|
|
|
|
LiveVariables &LV) const {
|
|
|
|
MachineInstr *MI = MBBI;
|
2005-01-02 10:37:07 +08:00
|
|
|
// All instructions input are two-addr instructions. Get the known operands.
|
|
|
|
unsigned Dest = MI->getOperand(0).getReg();
|
|
|
|
unsigned Src = MI->getOperand(1).getReg();
|
|
|
|
|
2006-11-16 04:58:11 +08:00
|
|
|
MachineInstr *NewMI = NULL;
|
2006-12-02 05:52:41 +08:00
|
|
|
// FIXME: 16-bit LEA's are really slow on Athlons, but not bad on P4's. When
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
// we have better subtarget support, enable the 16-bit LEA generation here.
|
2006-12-02 05:52:41 +08:00
|
|
|
bool DisableLEA16 = true;
|
|
|
|
|
2007-10-06 04:34:26 +08:00
|
|
|
unsigned MIOpc = MI->getOpcode();
|
|
|
|
switch (MIOpc) {
|
2006-05-31 04:26:50 +08:00
|
|
|
case X86::SHUFPSrri: {
|
|
|
|
assert(MI->getNumOperands() == 4 && "Unknown shufps instruction!");
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
if (!TM.getSubtarget<X86Subtarget>().hasSSE2()) return 0;
|
|
|
|
|
2006-05-31 05:45:53 +08:00
|
|
|
unsigned A = MI->getOperand(0).getReg();
|
|
|
|
unsigned B = MI->getOperand(1).getReg();
|
|
|
|
unsigned C = MI->getOperand(2).getReg();
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
unsigned M = MI->getOperand(3).getImm();
|
|
|
|
if (B != C) return 0;
|
2006-11-28 07:37:22 +08:00
|
|
|
NewMI = BuildMI(get(X86::PSHUFDri), A).addReg(B).addImm(M);
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-03-29 02:12:31 +08:00
|
|
|
case X86::SHL64ri: {
|
2007-09-15 05:48:26 +08:00
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown shift instruction!");
|
2007-03-29 02:12:31 +08:00
|
|
|
// NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
|
|
|
|
// the flags produced by a shift yet, so this is safe.
|
|
|
|
unsigned Dest = MI->getOperand(0).getReg();
|
|
|
|
unsigned Src = MI->getOperand(1).getReg();
|
|
|
|
unsigned ShAmt = MI->getOperand(2).getImm();
|
|
|
|
if (ShAmt == 0 || ShAmt >= 4) return 0;
|
|
|
|
|
|
|
|
NewMI = BuildMI(get(X86::LEA64r), Dest)
|
|
|
|
.addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
|
|
|
|
break;
|
|
|
|
}
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
case X86::SHL32ri: {
|
2007-09-15 05:48:26 +08:00
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown shift instruction!");
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
// NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
|
|
|
|
// the flags produced by a shift yet, so this is safe.
|
|
|
|
unsigned Dest = MI->getOperand(0).getReg();
|
|
|
|
unsigned Src = MI->getOperand(1).getReg();
|
|
|
|
unsigned ShAmt = MI->getOperand(2).getImm();
|
|
|
|
if (ShAmt == 0 || ShAmt >= 4) return 0;
|
|
|
|
|
2007-03-28 08:58:40 +08:00
|
|
|
unsigned Opc = TM.getSubtarget<X86Subtarget>().is64Bit() ?
|
|
|
|
X86::LEA64_32r : X86::LEA32r;
|
|
|
|
NewMI = BuildMI(get(Opc), Dest)
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
.addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X86::SHL16ri: {
|
2007-09-15 05:48:26 +08:00
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown shift instruction!");
|
2007-09-06 08:14:41 +08:00
|
|
|
// NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
|
|
|
|
// the flags produced by a shift yet, so this is safe.
|
|
|
|
unsigned Dest = MI->getOperand(0).getReg();
|
|
|
|
unsigned Src = MI->getOperand(1).getReg();
|
|
|
|
unsigned ShAmt = MI->getOperand(2).getImm();
|
|
|
|
if (ShAmt == 0 || ShAmt >= 4) return 0;
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
|
2007-08-11 05:18:25 +08:00
|
|
|
if (DisableLEA16) {
|
|
|
|
// If 16-bit LEA is disabled, use 32-bit LEA via subregisters.
|
2007-12-31 12:13:23 +08:00
|
|
|
MachineRegisterInfo &RegInfo = MFI->getParent()->getRegInfo();
|
2007-09-06 08:14:41 +08:00
|
|
|
unsigned Opc = TM.getSubtarget<X86Subtarget>().is64Bit()
|
|
|
|
? X86::LEA64_32r : X86::LEA32r;
|
2007-12-31 12:13:23 +08:00
|
|
|
unsigned leaInReg = RegInfo.createVirtualRegister(&X86::GR32RegClass);
|
|
|
|
unsigned leaOutReg = RegInfo.createVirtualRegister(&X86::GR32RegClass);
|
2007-08-11 05:18:25 +08:00
|
|
|
|
2007-09-06 08:14:41 +08:00
|
|
|
MachineInstr *Ins =
|
|
|
|
BuildMI(get(X86::INSERT_SUBREG), leaInReg).addReg(Src).addImm(2);
|
2007-08-11 05:18:25 +08:00
|
|
|
Ins->copyKillDeadInfo(MI);
|
|
|
|
|
|
|
|
NewMI = BuildMI(get(Opc), leaOutReg)
|
|
|
|
.addReg(0).addImm(1 << ShAmt).addReg(leaInReg).addImm(0);
|
|
|
|
|
2007-09-06 08:14:41 +08:00
|
|
|
MachineInstr *Ext =
|
|
|
|
BuildMI(get(X86::EXTRACT_SUBREG), Dest).addReg(leaOutReg).addImm(2);
|
2007-08-11 05:18:25 +08:00
|
|
|
Ext->copyKillDeadInfo(MI);
|
|
|
|
|
|
|
|
MFI->insert(MBBI, Ins); // Insert the insert_subreg
|
|
|
|
LV.instructionChanged(MI, NewMI); // Update live variables
|
|
|
|
LV.addVirtualRegisterKilled(leaInReg, NewMI);
|
|
|
|
MFI->insert(MBBI, NewMI); // Insert the new inst
|
|
|
|
LV.addVirtualRegisterKilled(leaOutReg, Ext);
|
2007-09-06 08:14:41 +08:00
|
|
|
MFI->insert(MBBI, Ext); // Insert the extract_subreg
|
2007-08-11 05:18:25 +08:00
|
|
|
return Ext;
|
|
|
|
} else {
|
|
|
|
NewMI = BuildMI(get(X86::LEA16r), Dest)
|
|
|
|
.addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
|
|
|
|
}
|
Two changes:
1) codegen a shift of a register as a shift, not an LEA.
2) teach the RA to convert a shift to an LEA instruction if it wants something
in three-address form.
This gives us asm diffs like:
- leal (,%eax,4), %eax
+ shll $2, %eax
which is faster on some processors and smaller on all of them.
and, more interestingly:
- movl 24(%esi), %eax
- leal (,%eax,4), %edi
+ movl 24(%esi), %edi
+ shll $2, %edi
Without #2, #1 was a significant pessimization in some cases.
This implements CodeGen/X86/shift-codegen.ll
llvm-svn: 35204
2007-03-20 14:08:29 +08:00
|
|
|
break;
|
2006-05-31 04:26:50 +08:00
|
|
|
}
|
2007-10-06 04:34:26 +08:00
|
|
|
default: {
|
|
|
|
// The following opcodes also sets the condition code register(s). Only
|
|
|
|
// convert them to equivalent lea if the condition code register def's
|
|
|
|
// are dead!
|
|
|
|
if (hasLiveCondCodeDef(MI))
|
|
|
|
return 0;
|
2006-05-31 04:26:50 +08:00
|
|
|
|
2007-10-09 15:14:53 +08:00
|
|
|
bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
|
2007-10-06 04:34:26 +08:00
|
|
|
switch (MIOpc) {
|
|
|
|
default: return 0;
|
|
|
|
case X86::INC64r:
|
2007-10-06 05:55:32 +08:00
|
|
|
case X86::INC32r: {
|
2007-10-06 04:34:26 +08:00
|
|
|
assert(MI->getNumOperands() >= 2 && "Unknown inc instruction!");
|
2007-10-09 15:14:53 +08:00
|
|
|
unsigned Opc = MIOpc == X86::INC64r ? X86::LEA64r
|
|
|
|
: (is64Bit ? X86::LEA64_32r : X86::LEA32r);
|
2007-10-06 04:34:26 +08:00
|
|
|
NewMI = addRegOffset(BuildMI(get(Opc), Dest), Src, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X86::INC16r:
|
|
|
|
case X86::INC64_16r:
|
|
|
|
if (DisableLEA16) return 0;
|
|
|
|
assert(MI->getNumOperands() >= 2 && "Unknown inc instruction!");
|
|
|
|
NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src, 1);
|
|
|
|
break;
|
|
|
|
case X86::DEC64r:
|
2007-10-06 05:55:32 +08:00
|
|
|
case X86::DEC32r: {
|
2007-10-06 04:34:26 +08:00
|
|
|
assert(MI->getNumOperands() >= 2 && "Unknown dec instruction!");
|
2007-10-09 15:14:53 +08:00
|
|
|
unsigned Opc = MIOpc == X86::DEC64r ? X86::LEA64r
|
|
|
|
: (is64Bit ? X86::LEA64_32r : X86::LEA32r);
|
2007-10-06 04:34:26 +08:00
|
|
|
NewMI = addRegOffset(BuildMI(get(Opc), Dest), Src, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X86::DEC16r:
|
|
|
|
case X86::DEC64_16r:
|
|
|
|
if (DisableLEA16) return 0;
|
|
|
|
assert(MI->getNumOperands() >= 2 && "Unknown dec instruction!");
|
|
|
|
NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src, -1);
|
|
|
|
break;
|
|
|
|
case X86::ADD64rr:
|
|
|
|
case X86::ADD32rr: {
|
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown add instruction!");
|
2007-10-09 15:14:53 +08:00
|
|
|
unsigned Opc = MIOpc == X86::ADD64rr ? X86::LEA64r
|
|
|
|
: (is64Bit ? X86::LEA64_32r : X86::LEA32r);
|
2007-10-06 04:34:26 +08:00
|
|
|
NewMI = addRegReg(BuildMI(get(Opc), Dest), Src,
|
|
|
|
MI->getOperand(2).getReg());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X86::ADD16rr:
|
|
|
|
if (DisableLEA16) return 0;
|
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown add instruction!");
|
|
|
|
NewMI = addRegReg(BuildMI(get(X86::LEA16r), Dest), Src,
|
|
|
|
MI->getOperand(2).getReg());
|
|
|
|
break;
|
|
|
|
case X86::ADD64ri32:
|
|
|
|
case X86::ADD64ri8:
|
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown add instruction!");
|
|
|
|
if (MI->getOperand(2).isImmediate())
|
|
|
|
NewMI = addRegOffset(BuildMI(get(X86::LEA64r), Dest), Src,
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm());
|
2007-10-06 04:34:26 +08:00
|
|
|
break;
|
|
|
|
case X86::ADD32ri:
|
|
|
|
case X86::ADD32ri8:
|
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown add instruction!");
|
2007-10-09 15:14:53 +08:00
|
|
|
if (MI->getOperand(2).isImmediate()) {
|
|
|
|
unsigned Opc = is64Bit ? X86::LEA64_32r : X86::LEA32r;
|
|
|
|
NewMI = addRegOffset(BuildMI(get(Opc), Dest), Src,
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm());
|
2007-10-09 15:14:53 +08:00
|
|
|
}
|
2007-10-06 04:34:26 +08:00
|
|
|
break;
|
|
|
|
case X86::ADD16ri:
|
|
|
|
case X86::ADD16ri8:
|
|
|
|
if (DisableLEA16) return 0;
|
|
|
|
assert(MI->getNumOperands() >= 3 && "Unknown add instruction!");
|
|
|
|
if (MI->getOperand(2).isImmediate())
|
|
|
|
NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src,
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm());
|
2007-10-06 04:34:26 +08:00
|
|
|
break;
|
|
|
|
case X86::SHL16ri:
|
|
|
|
if (DisableLEA16) return 0;
|
|
|
|
case X86::SHL32ri:
|
|
|
|
case X86::SHL64ri: {
|
|
|
|
assert(MI->getNumOperands() >= 3 && MI->getOperand(2).isImmediate() &&
|
|
|
|
"Unknown shl instruction!");
|
2007-12-31 04:49:49 +08:00
|
|
|
unsigned ShAmt = MI->getOperand(2).getImm();
|
2007-10-06 04:34:26 +08:00
|
|
|
if (ShAmt == 1 || ShAmt == 2 || ShAmt == 3) {
|
|
|
|
X86AddressMode AM;
|
|
|
|
AM.Scale = 1 << ShAmt;
|
|
|
|
AM.IndexReg = Src;
|
|
|
|
unsigned Opc = MIOpc == X86::SHL64ri ? X86::LEA64r
|
2007-10-09 15:14:53 +08:00
|
|
|
: (MIOpc == X86::SHL32ri
|
|
|
|
? (is64Bit ? X86::LEA64_32r : X86::LEA32r) : X86::LEA16r);
|
2007-10-06 04:34:26 +08:00
|
|
|
NewMI = addFullAddress(BuildMI(get(Opc), Dest), AM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-01-02 10:37:07 +08:00
|
|
|
}
|
|
|
|
}
|
2006-12-02 05:52:41 +08:00
|
|
|
}
|
2007-10-06 04:34:26 +08:00
|
|
|
|
|
|
|
NewMI->copyKillDeadInfo(MI);
|
|
|
|
LV.instructionChanged(MI, NewMI); // Update live variables
|
|
|
|
MFI->insert(MBBI, NewMI); // Insert the new inst
|
2006-11-16 04:58:11 +08:00
|
|
|
return NewMI;
|
2005-01-02 10:37:07 +08:00
|
|
|
}
|
|
|
|
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
/// commuteInstruction - We have a few instructions that must be hacked on to
|
|
|
|
/// commute them.
|
|
|
|
///
|
|
|
|
MachineInstr *X86InstrInfo::commuteInstruction(MachineInstr *MI) const {
|
|
|
|
switch (MI->getOpcode()) {
|
2005-01-19 15:31:24 +08:00
|
|
|
case X86::SHRD16rri8: // A = SHRD16rri8 B, C, I -> A = SHLD16rri8 C, B, (16-I)
|
|
|
|
case X86::SHLD16rri8: // A = SHLD16rri8 B, C, I -> A = SHRD16rri8 C, B, (16-I)
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
case X86::SHRD32rri8: // A = SHRD32rri8 B, C, I -> A = SHLD32rri8 C, B, (32-I)
|
2007-09-15 07:17:45 +08:00
|
|
|
case X86::SHLD32rri8: // A = SHLD32rri8 B, C, I -> A = SHRD32rri8 C, B, (32-I)
|
|
|
|
case X86::SHRD64rri8: // A = SHRD64rri8 B, C, I -> A = SHLD64rri8 C, B, (64-I)
|
|
|
|
case X86::SHLD64rri8:{// A = SHLD64rri8 B, C, I -> A = SHRD64rri8 C, B, (64-I)
|
2005-01-19 15:31:24 +08:00
|
|
|
unsigned Opc;
|
|
|
|
unsigned Size;
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
case X86::SHRD16rri8: Size = 16; Opc = X86::SHLD16rri8; break;
|
|
|
|
case X86::SHLD16rri8: Size = 16; Opc = X86::SHRD16rri8; break;
|
|
|
|
case X86::SHRD32rri8: Size = 32; Opc = X86::SHLD32rri8; break;
|
|
|
|
case X86::SHLD32rri8: Size = 32; Opc = X86::SHRD32rri8; break;
|
2007-09-15 07:17:45 +08:00
|
|
|
case X86::SHRD64rri8: Size = 64; Opc = X86::SHLD64rri8; break;
|
|
|
|
case X86::SHLD64rri8: Size = 64; Opc = X86::SHRD64rri8; break;
|
2005-01-19 15:31:24 +08:00
|
|
|
}
|
2007-12-31 04:49:49 +08:00
|
|
|
unsigned Amt = MI->getOperand(3).getImm();
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
unsigned A = MI->getOperand(0).getReg();
|
|
|
|
unsigned B = MI->getOperand(1).getReg();
|
|
|
|
unsigned C = MI->getOperand(2).getReg();
|
2006-11-16 04:58:11 +08:00
|
|
|
bool BisKill = MI->getOperand(1).isKill();
|
|
|
|
bool CisKill = MI->getOperand(2).isKill();
|
2006-11-28 07:37:22 +08:00
|
|
|
return BuildMI(get(Opc), A).addReg(C, false, false, CisKill)
|
2006-11-16 04:58:11 +08:00
|
|
|
.addReg(B, false, false, BisKill).addImm(Size-Amt);
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
}
|
2007-10-06 07:13:21 +08:00
|
|
|
case X86::CMOVB16rr:
|
|
|
|
case X86::CMOVB32rr:
|
|
|
|
case X86::CMOVB64rr:
|
|
|
|
case X86::CMOVAE16rr:
|
|
|
|
case X86::CMOVAE32rr:
|
|
|
|
case X86::CMOVAE64rr:
|
|
|
|
case X86::CMOVE16rr:
|
|
|
|
case X86::CMOVE32rr:
|
|
|
|
case X86::CMOVE64rr:
|
|
|
|
case X86::CMOVNE16rr:
|
|
|
|
case X86::CMOVNE32rr:
|
|
|
|
case X86::CMOVNE64rr:
|
|
|
|
case X86::CMOVBE16rr:
|
|
|
|
case X86::CMOVBE32rr:
|
|
|
|
case X86::CMOVBE64rr:
|
|
|
|
case X86::CMOVA16rr:
|
|
|
|
case X86::CMOVA32rr:
|
|
|
|
case X86::CMOVA64rr:
|
|
|
|
case X86::CMOVL16rr:
|
|
|
|
case X86::CMOVL32rr:
|
|
|
|
case X86::CMOVL64rr:
|
|
|
|
case X86::CMOVGE16rr:
|
|
|
|
case X86::CMOVGE32rr:
|
|
|
|
case X86::CMOVGE64rr:
|
|
|
|
case X86::CMOVLE16rr:
|
|
|
|
case X86::CMOVLE32rr:
|
|
|
|
case X86::CMOVLE64rr:
|
|
|
|
case X86::CMOVG16rr:
|
|
|
|
case X86::CMOVG32rr:
|
|
|
|
case X86::CMOVG64rr:
|
|
|
|
case X86::CMOVS16rr:
|
|
|
|
case X86::CMOVS32rr:
|
|
|
|
case X86::CMOVS64rr:
|
|
|
|
case X86::CMOVNS16rr:
|
|
|
|
case X86::CMOVNS32rr:
|
|
|
|
case X86::CMOVNS64rr:
|
|
|
|
case X86::CMOVP16rr:
|
|
|
|
case X86::CMOVP32rr:
|
|
|
|
case X86::CMOVP64rr:
|
|
|
|
case X86::CMOVNP16rr:
|
|
|
|
case X86::CMOVNP32rr:
|
|
|
|
case X86::CMOVNP64rr: {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case X86::CMOVB16rr: Opc = X86::CMOVAE16rr; break;
|
|
|
|
case X86::CMOVB32rr: Opc = X86::CMOVAE32rr; break;
|
|
|
|
case X86::CMOVB64rr: Opc = X86::CMOVAE64rr; break;
|
|
|
|
case X86::CMOVAE16rr: Opc = X86::CMOVB16rr; break;
|
|
|
|
case X86::CMOVAE32rr: Opc = X86::CMOVB32rr; break;
|
|
|
|
case X86::CMOVAE64rr: Opc = X86::CMOVB64rr; break;
|
|
|
|
case X86::CMOVE16rr: Opc = X86::CMOVNE16rr; break;
|
|
|
|
case X86::CMOVE32rr: Opc = X86::CMOVNE32rr; break;
|
|
|
|
case X86::CMOVE64rr: Opc = X86::CMOVNE64rr; break;
|
|
|
|
case X86::CMOVNE16rr: Opc = X86::CMOVE16rr; break;
|
|
|
|
case X86::CMOVNE32rr: Opc = X86::CMOVE32rr; break;
|
|
|
|
case X86::CMOVNE64rr: Opc = X86::CMOVE64rr; break;
|
|
|
|
case X86::CMOVBE16rr: Opc = X86::CMOVA16rr; break;
|
|
|
|
case X86::CMOVBE32rr: Opc = X86::CMOVA32rr; break;
|
|
|
|
case X86::CMOVBE64rr: Opc = X86::CMOVA64rr; break;
|
|
|
|
case X86::CMOVA16rr: Opc = X86::CMOVBE16rr; break;
|
|
|
|
case X86::CMOVA32rr: Opc = X86::CMOVBE32rr; break;
|
|
|
|
case X86::CMOVA64rr: Opc = X86::CMOVBE64rr; break;
|
|
|
|
case X86::CMOVL16rr: Opc = X86::CMOVGE16rr; break;
|
|
|
|
case X86::CMOVL32rr: Opc = X86::CMOVGE32rr; break;
|
|
|
|
case X86::CMOVL64rr: Opc = X86::CMOVGE64rr; break;
|
|
|
|
case X86::CMOVGE16rr: Opc = X86::CMOVL16rr; break;
|
|
|
|
case X86::CMOVGE32rr: Opc = X86::CMOVL32rr; break;
|
|
|
|
case X86::CMOVGE64rr: Opc = X86::CMOVL64rr; break;
|
|
|
|
case X86::CMOVLE16rr: Opc = X86::CMOVG16rr; break;
|
|
|
|
case X86::CMOVLE32rr: Opc = X86::CMOVG32rr; break;
|
|
|
|
case X86::CMOVLE64rr: Opc = X86::CMOVG64rr; break;
|
|
|
|
case X86::CMOVG16rr: Opc = X86::CMOVLE16rr; break;
|
|
|
|
case X86::CMOVG32rr: Opc = X86::CMOVLE32rr; break;
|
|
|
|
case X86::CMOVG64rr: Opc = X86::CMOVLE64rr; break;
|
|
|
|
case X86::CMOVS16rr: Opc = X86::CMOVNS16rr; break;
|
|
|
|
case X86::CMOVS32rr: Opc = X86::CMOVNS32rr; break;
|
|
|
|
case X86::CMOVS64rr: Opc = X86::CMOVNS32rr; break;
|
|
|
|
case X86::CMOVNS16rr: Opc = X86::CMOVS16rr; break;
|
|
|
|
case X86::CMOVNS32rr: Opc = X86::CMOVS32rr; break;
|
|
|
|
case X86::CMOVNS64rr: Opc = X86::CMOVS64rr; break;
|
|
|
|
case X86::CMOVP16rr: Opc = X86::CMOVNP16rr; break;
|
|
|
|
case X86::CMOVP32rr: Opc = X86::CMOVNP32rr; break;
|
|
|
|
case X86::CMOVP64rr: Opc = X86::CMOVNP32rr; break;
|
|
|
|
case X86::CMOVNP16rr: Opc = X86::CMOVP16rr; break;
|
|
|
|
case X86::CMOVNP32rr: Opc = X86::CMOVP32rr; break;
|
|
|
|
case X86::CMOVNP64rr: Opc = X86::CMOVP64rr; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MI->setInstrDescriptor(get(Opc));
|
|
|
|
// Fallthrough intended.
|
|
|
|
}
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
default:
|
2008-01-01 09:05:34 +08:00
|
|
|
return TargetInstrInfoImpl::commuteInstruction(MI);
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
static X86::CondCode GetCondFromBranchOpc(unsigned BrOpc) {
|
|
|
|
switch (BrOpc) {
|
|
|
|
default: return X86::COND_INVALID;
|
|
|
|
case X86::JE: return X86::COND_E;
|
|
|
|
case X86::JNE: return X86::COND_NE;
|
|
|
|
case X86::JL: return X86::COND_L;
|
|
|
|
case X86::JLE: return X86::COND_LE;
|
|
|
|
case X86::JG: return X86::COND_G;
|
|
|
|
case X86::JGE: return X86::COND_GE;
|
|
|
|
case X86::JB: return X86::COND_B;
|
|
|
|
case X86::JBE: return X86::COND_BE;
|
|
|
|
case X86::JA: return X86::COND_A;
|
|
|
|
case X86::JAE: return X86::COND_AE;
|
|
|
|
case X86::JS: return X86::COND_S;
|
|
|
|
case X86::JNS: return X86::COND_NS;
|
|
|
|
case X86::JP: return X86::COND_P;
|
|
|
|
case X86::JNP: return X86::COND_NP;
|
|
|
|
case X86::JO: return X86::COND_O;
|
|
|
|
case X86::JNO: return X86::COND_NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned X86::GetCondBranchFromCond(X86::CondCode CC) {
|
|
|
|
switch (CC) {
|
|
|
|
default: assert(0 && "Illegal condition code!");
|
2007-09-29 08:00:36 +08:00
|
|
|
case X86::COND_E: return X86::JE;
|
|
|
|
case X86::COND_NE: return X86::JNE;
|
|
|
|
case X86::COND_L: return X86::JL;
|
|
|
|
case X86::COND_LE: return X86::JLE;
|
|
|
|
case X86::COND_G: return X86::JG;
|
|
|
|
case X86::COND_GE: return X86::JGE;
|
|
|
|
case X86::COND_B: return X86::JB;
|
|
|
|
case X86::COND_BE: return X86::JBE;
|
|
|
|
case X86::COND_A: return X86::JA;
|
|
|
|
case X86::COND_AE: return X86::JAE;
|
|
|
|
case X86::COND_S: return X86::JS;
|
|
|
|
case X86::COND_NS: return X86::JNS;
|
|
|
|
case X86::COND_P: return X86::JP;
|
|
|
|
case X86::COND_NP: return X86::JNP;
|
|
|
|
case X86::COND_O: return X86::JO;
|
|
|
|
case X86::COND_NO: return X86::JNO;
|
2006-10-21 01:42:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 13:52:40 +08:00
|
|
|
/// GetOppositeBranchCondition - Return the inverse of the specified condition,
|
|
|
|
/// e.g. turning COND_E to COND_NE.
|
|
|
|
X86::CondCode X86::GetOppositeBranchCondition(X86::CondCode CC) {
|
|
|
|
switch (CC) {
|
|
|
|
default: assert(0 && "Illegal condition code!");
|
|
|
|
case X86::COND_E: return X86::COND_NE;
|
|
|
|
case X86::COND_NE: return X86::COND_E;
|
|
|
|
case X86::COND_L: return X86::COND_GE;
|
|
|
|
case X86::COND_LE: return X86::COND_G;
|
|
|
|
case X86::COND_G: return X86::COND_LE;
|
|
|
|
case X86::COND_GE: return X86::COND_L;
|
|
|
|
case X86::COND_B: return X86::COND_AE;
|
|
|
|
case X86::COND_BE: return X86::COND_A;
|
|
|
|
case X86::COND_A: return X86::COND_BE;
|
|
|
|
case X86::COND_AE: return X86::COND_B;
|
|
|
|
case X86::COND_S: return X86::COND_NS;
|
|
|
|
case X86::COND_NS: return X86::COND_S;
|
|
|
|
case X86::COND_P: return X86::COND_NP;
|
|
|
|
case X86::COND_NP: return X86::COND_P;
|
|
|
|
case X86::COND_O: return X86::COND_NO;
|
|
|
|
case X86::COND_NO: return X86::COND_O;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-15 06:03:45 +08:00
|
|
|
bool X86InstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
|
2007-07-07 07:22:03 +08:00
|
|
|
const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
|
|
|
|
if (TID->Flags & M_TERMINATOR_FLAG) {
|
|
|
|
// Conditional branch is a special case.
|
|
|
|
if ((TID->Flags & M_BRANCH_FLAG) != 0 && (TID->Flags & M_BARRIER_FLAG) == 0)
|
|
|
|
return true;
|
|
|
|
if ((TID->Flags & M_PREDICABLE) == 0)
|
|
|
|
return true;
|
2007-06-15 06:03:45 +08:00
|
|
|
return !isPredicated(MI);
|
2007-07-07 07:22:03 +08:00
|
|
|
}
|
2007-06-15 06:03:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
2006-10-21 13:52:40 +08:00
|
|
|
|
2007-07-27 01:32:14 +08:00
|
|
|
// For purposes of branch analysis do not count FP_REG_KILL as a terminator.
|
|
|
|
static bool isBrAnalysisUnpredicatedTerminator(const MachineInstr *MI,
|
|
|
|
const X86InstrInfo &TII) {
|
|
|
|
if (MI->getOpcode() == X86::FP_REG_KILL)
|
|
|
|
return false;
|
|
|
|
return TII.isUnpredicatedTerminator(MI);
|
|
|
|
}
|
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
bool X86InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
std::vector<MachineOperand> &Cond) const {
|
|
|
|
// If the block has no terminators, it just falls into the block after it.
|
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
2007-07-27 01:32:14 +08:00
|
|
|
if (I == MBB.begin() || !isBrAnalysisUnpredicatedTerminator(--I, *this))
|
2006-10-21 01:42:20 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the last instruction in the block.
|
|
|
|
MachineInstr *LastInst = I;
|
|
|
|
|
|
|
|
// If there is only one terminator instruction, process it.
|
2007-07-27 01:32:14 +08:00
|
|
|
if (I == MBB.begin() || !isBrAnalysisUnpredicatedTerminator(--I, *this)) {
|
2006-10-21 01:42:20 +08:00
|
|
|
if (!isBranch(LastInst->getOpcode()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If the block ends with a branch there are 3 possibilities:
|
|
|
|
// it's an unconditional, conditional, or indirect branch.
|
|
|
|
|
|
|
|
if (LastInst->getOpcode() == X86::JMP) {
|
2007-12-31 07:10:15 +08:00
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
2006-10-21 01:42:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
X86::CondCode BranchCode = GetCondFromBranchOpc(LastInst->getOpcode());
|
|
|
|
if (BranchCode == X86::COND_INVALID)
|
|
|
|
return true; // Can't handle indirect branch.
|
|
|
|
|
|
|
|
// Otherwise, block ends with fall-through condbranch.
|
2007-12-31 07:10:15 +08:00
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
2006-10-21 01:42:20 +08:00
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the instruction before it if it's a terminator.
|
|
|
|
MachineInstr *SecondLastInst = I;
|
|
|
|
|
|
|
|
// If there are three terminators, we don't know what sort of block this is.
|
2007-07-27 01:32:14 +08:00
|
|
|
if (SecondLastInst && I != MBB.begin() &&
|
|
|
|
isBrAnalysisUnpredicatedTerminator(--I, *this))
|
2006-10-21 01:42:20 +08:00
|
|
|
return true;
|
|
|
|
|
2006-10-31 06:27:23 +08:00
|
|
|
// If the block ends with X86::JMP and a conditional branch, handle it.
|
2006-10-21 01:42:20 +08:00
|
|
|
X86::CondCode BranchCode = GetCondFromBranchOpc(SecondLastInst->getOpcode());
|
|
|
|
if (BranchCode != X86::COND_INVALID && LastInst->getOpcode() == X86::JMP) {
|
2007-12-31 07:10:15 +08:00
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
2006-10-31 06:27:23 +08:00
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
2007-12-31 07:10:15 +08:00
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
2006-10-31 06:27:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
2006-10-21 01:42:20 +08:00
|
|
|
|
2007-06-14 01:59:52 +08:00
|
|
|
// If the block ends with two X86::JMPs, handle it. The second one is not
|
|
|
|
// executed, so remove it.
|
|
|
|
if (SecondLastInst->getOpcode() == X86::JMP &&
|
|
|
|
LastInst->getOpcode() == X86::JMP) {
|
2007-12-31 07:10:15 +08:00
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
2007-06-14 01:59:52 +08:00
|
|
|
I = LastInst;
|
|
|
|
I->eraseFromParent();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
// Otherwise, can't handle this.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-18 08:18:17 +08:00
|
|
|
unsigned X86InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
|
2006-10-21 01:42:20 +08:00
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
2007-05-18 08:18:17 +08:00
|
|
|
if (I == MBB.begin()) return 0;
|
2006-10-21 01:42:20 +08:00
|
|
|
--I;
|
|
|
|
if (I->getOpcode() != X86::JMP &&
|
|
|
|
GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID)
|
2007-05-18 08:18:17 +08:00
|
|
|
return 0;
|
2006-10-21 01:42:20 +08:00
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
|
|
|
|
I = MBB.end();
|
|
|
|
|
2007-05-18 08:18:17 +08:00
|
|
|
if (I == MBB.begin()) return 1;
|
2006-10-21 01:42:20 +08:00
|
|
|
--I;
|
|
|
|
if (GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID)
|
2007-05-18 08:18:17 +08:00
|
|
|
return 1;
|
2006-10-21 01:42:20 +08:00
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
2007-05-18 08:18:17 +08:00
|
|
|
return 2;
|
2006-10-21 01:42:20 +08:00
|
|
|
}
|
|
|
|
|
2008-01-02 05:11:32 +08:00
|
|
|
static const MachineInstrBuilder &X86InstrAddOperand(MachineInstrBuilder &MIB,
|
|
|
|
MachineOperand &MO) {
|
|
|
|
if (MO.isRegister())
|
|
|
|
MIB = MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit(),
|
|
|
|
false, false, MO.getSubReg());
|
|
|
|
else if (MO.isImmediate())
|
|
|
|
MIB = MIB.addImm(MO.getImm());
|
|
|
|
else if (MO.isFrameIndex())
|
|
|
|
MIB = MIB.addFrameIndex(MO.getIndex());
|
|
|
|
else if (MO.isGlobalAddress())
|
|
|
|
MIB = MIB.addGlobalAddress(MO.getGlobal(), MO.getOffset());
|
|
|
|
else if (MO.isConstantPoolIndex())
|
|
|
|
MIB = MIB.addConstantPoolIndex(MO.getIndex(), MO.getOffset());
|
|
|
|
else if (MO.isJumpTableIndex())
|
|
|
|
MIB = MIB.addJumpTableIndex(MO.getIndex());
|
|
|
|
else if (MO.isExternalSymbol())
|
|
|
|
MIB = MIB.addExternalSymbol(MO.getSymbolName());
|
|
|
|
else
|
|
|
|
assert(0 && "Unknown operand for X86InstrAddOperand!");
|
|
|
|
|
|
|
|
return MIB;
|
|
|
|
}
|
|
|
|
|
2007-05-18 08:18:17 +08:00
|
|
|
unsigned
|
|
|
|
X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const std::vector<MachineOperand> &Cond) const {
|
2006-10-21 01:42:20 +08:00
|
|
|
// Shouldn't be a fall through.
|
|
|
|
assert(TBB && "InsertBranch must not be told to insert a fallthrough");
|
2006-10-21 13:34:23 +08:00
|
|
|
assert((Cond.size() == 1 || Cond.size() == 0) &&
|
|
|
|
"X86 branch conditions have one component!");
|
|
|
|
|
|
|
|
if (FBB == 0) { // One way branch.
|
|
|
|
if (Cond.empty()) {
|
|
|
|
// Unconditional branch?
|
2006-11-28 07:37:22 +08:00
|
|
|
BuildMI(&MBB, get(X86::JMP)).addMBB(TBB);
|
2006-10-21 13:34:23 +08:00
|
|
|
} else {
|
|
|
|
// Conditional branch.
|
|
|
|
unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm());
|
2006-11-28 07:37:22 +08:00
|
|
|
BuildMI(&MBB, get(Opc)).addMBB(TBB);
|
2006-10-21 13:34:23 +08:00
|
|
|
}
|
2007-05-18 08:18:17 +08:00
|
|
|
return 1;
|
2006-10-21 01:42:20 +08:00
|
|
|
}
|
|
|
|
|
2006-10-21 13:42:09 +08:00
|
|
|
// Two-way Conditional branch.
|
2006-10-21 01:42:20 +08:00
|
|
|
unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm());
|
2006-11-28 07:37:22 +08:00
|
|
|
BuildMI(&MBB, get(Opc)).addMBB(TBB);
|
|
|
|
BuildMI(&MBB, get(X86::JMP)).addMBB(FBB);
|
2007-05-18 08:18:17 +08:00
|
|
|
return 2;
|
2006-10-21 01:42:20 +08:00
|
|
|
}
|
|
|
|
|
2007-12-31 14:32:00 +08:00
|
|
|
void X86InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
|
|
|
if (DestRC != SrcRC) {
|
|
|
|
// Moving EFLAGS to / from another register requires a push and a pop.
|
|
|
|
if (SrcRC == &X86::CCRRegClass) {
|
|
|
|
assert(SrcReg == X86::EFLAGS);
|
|
|
|
if (DestRC == &X86::GR64RegClass) {
|
|
|
|
BuildMI(MBB, MI, get(X86::PUSHFQ));
|
|
|
|
BuildMI(MBB, MI, get(X86::POP64r), DestReg);
|
|
|
|
return;
|
|
|
|
} else if (DestRC == &X86::GR32RegClass) {
|
|
|
|
BuildMI(MBB, MI, get(X86::PUSHFD));
|
|
|
|
BuildMI(MBB, MI, get(X86::POP32r), DestReg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (DestRC == &X86::CCRRegClass) {
|
|
|
|
assert(DestReg == X86::EFLAGS);
|
|
|
|
if (SrcRC == &X86::GR64RegClass) {
|
|
|
|
BuildMI(MBB, MI, get(X86::PUSH64r)).addReg(SrcReg);
|
|
|
|
BuildMI(MBB, MI, get(X86::POPFQ));
|
|
|
|
return;
|
|
|
|
} else if (SrcRC == &X86::GR32RegClass) {
|
|
|
|
BuildMI(MBB, MI, get(X86::PUSH32r)).addReg(SrcReg);
|
|
|
|
BuildMI(MBB, MI, get(X86::POPFD));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cerr << "Not yet supported!";
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Opc;
|
|
|
|
if (DestRC == &X86::GR64RegClass) {
|
|
|
|
Opc = X86::MOV64rr;
|
|
|
|
} else if (DestRC == &X86::GR32RegClass) {
|
|
|
|
Opc = X86::MOV32rr;
|
|
|
|
} else if (DestRC == &X86::GR16RegClass) {
|
|
|
|
Opc = X86::MOV16rr;
|
|
|
|
} else if (DestRC == &X86::GR8RegClass) {
|
|
|
|
Opc = X86::MOV8rr;
|
|
|
|
} else if (DestRC == &X86::GR32_RegClass) {
|
|
|
|
Opc = X86::MOV32_rr;
|
|
|
|
} else if (DestRC == &X86::GR16_RegClass) {
|
|
|
|
Opc = X86::MOV16_rr;
|
|
|
|
} else if (DestRC == &X86::RFP32RegClass) {
|
|
|
|
Opc = X86::MOV_Fp3232;
|
|
|
|
} else if (DestRC == &X86::RFP64RegClass || DestRC == &X86::RSTRegClass) {
|
|
|
|
Opc = X86::MOV_Fp6464;
|
|
|
|
} else if (DestRC == &X86::RFP80RegClass) {
|
|
|
|
Opc = X86::MOV_Fp8080;
|
|
|
|
} else if (DestRC == &X86::FR32RegClass) {
|
|
|
|
Opc = X86::FsMOVAPSrr;
|
|
|
|
} else if (DestRC == &X86::FR64RegClass) {
|
|
|
|
Opc = X86::FsMOVAPDrr;
|
|
|
|
} else if (DestRC == &X86::VR128RegClass) {
|
|
|
|
Opc = X86::MOVAPSrr;
|
|
|
|
} else if (DestRC == &X86::VR64RegClass) {
|
|
|
|
Opc = X86::MMX_MOVQ64rr;
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown regclass");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
BuildMI(MBB, MI, get(Opc), DestReg).addReg(SrcReg);
|
|
|
|
}
|
|
|
|
|
2008-01-02 05:11:32 +08:00
|
|
|
static unsigned getStoreRegOpcode(const TargetRegisterClass *RC,
|
|
|
|
unsigned StackAlign) {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == &X86::GR64RegClass) {
|
|
|
|
Opc = X86::MOV64mr;
|
|
|
|
} else if (RC == &X86::GR32RegClass) {
|
|
|
|
Opc = X86::MOV32mr;
|
|
|
|
} else if (RC == &X86::GR16RegClass) {
|
|
|
|
Opc = X86::MOV16mr;
|
|
|
|
} else if (RC == &X86::GR8RegClass) {
|
|
|
|
Opc = X86::MOV8mr;
|
|
|
|
} else if (RC == &X86::GR32_RegClass) {
|
|
|
|
Opc = X86::MOV32_mr;
|
|
|
|
} else if (RC == &X86::GR16_RegClass) {
|
|
|
|
Opc = X86::MOV16_mr;
|
|
|
|
} else if (RC == &X86::RFP80RegClass) {
|
|
|
|
Opc = X86::ST_FpP80m; // pops
|
|
|
|
} else if (RC == &X86::RFP64RegClass) {
|
|
|
|
Opc = X86::ST_Fp64m;
|
|
|
|
} else if (RC == &X86::RFP32RegClass) {
|
|
|
|
Opc = X86::ST_Fp32m;
|
|
|
|
} else if (RC == &X86::FR32RegClass) {
|
|
|
|
Opc = X86::MOVSSmr;
|
|
|
|
} else if (RC == &X86::FR64RegClass) {
|
|
|
|
Opc = X86::MOVSDmr;
|
|
|
|
} else if (RC == &X86::VR128RegClass) {
|
|
|
|
// FIXME: Use movaps once we are capable of selectively
|
|
|
|
// aligning functions that spill SSE registers on 16-byte boundaries.
|
|
|
|
Opc = StackAlign >= 16 ? X86::MOVAPSmr : X86::MOVUPSmr;
|
|
|
|
} else if (RC == &X86::VR64RegClass) {
|
|
|
|
Opc = X86::MMX_MOVQ64mr;
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown regclass");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Opc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
unsigned Opc = getStoreRegOpcode(RC, RI.getStackAlignment());
|
|
|
|
addFrameReference(BuildMI(MBB, MI, get(Opc)), FrameIdx)
|
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
|
|
|
bool isKill,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = getStoreRegOpcode(RC, RI.getStackAlignment());
|
|
|
|
MachineInstrBuilder MIB = BuildMI(get(Opc));
|
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB = X86InstrAddOperand(MIB, Addr[i]);
|
|
|
|
MIB.addReg(SrcReg, false, false, isKill);
|
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getLoadRegOpcode(const TargetRegisterClass *RC,
|
|
|
|
unsigned StackAlign) {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == &X86::GR64RegClass) {
|
|
|
|
Opc = X86::MOV64rm;
|
|
|
|
} else if (RC == &X86::GR32RegClass) {
|
|
|
|
Opc = X86::MOV32rm;
|
|
|
|
} else if (RC == &X86::GR16RegClass) {
|
|
|
|
Opc = X86::MOV16rm;
|
|
|
|
} else if (RC == &X86::GR8RegClass) {
|
|
|
|
Opc = X86::MOV8rm;
|
|
|
|
} else if (RC == &X86::GR32_RegClass) {
|
|
|
|
Opc = X86::MOV32_rm;
|
|
|
|
} else if (RC == &X86::GR16_RegClass) {
|
|
|
|
Opc = X86::MOV16_rm;
|
|
|
|
} else if (RC == &X86::RFP80RegClass) {
|
|
|
|
Opc = X86::LD_Fp80m;
|
|
|
|
} else if (RC == &X86::RFP64RegClass) {
|
|
|
|
Opc = X86::LD_Fp64m;
|
|
|
|
} else if (RC == &X86::RFP32RegClass) {
|
|
|
|
Opc = X86::LD_Fp32m;
|
|
|
|
} else if (RC == &X86::FR32RegClass) {
|
|
|
|
Opc = X86::MOVSSrm;
|
|
|
|
} else if (RC == &X86::FR64RegClass) {
|
|
|
|
Opc = X86::MOVSDrm;
|
|
|
|
} else if (RC == &X86::VR128RegClass) {
|
|
|
|
// FIXME: Use movaps once we are capable of selectively
|
|
|
|
// aligning functions that spill SSE registers on 16-byte boundaries.
|
|
|
|
Opc = StackAlign >= 16 ? X86::MOVAPSrm : X86::MOVUPSrm;
|
|
|
|
} else if (RC == &X86::VR64RegClass) {
|
|
|
|
Opc = X86::MMX_MOVQ64rm;
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown regclass");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Opc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const{
|
|
|
|
unsigned Opc = getLoadRegOpcode(RC, RI.getStackAlignment());
|
|
|
|
addFrameReference(BuildMI(MBB, MI, get(Opc), DestReg), FrameIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = getLoadRegOpcode(RC, RI.getStackAlignment());
|
|
|
|
MachineInstrBuilder MIB = BuildMI(get(Opc), DestReg);
|
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB = X86InstrAddOperand(MIB, Addr[i]);
|
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
}
|
|
|
|
|
2006-10-29 01:29:57 +08:00
|
|
|
bool X86InstrInfo::BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
|
|
|
|
if (MBB.empty()) return false;
|
|
|
|
|
|
|
|
switch (MBB.back().getOpcode()) {
|
2007-10-12 03:40:01 +08:00
|
|
|
case X86::TCRETURNri:
|
|
|
|
case X86::TCRETURNdi:
|
2007-05-22 02:44:17 +08:00
|
|
|
case X86::RET: // Return.
|
|
|
|
case X86::RETI:
|
|
|
|
case X86::TAILJMPd:
|
|
|
|
case X86::TAILJMPr:
|
|
|
|
case X86::TAILJMPm:
|
2006-10-29 01:29:57 +08:00
|
|
|
case X86::JMP: // Uncond branch.
|
|
|
|
case X86::JMP32r: // Indirect branch.
|
2007-09-17 23:19:08 +08:00
|
|
|
case X86::JMP64r: // Indirect branch (64-bit).
|
2006-10-29 01:29:57 +08:00
|
|
|
case X86::JMP32m: // Indirect branch through mem.
|
2007-09-17 23:19:08 +08:00
|
|
|
case X86::JMP64m: // Indirect branch through mem (64-bit).
|
2006-10-29 01:29:57 +08:00
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
bool X86InstrInfo::
|
|
|
|
ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
|
2006-10-21 13:52:40 +08:00
|
|
|
assert(Cond.size() == 1 && "Invalid X86 branch condition!");
|
|
|
|
Cond[0].setImm(GetOppositeBranchCondition((X86::CondCode)Cond[0].getImm()));
|
|
|
|
return false;
|
2006-10-21 01:42:20 +08:00
|
|
|
}
|
|
|
|
|
2006-09-08 14:48:29 +08:00
|
|
|
const TargetRegisterClass *X86InstrInfo::getPointerRegClass() const {
|
|
|
|
const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
|
|
|
|
if (Subtarget->is64Bit())
|
|
|
|
return &X86::GR64RegClass;
|
|
|
|
else
|
|
|
|
return &X86::GR32RegClass;
|
|
|
|
}
|