Skip to content

Commit 36b339b

Browse files
authored
[flang][cuda] Relax assertion for atomicexch (#128582)
atomicexch interfaces accepts also floating point numbers. Relax the assertion so float are also accepted.
1 parent 594919c commit 36b339b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType,
27602760
mlir::Value IntrinsicLibrary::genAtomicExch(mlir::Type resultType,
27612761
llvm::ArrayRef<mlir::Value> args) {
27622762
assert(args.size() == 2);
2763-
assert(mlir::isa<mlir::IntegerType>(args[1].getType()));
2763+
assert(args[1].getType().isIntOrFloat());
27642764

27652765
mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::xchg;
27662766
return genAtomBinOp(builder, loc, binOp, args[0], args[1]);

flang/test/Lower/CUDA/cuda-device-proc.cuf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,16 @@ end subroutine
152152

153153
attributes(device) subroutine testAtomic()
154154
integer :: a, istat, j
155+
real :: r
155156
istat = atomicexch(a,0)
157+
istat = atomicexch(r, 0.0)
156158
istat = atomicxor(a, j)
157159
istat = atomiccas(a, i, 14)
158160
end subroutine
159161

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

0 commit comments

Comments
 (0)