aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/M68k/M68kInstrInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/M68k/M68kInstrInfo.cpp')
-rw-r--r--llvm/lib/Target/M68k/M68kInstrInfo.cpp62
1 files changed, 55 insertions, 7 deletions
diff --git a/llvm/lib/Target/M68k/M68kInstrInfo.cpp b/llvm/lib/Target/M68k/M68kInstrInfo.cpp
index 23c5c76..2d9285f 100644
--- a/llvm/lib/Target/M68k/M68kInstrInfo.cpp
+++ b/llvm/lib/Target/M68k/M68kInstrInfo.cpp
@@ -346,8 +346,8 @@ void M68kInstrInfo::AddZExt(MachineBasicBlock &MBB,
BuildMI(MBB, I, DL, get(And), Reg).addReg(Reg).addImm(Mask);
}
-// Convert MOVI to MOVQ if the target is a data register and the immediate
-// fits in a sign-extended i8, otherwise emit a plain MOV.
+// Convert MOVI to the appropriate instruction (sequence) for setting
+// the register to an immediate value.
bool M68kInstrInfo::ExpandMOVI(MachineInstrBuilder &MIB, MVT MVTSize) const {
Register Reg = MIB->getOperand(0).getReg();
int64_t Imm = MIB->getOperand(1).getImm();
@@ -360,18 +360,66 @@ bool M68kInstrInfo::ExpandMOVI(MachineInstrBuilder &MIB, MVT MVTSize) const {
if (AR16->contains(Reg) || AR32->contains(Reg))
IsAddressReg = true;
+ // We need to assign to the full register to make IV happy
+ Register SReg =
+ MVTSize == MVT::i32
+ ? Reg
+ : Register(RI.getMatchingMegaReg(Reg, IsAddressReg ? AR32 : DR32));
+ assert(SReg && "No viable MEGA register available");
+
LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
+ // Sign extention doesn't matter if we only use the bottom 8 bits
if (MVTSize == MVT::i8 || (!IsAddressReg && Imm >= -128 && Imm <= 127)) {
LLVM_DEBUG(dbgs() << "MOVEQ\n");
- // We need to assign to the full register to make IV happy
- Register SReg =
- MVTSize == MVT::i32 ? Reg : Register(RI.getMatchingMegaReg(Reg, DR32));
- assert(SReg && "No viable MEGA register available");
-
MIB->setDesc(get(M68k::MOVQ));
MIB->getOperand(0).setReg(SReg);
+
+ // Counter the effects of sign-extension with a bitwise not.
+ // This is only faster and smaller for 32 bit values.
+ } else if (DR32->contains(Reg) && isUInt<8>(Imm)) {
+ LLVM_DEBUG(dbgs() << "MOVEQ and NOT\n");
+
+ MachineBasicBlock &MBB = *MIB->getParent();
+ DebugLoc DL = MIB->getDebugLoc();
+
+ unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex8Lo);
+ assert(SubReg && "No viable SUB register available");
+
+ BuildMI(MBB, MIB.getInstr(), DL, get(M68k::MOVQ), SReg).addImm(~Imm & 0xFF);
+ BuildMI(MBB, MIB.getInstr(), DL, get(M68k::NOT8d), SubReg).addReg(SubReg);
+
+ MIB->removeFromParent();
+
+ // Special case for setting address register to NULL (0)
+ } else if (IsAddressReg && Imm == 0) {
+ LLVM_DEBUG(dbgs() << "SUBA\n");
+
+ MachineBasicBlock &MBB = *MIB->getParent();
+ DebugLoc DL = MIB->getDebugLoc();
+
+ BuildMI(MBB, MIB.getInstr(), DL, get(M68k::SUB32ar), SReg)
+ .addReg(SReg, RegState::Undef)
+ .addReg(SReg, RegState::Undef);
+
+ MIB->removeFromParent();
+
+ // movea.w implicitly sign extends to the full register width,
+ // so exploit that if the immediate fits in the correct range.
+ //
+ // TODO: use lea imm.w, %an for further constants when 16-bit
+ // absolute addressing is implemented.
+ } else if (AR32->contains(Reg) && isUInt<16>(Imm)) {
+ LLVM_DEBUG(dbgs() << "MOVEA w/ implicit extend\n");
+
+ unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex16Lo);
+ assert(SubReg && "No viable SUB register available");
+
+ MIB->setDesc(get(M68k::MOV16ai));
+ MIB->getOperand(0).setReg(SubReg);
+
+ // Fall back to a move with immediate
} else {
LLVM_DEBUG(dbgs() << "MOVE\n");
MIB->setDesc(get(MVTSize == MVT::i16 ? M68k::MOV16ri : M68k::MOV32ri));