Skip to content

Commit

Permalink
Allow 16 bit floating point operand for LLVM_AtomicRMWOp
Browse files Browse the repository at this point in the history
As far as AMDGPU target supports vectorization for atomic_rmw operation,
allow construction of LLVM_AtomicRMWOp with 16 bit floating point values.

See also: llvm#94845, llvm#95393, llvm#95394

Signed-off-by: Ilya Veselov <iveselov.nn@gmail.com>
  • Loading branch information
joviliast committed Sep 27, 2024
1 parent 3527e83 commit 5d1c13f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@ def LLVM_ConstantOp
// Atomic operations.
//

def LLVM_AtomicRMWType : AnyTypeOf<[LLVM_AnyFloat, LLVM_AnyPointer, AnySignlessInteger]>;
def LLVM_AtomicRMWType
: AnyTypeOf<[LLVM_ScalarOrVectorOf<LLVM_AnyFloat>, LLVM_AnyPointer, AnySignlessInteger]>;

def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [
TypesMatchWith<"result #0 and operand #1 have the same type",
Expand Down
14 changes: 11 additions & 3 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3008,9 +3008,17 @@ void AtomicRMWOp::build(OpBuilder &builder, OperationState &state,

LogicalResult AtomicRMWOp::verify() {
auto valType = getVal().getType();
if (getBinOp() == AtomicBinOp::fadd || getBinOp() == AtomicBinOp::fsub ||
getBinOp() == AtomicBinOp::fmin || getBinOp() == AtomicBinOp::fmax) {
if (!mlir::LLVM::isCompatibleFloatingPointType(valType))
if (getBinOp() == AtomicBinOp::fadd &&
mlir::LLVM::isCompatibleVectorType(valType)) {
Type elemType = mlir::LLVM::getVectorElementType(valType);
if (mlir::LLVM::isCompatibleFloatingPointType(elemType) &&
elemType.getIntOrFloatBitWidth() == 16)
return emitOpError("unexpected LLVM IR type for vector element");
} else if (getBinOp() == AtomicBinOp::fadd ||
getBinOp() == AtomicBinOp::fsub ||
getBinOp() == AtomicBinOp::fmin ||
getBinOp() == AtomicBinOp::fmax) {
if (!isCompatibleFloatingPointType(valType))
return emitOpError("expected LLVM IR floating point type");
} else if (getBinOp() == AtomicBinOp::xchg) {
DataLayout dataLayout = DataLayout::closest(*this);
Expand Down

0 comments on commit 5d1c13f

Please sign in to comment.