Index: lib/Target/PowerPC/PPCFrameLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCFrameLowering.cpp +++ lib/Target/PowerPC/PPCFrameLowering.cpp @@ -1765,31 +1765,36 @@ // Check whether the frame pointer register is allocated. If so, make sure it // is spilled to the correct offset. if (needsFP(MF)) { - HasGPSaveArea = true; - int FI = PFI->getFramePointerSaveIndex(); assert(FI && "No Frame Pointer Save Slot!"); - MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI)); + // FP is R31/X31, so no need to update MinGPR/MinG8R. + HasGPSaveArea = true; } if (PFI->usesPICBase()) { - HasGPSaveArea = true; - int FI = PFI->getPICBasePointerSaveIndex(); assert(FI && "No PIC Base Pointer Save Slot!"); - MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI)); + + MinGPR = std::min(MinGPR, PPC::R30); + HasGPSaveArea = true; } const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo(); if (RegInfo->hasBasePointer(MF)) { - HasGPSaveArea = true; - int FI = PFI->getBasePointerSaveIndex(); assert(FI && "No Base Pointer Save Slot!"); - MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI)); + + unsigned BP = RegInfo->getBaseRegister(MF); + if (PPC::G8RCRegClass.contains(BP)) { + MinG8R = std::min(MinG8R, BP); + HasG8SaveArea = true; + } else if (PPC::GPRCRegClass.contains(BP)) { + MinGPR = std::min(MinGPR, BP); + HasGPSaveArea = true; + } } // General register save area starts right below the Floating-point Index: test/CodeGen/PowerPC/save-cr-ppc32svr4.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/save-cr-ppc32svr4.ll @@ -0,0 +1,46 @@ +; RUN: llc -march=ppc32 -relocation-model pic < %s | FileCheck %s +; +; Make sure that the CR register is saved correctly on PPC32/SVR4. + +; CHECK-LABEL: Perl_cast_iv: +; CHECK: stwu 1, -32(1) +; CHECK: stw 31, 28(1) +; CHECK: mr 31, 1 +; CHECK: stw 30, 24(1) +; CHECK: mfcr [[CR:[0-9]+]] +; CHECK: stw [[CR]], 20(31) + +target datalayout = "E-m:e-p:32:32-i64:64-n32" +target triple = "powerpc-unknown-freebsd" + +; Function Attrs: norecurse nounwind readnone sspstrong +define i64 @Perl_cast_iv(double %f) local_unnamed_addr #0 { +entry: + %cmp = fcmp olt double %f, 0x43E0000000000000 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %cmp1 = fcmp olt double %f, 0xC3E0000000000000 + %conv = fptosi double %f to i64 + %cond = select i1 %cmp1, i64 -9223372036854775808, i64 %conv + br label %return + +if.end: ; preds = %entry + %cmp2 = fcmp olt double %f, 0x43F0000000000000 + br i1 %cmp2, label %if.then4, label %if.end6 + +if.then4: ; preds = %if.end + %conv5 = fptoui double %f to i64 + br label %return + +if.end6: ; preds = %if.end + %cmp7 = fcmp ogt double %f, 0.000000e+00 + %cond9 = sext i1 %cmp7 to i64 + br label %return + +return: ; preds = %if.end6, %if.then4, %if.then + %retval.0 = phi i64 [ %cond, %if.then ], [ %conv5, %if.then4 ], [ %cond9, %if.end6 ] + ret i64 %retval.0 +} + +attributes #0 = { norecurse nounwind readnone sspstrong "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "stack-protector-buffer-size"="8" "target-cpu"="ppc" }