Index: lib/Target/AMDGPU/AMDGPUSubtarget.h =================================================================== --- lib/Target/AMDGPU/AMDGPUSubtarget.h +++ lib/Target/AMDGPU/AMDGPUSubtarget.h @@ -587,6 +587,9 @@ FlatWorkGroupSize); } + /// \returns Default range flat work group size for a calling convention. + std::pair getDefaultFlatWorkGroupSize(CallingConv::ID CC) const; + /// \returns Subtarget's default pair of minimum/maximum flat work group sizes /// for function \p F, or minimum/maximum flat work group sizes explicitly /// requested using "amdgpu-flat-work-group-size" attribute attached to Index: lib/Target/AMDGPU/AMDGPUSubtarget.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUSubtarget.cpp +++ lib/Target/AMDGPU/AMDGPUSubtarget.cpp @@ -190,14 +190,31 @@ return NumWaves; } +std::pair +AMDGPUSubtarget::getDefaultFlatWorkGroupSize(CallingConv::ID CC) const { + switch (CC) { + case CallingConv::AMDGPU_CS: + case CallingConv::AMDGPU_KERNEL: + case CallingConv::SPIR_KERNEL: + return std::make_pair(getWavefrontSize() * 2, getWavefrontSize() * 4); + case CallingConv::AMDGPU_VS: + case CallingConv::AMDGPU_LS: + case CallingConv::AMDGPU_HS: + case CallingConv::AMDGPU_ES: + case CallingConv::AMDGPU_GS: + case CallingConv::AMDGPU_PS: + return std::make_pair(1, getWavefrontSize()); + default: + return std::make_pair(1, 16 * getWavefrontSize()); + } +} + std::pair AMDGPUSubtarget::getFlatWorkGroupSizes( const Function &F) const { + // FIXME: 1024 if function. // Default minimum/maximum flat work group sizes. std::pair Default = - AMDGPU::isCompute(F.getCallingConv()) ? - std::pair(getWavefrontSize() * 2, - getWavefrontSize() * 4) : - std::pair(1, getWavefrontSize()); + getDefaultFlatWorkGroupSize(F.getCallingConv()); // TODO: Do not process "amdgpu-max-work-group-size" attribute once mesa // starts using "amdgpu-flat-work-group-size" attribute. Index: test/CodeGen/AMDGPU/zext-lid.ll =================================================================== --- test/CodeGen/AMDGPU/zext-lid.ll +++ test/CodeGen/AMDGPU/zext-lid.ll @@ -63,6 +63,26 @@ ret void } +; OPT-LABEL: @func_test_workitem_id_x_known_max_range( +; OPT: tail call i32 @llvm.amdgcn.workitem.id.x(), !range !0 +define void @func_test_workitem_id_x_known_max_range(i32 addrspace(1)* nocapture %out) #0 { +entry: + %id = tail call i32 @llvm.amdgcn.workitem.id.x() + %and = and i32 %id, 1023 + store i32 %and, i32 addrspace(1)* %out, align 4 + ret void +} + +; OPT-LABEL: @func_test_workitem_id_x_default_range( +; OPT: tail call i32 @llvm.amdgcn.workitem.id.x(), !range !6 +define void @func_test_workitem_id_x_default_range(i32 addrspace(1)* nocapture %out) #4 { +entry: + %id = tail call i32 @llvm.amdgcn.workitem.id.x() + %and = and i32 %id, 1023 + store i32 %and, i32 addrspace(1)* %out, align 4 + ret void +} + declare i32 @llvm.amdgcn.workitem.id.x() #2 declare i32 @llvm.amdgcn.workitem.id.y() #2 @@ -73,6 +93,7 @@ attributes #1 = { nounwind "amdgpu-flat-work-group-size"="512,512" } attributes #2 = { nounwind readnone speculatable } attributes #3 = { nounwind readnone } +attributes #4 = { nounwind } !0 = !{i32 32, i32 4, i32 1} @@ -82,3 +103,4 @@ ; OPT: !3 = !{i32 0, i32 4} ; OPT: !4 = !{i32 0, i32 1} ; OPT: !5 = !{i32 0, i32 512} +; OPT: !6 = !{i32 0, i32 1024}