From eebaeff994a1a66e4ea4377f7a74b507521b62a4 Mon Sep 17 00:00:00 2001 From: cdevadas Date: Mon, 24 Jun 2019 16:54:32 +0530 Subject: [PATCH] Fixing the liveset computation in the epilogue code. --- lib/Target/AMDGPU/SIFrameLowering.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Target/AMDGPU/SIFrameLowering.cpp b/lib/Target/AMDGPU/SIFrameLowering.cpp index 11d41775421ac..7a10de4686bf2 100644 --- a/lib/Target/AMDGPU/SIFrameLowering.cpp +++ b/lib/Target/AMDGPU/SIFrameLowering.cpp @@ -681,7 +681,18 @@ void SIFrameLowering::emitEpilogue(MachineFunction &MF, if (ScratchExecCopy == AMDGPU::NoRegister) { // See emitPrologue LivePhysRegs LiveRegs(*ST.getRegisterInfo()); - LiveRegs.addLiveIns(MBB); + LiveRegs.addLiveOuts(MBB); + + // Step-backwards until the insertion point + // to get the live registers. + for (MachineInstr &MI : llvm::reverse(MBB)){ + for (const MachineOperand &MO : MI.operands()) { + if (MO.isReg()) + LiveRegs.addReg(MO.getReg()); + } + if (MI == MBBI) + break; + } ScratchExecCopy = findScratchNonCalleeSaveRegister(MF, LiveRegs,