Skip to content

[flang][cuda] Fix atmoicxor lowering to accept arrays #130331

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
Mar 7, 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
3 changes: 2 additions & 1 deletion flang/include/flang/Optimizer/Builder/IntrinsicCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ struct IntrinsicLibrary {
mlir::Value genAtomicMin(mlir::Type, llvm::ArrayRef<mlir::Value>);
mlir::Value genAtomicOr(mlir::Type, llvm::ArrayRef<mlir::Value>);
mlir::Value genAtomicSub(mlir::Type, llvm::ArrayRef<mlir::Value>);
mlir::Value genAtomicXor(mlir::Type, llvm::ArrayRef<mlir::Value>);
fir::ExtendedValue genAtomicXor(mlir::Type,
llvm::ArrayRef<fir::ExtendedValue>);
fir::ExtendedValue
genCommandArgumentCount(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
mlir::Value genAsind(mlir::Type, llvm::ArrayRef<mlir::Value>);
Expand Down
12 changes: 6 additions & 6 deletions flang/lib/Optimizer/Builder/IntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2827,13 +2827,13 @@ mlir::Value IntrinsicLibrary::genAtomicMin(mlir::Type resultType,
}

// ATOMICXOR
mlir::Value IntrinsicLibrary::genAtomicXor(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
fir::ExtendedValue
IntrinsicLibrary::genAtomicXor(mlir::Type resultType,
llvm::ArrayRef<fir::ExtendedValue> args) {
assert(args.size() == 2);
assert(mlir::isa<mlir::IntegerType>(args[1].getType()));

mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::_xor;
return genAtomBinOp(builder, loc, binOp, args[0], args[1]);
mlir::Value arg0 = fir::getBase(args[0]);
mlir::Value arg1 = fir::getBase(args[1]);
return genAtomBinOp(builder, loc, mlir::LLVM::AtomicBinOp::_xor, arg0, arg1);
}

// ASSOCIATED
Expand Down
13 changes: 10 additions & 3 deletions flang/test/Lower/CUDA/cuda-device-proc.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,28 @@ end subroutine
! CHECK: fir.convert %{{.*}} : (f64) -> i64
! CHECK: fir.call @llvm.nvvm.match.any.sync.i64p

attributes(device) subroutine testAtomic()
integer :: a, istat, j
attributes(device) subroutine testAtomic(aa, n)
integer :: aa(*)
integer, intent(in) :: n
integer :: a, istat, j, i
real :: r
istat = atomicexch(a,0)
istat = atomicexch(r, 0.0)
istat = atomicxor(a, j)
istat = atomiccas(a, i, 14)
do i = 1, n
istat = atomicxor(aa, i)
end do
end subroutine

! CHECK-LABEL: func.func @_QPtestatomic()
! CHECK-LABEL: func.func @_QPtestatomic
! CHECK: llvm.atomicrmw xchg %{{.*}}, %c0{{.*}} seq_cst : !llvm.ptr, i32
! CHECK: llvm.atomicrmw xchg %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, f32
! CHECK: llvm.atomicrmw _xor %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, i32
! CHECK: %[[ADDR:.*]] = builtin.unrealized_conversion_cast %{{.*}}#1 : !fir.ref<i32> to !llvm.ptr
! CHECK: llvm.cmpxchg %[[ADDR]], %{{.*}}, %c14{{.*}} acq_rel monotonic : !llvm.ptr, i32
! CHECK: fir.do_loop
! CHECK: llvm.atomicrmw _xor %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, i32

attributes(device) subroutine testAtomic2()
integer(8) :: a, i, istat
Expand Down