[Mlir-commits] [mlir] d54e447 - [mlir][LLVMIR] Allow !llvm.ptr<ptr> operands in atomicrmw xchg op.

Ingo Müller llvmlistbot at llvm.org
Mon Jun 26 01:40:09 PDT 2023


Author: Ingo Müller
Date: 2023-06-26T08:40:05Z
New Revision: d54e447848e9e2b6410b22587f4179f2bc7a28bc

URL: https://github.com/llvm/llvm-project/commit/d54e447848e9e2b6410b22587f4179f2bc7a28bc
DIFF: https://github.com/llvm/llvm-project/commit/d54e447848e9e2b6410b22587f4179f2bc7a28bc.diff

LOG: [mlir][LLVMIR] Allow !llvm.ptr<ptr> operands in atomicrmw xchg op.

Previously, llvm.atomicrmw only allowed operands that are pointers to
LLVM floats or integers. However, according to the LLVM IR Language
Reference, that op allows pointer to pointer operands in its `xchg`
mode. This patch allows those operands also in MLIR's LLVM dialect and
adapts the tests accordingly.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D153747

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    mlir/test/Dialect/LLVMIR/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index a106592c9b5a2..8536cbf835332 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1832,7 +1832,7 @@ def LLVM_ConstantOp
 // Atomic operations.
 //
 
-def LLVM_AtomicRMWType : AnyTypeOf<[LLVM_AnyFloat, AnyInteger]>;
+def LLVM_AtomicRMWType : AnyTypeOf<[LLVM_AnyFloat, LLVM_AnyPointer, AnyInteger]>;
 
 def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [
       TypesMatchWith<"result #0 and operand #1 have the same type",

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 7bbdb67d8c4a7..b24e2ca47b688 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2450,7 +2450,7 @@ LogicalResult AtomicRMWOp::verify() {
     if (!mlir::LLVM::isCompatibleFloatingPointType(valType))
       return emitOpError("expected LLVM IR floating point type");
   } else if (getBinOp() == AtomicBinOp::xchg) {
-    if (!isTypeCompatibleWithAtomicOp(valType, /*isPointerTypeAllowed=*/false))
+    if (!isTypeCompatibleWithAtomicOp(valType, /*isPointerTypeAllowed=*/true))
       return emitOpError("unexpected LLVM IR type for 'xchg' bin_op");
   } else {
     auto intType = llvm::dyn_cast<IntegerType>(valType);

diff  --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 787889f413b5c..c88ed03f0c6e0 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -633,7 +633,7 @@ func.func @nvvm_invalid_mma_8(%a0 : i32, %a1 : i32,
 // -----
 
 func.func @atomicrmw_expected_ptr(%f32 : f32) {
-  // expected-error at +1 {{operand #0 must be LLVM pointer to floating point LLVM type or integer}}
+  // expected-error at +1 {{operand #0 must be LLVM pointer to floating point LLVM type or LLVM pointer type or integer}}
   %0 = "llvm.atomicrmw"(%f32, %f32) {bin_op=11, ordering=1} : (f32, f32) -> f32
   llvm.return
 }


        


More information about the Mlir-commits mailing list