Skip to content

[flang][cuda] Fix pred type for vote functions #134166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions flang/lib/Optimizer/Builder/IntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6508,12 +6508,13 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType,
}

static mlir::Value genVoteSync(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::StringRef funcName,
llvm::StringRef funcName, mlir::Type resTy,
llvm::ArrayRef<mlir::Value> args) {
mlir::MLIRContext *context = builder.getContext();
mlir::Type i32Ty = builder.getI32Type();
mlir::Type i1Ty = builder.getI1Type();
mlir::FunctionType ftype =
mlir::FunctionType::get(context, {i32Ty, i32Ty}, {i32Ty});
mlir::FunctionType::get(context, {i32Ty, i1Ty}, {resTy});
auto funcOp = builder.createFunction(loc, funcName, ftype);
llvm::SmallVector<mlir::Value> filteredArgs;
return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0);
Expand All @@ -6523,22 +6524,25 @@ static mlir::Value genVoteSync(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value IntrinsicLibrary::genVoteAllSync(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
return genVoteSync(builder, loc, "llvm.nvvm.vote.all.sync", args);
return genVoteSync(builder, loc, "llvm.nvvm.vote.all.sync",
builder.getI1Type(), args);
}

// ANY_SYNC
mlir::Value IntrinsicLibrary::genVoteAnySync(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
return genVoteSync(builder, loc, "llvm.nvvm.vote.any.sync", args);
return genVoteSync(builder, loc, "llvm.nvvm.vote.any.sync",
builder.getI1Type(), args);
}

// BALLOT_SYNC
mlir::Value
IntrinsicLibrary::genVoteBallotSync(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
return genVoteSync(builder, loc, "llvm.nvvm.vote.ballot.sync", args);
return genVoteSync(builder, loc, "llvm.nvvm.vote.ballot.sync",
builder.getI32Type(), args);
}

// MATCH_ANY_SYNC
Expand Down
9 changes: 5 additions & 4 deletions flang/test/Lower/CUDA/cuda-device-proc.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ end
! CHECK: fir.call @__ldcv_r8x2_(%{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.array<2xf64>>, !fir.ref<!fir.array<?xf64>>) -> ()

attributes(device) subroutine testVote()
integer :: a, ipred, mask, v32
a = all_sync(mask, v32)
a = any_sync(mask, v32)
a = ballot_sync(mask, v32)
integer :: a, ipred, mask
logical(4) :: pred
a = all_sync(mask, pred)
a = any_sync(mask, pred)
a = ballot_sync(mask, pred)
end subroutine

! CHECK-LABEL: func.func @_QPtestvote()
Expand Down