From 56faeb049c0b274ed12267ef74aed60d290be60f Mon Sep 17 00:00:00 2001 From: Kit Barton Date: Mon, 30 Nov 2015 18:59:41 +0000 Subject: [PATCH] Enable shrink wrapping for PPC64 Re-enable shrink wrapping for PPC64 Little Endian. One minor modification to PPCFrameLowering::findScratchRegister was necessary to handle fall-thru blocks (blocks with no terminator) correctly. Tested with all LLVM test, clang tests, and the self-hosting build, with no problems found. PHabricator: http://reviews.llvm.org/D14778 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254314 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPCFrameLowering.cpp | 20 ++++++++++++++------ test/CodeGen/PowerPC/ppc-shrink-wrapping.ll | 1 - 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Target/PowerPC/PPCFrameLowering.cpp b/lib/Target/PowerPC/PPCFrameLowering.cpp index c7a3bbd3762..5a151eb6ab2 100644 --- a/lib/Target/PowerPC/PPCFrameLowering.cpp +++ b/lib/Target/PowerPC/PPCFrameLowering.cpp @@ -573,10 +573,18 @@ bool PPCFrameLowering::findScratchRegister(MachineBasicBlock *MBB, RS.initRegState(); RS.enterBasicBlock(MBB); - // The scratch register will be used at the end of the block, so must consider - // all registers used within the block - if (UseAtEnd && MBB->begin() != MBB->getFirstTerminator()) - RS.forward(MBB->getFirstTerminator()); + if (UseAtEnd && !MBB->empty()) { + // The scratch register will be used at the end of the block, so must consider + // all registers used within the block + + MachineBasicBlock::iterator MBBI = MBB->getFirstTerminator(); + // If no terminator, back iterator up to previous instruction. + if (MBBI == MBB->end()) + MBBI = std::prev(MBBI); + + if (MBBI != MBB->begin()) + RS.forward(MBBI); + } if (!RS.isRegUsed(R0)) return true; @@ -1768,6 +1776,6 @@ PPCFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB, } bool PPCFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const { - // FIXME: Enable this for non-Darwin PPC64 once it is confirmed working. - return false; + return (MF.getSubtarget().isSVR4ABI() && + MF.getSubtarget().isPPC64()); } diff --git a/test/CodeGen/PowerPC/ppc-shrink-wrapping.ll b/test/CodeGen/PowerPC/ppc-shrink-wrapping.ll index a23888425bf..2da8e8d0984 100644 --- a/test/CodeGen/PowerPC/ppc-shrink-wrapping.ll +++ b/test/CodeGen/PowerPC/ppc-shrink-wrapping.ll @@ -1,6 +1,5 @@ ; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE ; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu %s -o - -enable-shrink-wrap=false | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE -; XFAIL: * ; ; Note: Lots of tests use inline asm instead of regular calls. ; This allows to have a better control on what the allocation will do. -- 2.34.1