Don't reserve R2 on Darwin/PPC
authorHal Finkel <hfinkel@anl.gov>
Tue, 12 Mar 2013 15:18:14 +0000 (15:18 +0000)
committerHal Finkel <hfinkel@anl.gov>
Tue, 12 Mar 2013 15:18:14 +0000 (15:18 +0000)
Now that only the register-scavenger version of the CR spilling code remains,
we no longer need the Darwin R2 hack. Darwin can use R0 as a spare register in
any case where the System V ABI uses it (R0 is special architecturally, and so
is reserved under all common ABIs).

A few test cases needed to be updated to reflect the register-allocation changes.

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

lib/Target/PowerPC/PPCRegisterInfo.cpp
test/CodeGen/PowerPC/2009-08-17-inline-asm-addr-mode-breakage.ll
test/CodeGen/PowerPC/2010-02-12-saveCR.ll
test/CodeGen/PowerPC/2010-05-03-retaddr1.ll
test/CodeGen/PowerPC/2010-12-18-PPCStackRefs.ll
test/CodeGen/PowerPC/LargeAbsoluteAddr.ll
test/CodeGen/PowerPC/varargs.ll

index fd79de1387f0b1dc51ab5d69a9ffd147dfd53e3c..3e5ee752a9cdcc87f2a09177db549829dc71ef3c 100644 (file)
@@ -121,12 +121,6 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
     Reserved.set(PPC::R2);  // System-reserved register
     Reserved.set(PPC::R13); // Small Data Area pointer register
   }
-  // Reserve R2 on Darwin to hack around the problem of save/restore of CR
-  // when the stack frame is too big to address directly; we need two regs.
-  // This is a hack.
-  if (Subtarget.isDarwinABI()) {
-    Reserved.set(PPC::R2);
-  }
   
   // On PPC64, r13 is the thread pointer. Never allocate this register.
   // Note that this is over conservative, as it also prevents allocation of R31
@@ -144,12 +138,6 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
     if (Subtarget.isSVR4ABI()) {
       Reserved.set(PPC::X2);
     }
-    // Reserve X2 on Darwin to hack around the problem of save/restore of CR
-    // when the stack frame is too big to address directly; we need two regs.
-    // This is a hack.
-    if (Subtarget.isDarwinABI()) {
-      Reserved.set(PPC::X2);
-    }
   }
 
   if (PPCFI->needsFP(MF))
@@ -334,8 +322,7 @@ void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II,
   (void) RS;
 
   bool LP64 = Subtarget.isPPC64();
-  unsigned Reg = Subtarget.isDarwinABI() ?  (LP64 ? PPC::X2 : PPC::R2) :
-                                            (LP64 ? PPC::X0 : PPC::R0);
+  unsigned Reg = LP64 ? PPC::X0 : PPC::R0;
   unsigned SrcReg = MI.getOperand(0).getReg();
 
   // We need to store the CR in the low 4-bits of the saved value. First, issue
@@ -377,8 +364,7 @@ void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II,
   (void) RS;
 
   bool LP64 = Subtarget.isPPC64();
-  unsigned Reg = Subtarget.isDarwinABI() ?  (LP64 ? PPC::X2 : PPC::R2) :
-                                            (LP64 ? PPC::X0 : PPC::R0);
+  unsigned Reg = LP64 ? PPC::X0 : PPC::R0;
   unsigned DestReg = MI.getOperand(0).getReg();
   assert(MI.definesRegister(DestReg) &&
     "RESTORE_CR does not define its destination");
