diff options
author | Evan Cheng <evan.cheng@apple.com> | 2009-08-11 23:00:31 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2009-08-11 23:00:31 +0000 |
commit | b89030ab6554d84de4331c2853edac4dbf8da9b9 (patch) | |
tree | b951b78ad1861c856b34592f6d85f1fb6366e227 /lib/Target/ARM/Thumb2SizeReduction.cpp | |
parent | 09652df5fc19b088d8baf43dd7839d9c2fc24980 (diff) |
Shrinkify Thumb2 r = add sp, imm.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78745 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/ARM/Thumb2SizeReduction.cpp')
-rw-r--r-- | lib/Target/ARM/Thumb2SizeReduction.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Target/ARM/Thumb2SizeReduction.cpp b/lib/Target/ARM/Thumb2SizeReduction.cpp index da3701d390..8f6fb3ac84 100644 --- a/lib/Target/ARM/Thumb2SizeReduction.cpp +++ b/lib/Target/ARM/Thumb2SizeReduction.cpp @@ -57,6 +57,8 @@ namespace { // FIXME: t2ADDS variants. { ARM::t2ADDri, ARM::tADDi3, ARM::tADDi8, 3, 8, 1, 1, 0,0, 0 }, { ARM::t2ADDrr, ARM::tADDrr, ARM::tADDhirr, 0, 0, 1, 0, 0,1, 0 }, + // Note: immediate scale is 4. + { ARM::t2ADDrSPi,ARM::tADDrSPi,0, 8, 0, 1, 0, 1,0, 0 }, { ARM::t2ANDrr, 0, ARM::tAND, 0, 0, 0, 1, 0,0, 0 }, { ARM::t2ASRri, ARM::tASRri, 0, 5, 0, 1, 0, 0,0, 0 }, { ARM::t2ASRrr, 0, ARM::tASRrr, 0, 0, 0, 1, 0,0, 0 }, @@ -199,7 +201,7 @@ static bool VerifyLowRegs(MachineInstr *MI) { unsigned Opc = MI->getOpcode(); bool isPCOk = (Opc == ARM::t2LDM_RET) || (Opc == ARM::t2LDM); bool isLROk = (Opc == ARM::t2STM); - bool isSPOk = isPCOk || isLROk; + bool isSPOk = isPCOk || isLROk || (Opc == ARM::t2ADDrSPi); for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { const MachineOperand &MO = MI->getOperand(i); if (!MO.isReg() || MO.isImplicit()) @@ -423,8 +425,9 @@ Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI, return false; unsigned Limit = ~0U; + unsigned Scale = (Entry.WideOpc == ARM::t2ADDrSPi) ? 4 : 1; if (Entry.Imm1Limit) - Limit = (1 << Entry.Imm1Limit) - 1; + Limit = ((1 << Entry.Imm1Limit) - 1) * Scale; const TargetInstrDesc &TID = MI->getDesc(); for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) { @@ -435,10 +438,13 @@ Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI, unsigned Reg = MO.getReg(); if (!Reg || Reg == ARM::CPSR) continue; + if (Entry.WideOpc == ARM::t2ADDrSPi && Reg == ARM::SP) + continue; if (Entry.LowRegs1 && !isARMLowRegister(Reg)) return false; - } else if (MO.isImm()) { - if (MO.getImm() > Limit) + } else if (MO.isImm() && + !TID.OpInfo[i].isPredicate()) { + if (MO.getImm() > Limit || (MO.getImm() & (Scale-1)) != 0) return false; } } @@ -479,9 +485,14 @@ Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI, for (unsigned i = 1, e = MI->getNumOperands(); i != e; ++i) { if (i < NumOps && TID.OpInfo[i].isOptionalDef()) continue; - if (SkipPred && TID.OpInfo[i].isPredicate()) - continue; - MIB.addOperand(MI->getOperand(i)); + bool isPred = (i < NumOps && TID.OpInfo[i].isPredicate()); + if (SkipPred && isPred) + continue; + const MachineOperand &MO = MI->getOperand(i); + if (Scale > 1 && !isPred && MO.isImm()) + MIB.addImm(MO.getImm() / Scale); + else + MIB.addOperand(MO); } |