diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp index d3b2cb1936b53e..0cd1d47a9bcc74 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp @@ -715,10 +715,6 @@ bool AMDGPUCallLowering::lowerFormalArguments( if (!IsEntryFunc && !IsGraphics) { // For the fixed ABI, pass workitem IDs in the last argument register. TLI.allocateSpecialInputVGPRsFixed(CCInfo, MF, *TRI, *Info); - - if (!Subtarget.enableFlatScratch()) - CCInfo.AllocateReg(Info->getScratchRSrcReg()); - TLI.allocateSpecialInputSGPRs(CCInfo, MF, *TRI, *Info); } IncomingValueAssigner Assigner(AssignFn); @@ -732,9 +728,14 @@ bool AMDGPUCallLowering::lowerFormalArguments( uint64_t StackSize = Assigner.StackSize; // Start adding system SGPRs. - if (IsEntryFunc) + if (IsEntryFunc) { TLI.allocateSystemSGPRs(CCInfo, MF, *Info, CC, IsGraphics); - + } else { + if (!Subtarget.enableFlatScratch()) + CCInfo.AllocateReg(Info->getScratchRSrcReg()); + if(!IsGraphics) + TLI.allocateSpecialInputSGPRs(CCInfo, MF, *TRI, *Info); + } // When we tail call, we need to check if the callee's arguments will fit on // the caller's stack. So, whenever we lower formal arguments, we should keep // track of this information, since we might lower a tail call in this diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td b/llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td index c5207228dc913f..4c922a81c02efd 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td @@ -23,6 +23,7 @@ def CC_SI_Gfx : CallingConv<[ // 33 is reserved for the frame pointer // 34 is reserved for the base pointer CCIfInRegenableFlatScratch()) - CCInfo.AllocateReg(Info->getScratchRSrcReg()); - - allocateSpecialInputSGPRs(CCInfo, MF, *TRI, *Info); } if (!IsKernel) { @@ -2993,8 +2987,14 @@ SDValue SITargetLowering::LowerFormalArguments( } // Start adding system SGPRs. - if (IsEntryFunc) + if (IsEntryFunc) { allocateSystemSGPRs(CCInfo, MF, *Info, CallConv, IsGraphics); + } else { + if (!Subtarget->enableFlatScratch()) + CCInfo.AllocateReg(Info->getScratchRSrcReg()); + if(!IsGraphics) + allocateSpecialInputSGPRs(CCInfo, MF, *TRI, *Info); + } auto &ArgUsageInfo = DAG.getPass()->getAnalysis();