index 84aa40c4b52ac99c81ecd41e91661a11af982d31..91253daae396d83290b83d59d3c4cf40ffdf065d 100644 (file)
@@ -10,8 +10,8 @@ target triple = "powerpc-apple-darwin10.0"
 define void @foo(i32 %y) nounwind ssp {
 entry:
 ; CHECK: foo
-; CHECK: add r3
-; CHECK: 0(r3)
+; CHECK: add r2
+; CHECK: 0(r2)
   %y_addr = alloca i32                            ; <i32*> [#uses=2]
   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
   store i32 %y, i32* %y_addr
index 974a99a52cb5117d0a6ff809e24a0fc31ad2a502..433fe5cc2aaaaa0cc4baee741b4d7634bc04ef50 100644 (file)
@@ -6,17 +6,17 @@ target triple = "powerpc-apple-darwin9.6"
 
 define void @foo() nounwind {
 entry:
-;CHECK:  mfcr r2
-;CHECK:  lis r3, 1
-;CHECK:  rlwinm r2, r2, 8, 0, 31
-;CHECK:  ori r3, r3, 34524
-;CHECK:  stwx r2, r1, r3
+;CHECK:  mfcr r0
+;CHECK:  lis r2, 1
+;CHECK:  rlwinm r0, r0, 8, 0, 31
+;CHECK:  ori r2, r2, 34524
+;CHECK:  stwx r0, r1, r2
 ; Make sure that the register scavenger returns the same temporary register.
-;CHECK:  mfcr r2
-;CHECK:  lis r3, 1
-;CHECK:  rlwinm r2, r2, 12, 0, 31
-;CHECK:  ori r3, r3, 34520
-;CHECK:  stwx r2, r1, r3
+;CHECK:  lis r2, 1
+;CHECK:  mfcr r0
+;CHECK:  ori r2, r2, 34520
+;CHECK:  rlwinm r0, r0, 12, 0, 31
+;CHECK:  stwx r0, r1, r2
   %x = alloca [100000 x i8]                       ; <[100000 x i8]*> [#uses=1]
   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
   %x1 = bitcast [100000 x i8]* %x to i8*          ; <i8*> [#uses=1]
@@ -25,11 +25,11 @@ entry:
   br label %return
 
 return:                                           ; preds = %entry
-;CHECK:  lis r3, 1
-;CHECK:  ori r3, r3, 34524
-;CHECK:  lwzx r2, r1, r3
-;CHECK:  rlwinm r2, r2, 24, 0, 31
-;CHECK:  mtcrf 32, r2
+;CHECK:  lis r2, 1
+;CHECK:  ori r2, r2, 34524
+;CHECK:  lwzx r0, r1, r2
+;CHECK:  rlwinm r0, r0, 24, 0, 31
+;CHECK:  mtcrf 32, r0
   ret void
 }
 
index 72ae9d6c73b38f06a3c6c799bdbcc4e7d4047fd0..0dbc2d0180ff5917e10edfb001dcffdb5371793c 100644 (file)
@@ -18,8 +18,8 @@ entry:
 ; CHECK: _g:
 ; CHECK:  mflr r0
 ; CHECK:  stw r0, 8(r1)
-; CHECK:  lwz r3, 0(r1)
-; CHECK:  lwz r3, 8(r3)
+; CHECK:  lwz r2, 0(r1)
+; CHECK:  lwz r3, 8(r2)
   %0 = tail call i8* @llvm.returnaddress(i32 1)   ; <i8*> [#uses=1]
   ret i8* %0
 }
index bf3d577a3677107da7071c76fe8891170c948dad..d1a3c9f46b573192f25eb0e7c38cbb90d4810f97 100644 (file)
@@ -7,7 +7,7 @@ define i32 @main() nounwind {
 entry:
 ; Make sure we're generating references using the red zone
 ; CHECK: main:
-; CHECK: stw r3, -12(r1)
+; CHECK: stw r2, -12(r1)
   %retval = alloca i32
   %0 = alloca i32
   %"alloca point" = bitcast i32 0 to i32
index 6f985c819fb676d1cb60cefe76097ec12f034569..e8765deab05db4a7ebcadb3f3864da8090fac16f 100644 (file)
@@ -1,9 +1,9 @@
 ; RUN: llc < %s -march=ppc32 -mtriple=powerpc-apple-darwin | \
-; RUN:   grep "stw r4, 32751"
+; RUN:   grep "stw r3, 32751"
 ; RUN: llc < %s -march=ppc64 -mtriple=powerpc-apple-darwin | \
-; RUN:   grep "stw r4, 32751"
+; RUN:   grep "stw r3, 32751"
 ; RUN: llc < %s -march=ppc64 -mtriple=powerpc-apple-darwin | \
-; RUN:   grep "std r4, 9024"
+; RUN:   grep "std r3, 9024"
 
 define void @test() nounwind {
        store i32 0, i32* inttoptr (i64 48725999 to i32*)
index 1769be957ac42a16f20c8acbddea28c5762ca29b..90f0480d6ad210df74b59438c7c95f1a1fc89d70 100644 (file)
@@ -8,15 +8,16 @@ define i8* @test1(i8** %foo) nounwind {
 }
 
 ; P32: test1:
-; P32:         lwz r4, 0(r3)
-; P32: addi r5, r4, 4
-; P32: stw r5, 0(r3)
-; P32: lwz r3, 0(r4)
-; P32: blr 
+; P32: lwz r2, 0(r3)
+; P32: addi r4, r2, 4
+; P32: stw r4, 0(r3)
+; P32: lwz r3, 0(r2)
+; P32: blr 
 
 ; P64: test1:
-; P64: ld r4, 0(r3)
-; P64: addi r5, r4, 8
-; P64: std r5, 0(r3)
-; P64: ld r3, 0(r4)
-; P64: blr
+; P64: ld r2, 0(r3)
+; P64: addi r4, r2, 8
+; P64: std r4, 0(r3)
+; P64: ld r3, 0(r2)
+; P64: blr 
+