Index: lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h =================================================================== --- lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -39,7 +39,8 @@ enum { // The closed Vulkan driver sets 96, which limits the wave count to 8 but // doesn't spill SGPRs as much as when 80 is set. - FIXED_NUM_SGPRS_FOR_INIT_BUG = 96 + FIXED_NUM_SGPRS_FOR_INIT_BUG = 96, + TRAP_NUM_SGPRS = 16 }; /// \brief Instruction set architecture version. Index: lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp =================================================================== --- lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -216,7 +216,9 @@ unsigned MinNumSGPRs = alignDown(getTotalNumSGPRs(Features) / (WavesPerEU + 1), getSGPRAllocGranule(Features)) + 1; - return std::min(MinNumSGPRs, getAddressableNumSGPRs(Features)); + return std::min(MinNumSGPRs - + (Features.test(FeatureTrapHandler) ? TRAP_NUM_SGPRS : 0), + getAddressableNumSGPRs(Features)); } unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU, @@ -229,7 +231,9 @@ unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Features); if (Version.Major >= 8 && !Addressable) AddressableNumSGPRs = 112; - return std::min(MaxNumSGPRs, AddressableNumSGPRs); + return std::min(MaxNumSGPRs - + (Features.test(FeatureTrapHandler) ? TRAP_NUM_SGPRS : 0), + AddressableNumSGPRs); } unsigned getVGPRAllocGranule(const FeatureBitset &Features) {