[AMDGPU][GISel] Add inverse ballot intrinsic
authorJessica Del <Jessica.Del@amd.com>
Thu, 16 Mar 2023 16:17:20 +0000 (17:17 +0100)
committerJessica Del <Jessica.Del@amd.com>
Thu, 6 Apr 2023 05:46:50 +0000 (07:46 +0200)
commit04317d4da78e4d444f59d182b8b7c63ae3608eb6
treef88d5d0c2692e198cc009bfa23931034aa5eb093
parent51b5b299f9fecf052a7973b2c05fa129229834fd
[AMDGPU][GISel] Add inverse ballot intrinsic

The inverse ballot intrinsic takes in a boolean mask for all lanes and
returns the boolean for the current lane. See SPIR-V's
`subgroupInverseBallot()` in the [[ https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_shader_subgroup.txt | GL_KHR_shader_subgroup extension ]].
This allows decision making via branch and select instructions with a manually
manipulated mask.

Implemented in GlobalISel and SelectionDAG, since currently both are supported.
The SelectionDAG required pseudo instructions to use the custom inserter.

The boolean mask needs to be uniform for all lanes.
Therefore we expect SGPR input. In case the source is in a
VGPR, we insert one or more `v_readfirstlane` instructions.

Reviewed By: nhaehnle

Differential Revision: https://reviews.llvm.org/D146287
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/AMDGPU/SIInstructions.td
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.inverse.ballot.i32.ll [new file with mode: 0644]
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.inverse.ballot.i64.ll [new file with mode: 0644]