llvm.org GIT mirror llvm / db6cbe1
In Thumb2 mode, lower frame indix references to: add <rd>, sp, #<imm8> ldr <rd>, [sp, #<imm8>] When the offset from sp is multiple of 4 and in range of 0-1020. This saves code size by utilizing 16-bit instructions. rdar://9321541 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129971 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 9 years ago
3 changed file(s) with 36 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
444444
445445 int
446446 ARMFrameLowering::ResolveFrameIndexReference(const MachineFunction &MF,
447 int FI,
448 unsigned &FrameReg,
447 int FI, unsigned &FrameReg,
449448 int SPAdj) const {
450449 const MachineFrameInfo *MFI = MF.getFrameInfo();
451450 const ARMBaseRegisterInfo *RegInfo =
489488 return FPOffset;
490489 } else if (MFI->hasVarSizedObjects()) {
491490 assert(RegInfo->hasBasePointer(MF) && "missing base pointer!");
492 // Try to use the frame pointer if we can, else use the base pointer
493 // since it's available. This is handy for the emergency spill slot, in
494 // particular.
495491 if (AFI->isThumb2Function()) {
492 // Try to use the frame pointer if we can, else use the base pointer
493 // since it's available. This is handy for the emergency spill slot, in
494 // particular.
496495 if (FPOffset >= -255 && FPOffset < 0) {
497496 FrameReg = RegInfo->getFrameRegister(MF);
498497 return FPOffset;
499498 }
500 } else
501 FrameReg = RegInfo->getBaseRegister();
499 }
502500 } else if (AFI->isThumb2Function()) {
501 // Use add , sp, #
502 // ldr , [sp, #]
503 // if at all possible to save space.
504 if (Offset >= 0 && (Offset & 3) == 0 && Offset <= 1020)
505 return Offset;
503506 // In Thumb2 mode, the negative offset is very limited. Try to avoid
504 // out of range references.
507 // out of range references. ldr ,[, #-]
505508 if (FPOffset >= -255 && FPOffset < 0) {
506509 FrameReg = RegInfo->getFrameRegister(MF);
507510 return FPOffset;
5050 bool canSimplifyCallFramePseudos(const MachineFunction &MF) const;
5151 int getFrameIndexReference(const MachineFunction &MF, int FI,
5252 unsigned &FrameReg) const;
53 int ResolveFrameIndexReference(const MachineFunction &MF, int FI,
53 int ResolveFrameIndexReference(const MachineFunction &MF,
54 int FI,
5455 unsigned &FrameReg, int SPAdj) const;
5556 int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
5657
0 ; RUN: llc < %s -mtriple=thumbv7-apple-darwin | FileCheck %s
1
2 ; Use sp, #imm to lower frame indices when the offset is multiple of 4
3 ; and in the range of 0-1020. This saves code size by utilizing
4 ; 16-bit instructions.
5 ; rdar://9321541
6
7 define i32 @t() nounwind {
8 entry:
9 ; CHECK: t:
10 ; CHECK: sub sp, #12
11 ; CHECK-NOT: sub
12 ; CHECK: add r0, sp, #4
13 ; CHECK: add r1, sp, #8
14 ; CHECK: mov r2, sp
15 %size = alloca i32, align 4
16 %count = alloca i32, align 4
17 %index = alloca i32, align 4
18 %0 = call i32 @foo(i32* %count, i32* %size, i32* %index) nounwind
19 ret i32 %0
20 }
21
22 declare i32 @foo(i32*, i32*, i32*)