When getting the number of bits necessary for addressing mode
authorBill Wendling <isanbard@gmail.com>
Mon, 10 Oct 2011 07:24:23 +0000 (07:24 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 10 Oct 2011 07:24:23 +0000 (07:24 +0000)
ARMII::AddrModeT1_s, we need to take into account that if the frame register is
ARM::SP, then the number of bits is 8. If it's not ARM::SP, then the number of
bits is 5.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141529 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMBaseRegisterInfo.cpp
test/CodeGen/Thumb/vargs.ll

index 7c42342229a266bbd40086a59d88d594157ea3d3..0c8480d9ef22aa81c0c3321d069005b5f8b93bff 100644 (file)
@@ -1109,11 +1109,20 @@ bool ARMBaseRegisterInfo::isFrameOffsetLegal(const MachineInstr *MI,
   case ARMII::AddrMode3:
     NumBits = 8;
     break;
-  case ARMII::AddrModeT1_s:
-    NumBits = 5;
+  case ARMII::AddrModeT1_s: {
+    const MachineBasicBlock &MBB = *MI->getParent();
+    const MachineFunction &MF = *MBB.getParent();
+    unsigned FrameReg = ARM::SP;
+    if (MF.getFrameInfo()->hasVarSizedObjects())
+      // There are alloca()'s in this function, must reference off the frame
+      // pointer or base pointer instead.
+      FrameReg = (!hasBasePointer(MF) ?BasePtr : getFrameRegister(MF));
+
+    NumBits = (FrameReg == ARM::SP) ? 8 : 5;
     Scale = 4;
     isSigned = false;
     break;
+  }
   default:
     llvm_unreachable("Unsupported addressing mode!");
     break;
index c2ba208e4ae27581a348d4e4c7348625acf0c5a1..16a9c4442d8a88009d15346dde7f8c3c1e32443d 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -march=thumb
-; RUN: llc < %s -mtriple=thumb-linux | grep pop | count 2
+; RUN: llc < %s -mtriple=thumb-linux | grep pop | count 1
 ; RUN: llc < %s -mtriple=thumb-darwin | grep pop | count 2
 
 @str = internal constant [4 x i8] c"%d\0A\00"           ; <[4 x i8]*> [#uses=1]