From 0eec68f39defe8f35efc5ce4b43fd53d226db384 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Mon, 24 Feb 2025 13:32:35 -0800 Subject: [PATCH] [flang][cuda] Relax assertion for atomicexch --- flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 2 +- flang/test/Lower/CUDA/cuda-device-proc.cuf | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 3d98fa44ab7fc..2c94a70e46b3b 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -2752,7 +2752,7 @@ mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, mlir::Value IntrinsicLibrary::genAtomicExch(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - assert(mlir::isa(args[1].getType())); + assert(args[1].getType().isIntOrFloat()); mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::xchg; return genAtomBinOp(builder, loc, binOp, args[0], args[1]); diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf index fcfcc2e537039..94cc1526e5203 100644 --- a/flang/test/Lower/CUDA/cuda-device-proc.cuf +++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf @@ -152,13 +152,16 @@ end subroutine attributes(device) subroutine testAtomic() integer :: a, istat, j + real :: r istat = atomicexch(a,0) + istat = atomicexch(r, 0.0) istat = atomicxor(a, j) istat = atomiccas(a, i, 14) end subroutine ! 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 to !llvm.ptr ! CHECK: llvm.cmpxchg %[[ADDR]], %{{.*}}, %c14{{.*}} acq_rel monotonic : !llvm.ptr, i32