Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -414,7 +414,7 @@ } } - if (VCCUsed) + if (VCCUsed || FlatUsed) MaxSGPR += 2; if (FlatUsed) Index: test/CodeGen/AMDGPU/ci-reserve-sgpr-for-flat-scratch-init.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/ci-reserve-sgpr-for-flat-scratch-init.ll @@ -0,0 +1,14 @@ +; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | FileCheck %s + +; CHECK: wavefront_sgpr_count = 10 +; CHECK-NOT: wavefront_sgpr_count = 8 +define spir_kernel void @test(i64 addrspace(1)* nocapture %arg, i32 %arg1, i32 %arg2) #0 { +bb: + %tmp = add nsw i32 %arg1, 10 + %tmp8 = add nsw i32 %tmp, %arg2 + %tmp9 = sext i32 %tmp8 to i64 + %tmp10 = add nsw i64 %tmp9, 22 + %tmp11 = getelementptr inbounds i64, i64 addrspace(1)* %arg, i64 %tmp10 + store i64 13, i64 addrspace(1)* %tmp11, align 8 + ret void +}