[clang] [clang][AMDGPU] Widen ballot for read_exec_lo/hi to wavefront size (PR #212813)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 29 11:55:15 PDT 2026
================
@@ -275,13 +275,22 @@ Value *EmitAMDGPUGridSize(CodeGenFunction &CGF, unsigned Index) {
// Generates the IR for __builtin_read_exec_*.
// Lowers the builtin to amdgcn_ballot intrinsic.
+//
+// The ballot must be taken at the wavefront width: a ballot narrower than the
+// wave size cannot represent one bit per lane and fails to select. Request the
+// mask at the wave width and narrow it afterwards for the _lo and _hi halves.
static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
llvm::Type *RegisterType,
llvm::Type *ValueType, bool isExecHi) {
CodeGen::CGBuilderTy &Builder = CGF.Builder;
CodeGen::CodeGenModule &CGM = CGF.CGM;
- Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
+ unsigned WaveSize = CGF.getTarget().getGridValue().GV_Warp_Size;
+ llvm::Type *BallotType = RegisterType;
+ if (BallotType->getIntegerBitWidth() < WaveSize)
----------------
arsenm wrote:
This shouldn't need to figure out the type, it should directly take the type
https://github.com/llvm/llvm-project/pull/212813
More information about the cfe-commits
mailing list