Index: lib/Target/AMDGPU/SIFrameLowering.cpp =================================================================== --- lib/Target/AMDGPU/SIFrameLowering.cpp +++ lib/Target/AMDGPU/SIFrameLowering.cpp @@ -721,10 +721,13 @@ } } -static bool allStackObjectsAreDead(const MachineFrameInfo &MFI) { +// Note SGPRSpill stack IDs should only be used for SGPR spilling to VGPRs, not +// memory. +static bool allStackObjectsAreDeadOrSGPR(const MachineFrameInfo &MFI) { for (int I = MFI.getObjectIndexBegin(), E = MFI.getObjectIndexEnd(); I != E; ++I) { - if (!MFI.isDeadObjectIndex(I)) + if (!MFI.isDeadObjectIndex(I) && + MFI.getStackID(I) != TargetStackID::SGPRSpill) return false; } @@ -786,11 +789,7 @@ FuncInfo->removeSGPRToVGPRFrameIndices(MFI); - // FIXME: The other checks should be redundant with allStackObjectsAreDead, - // but currently hasNonSpillStackObjects is set only from source - // allocas. Stack temps produced from legalization are not counted currently. - if (FuncInfo->hasNonSpillStackObjects() || FuncInfo->hasSpilledVGPRs() || - !AllSGPRSpilledToVGPRs || !allStackObjectsAreDead(MFI)) { + if (!allStackObjectsAreDeadOrSGPR(MFI)) { assert(RS && "RegScavenger required if spilling"); if (FuncInfo->isEntryFunction()) {