[Mlir-commits] [mlir] 28244e9 - [MLIR] Don't verify opaque pointer type in cmpxchg
Nikita Popov
llvmlistbot at llvm.org
Tue Jan 17 02:14:43 PST 2023
Author: Nikita Popov
Date: 2023-01-17T11:13:44+01:00
New Revision: 28244e9e6ed649011f5154a5b17ac821d3bfddc3
URL: https://github.com/llvm/llvm-project/commit/28244e9e6ed649011f5154a5b17ac821d3bfddc3
DIFF: https://github.com/llvm/llvm-project/commit/28244e9e6ed649011f5154a5b17ac821d3bfddc3.diff
LOG: [MLIR] Don't verify opaque pointer type in cmpxchg
We should not check the element type for opaque pointers. We should
still check that the value operands have the same type though.
This causes a verifier error when converting instructions.ll to
opaque pointers.
Added:
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/test/Dialect/LLVMIR/invalid.mlir
mlir/test/Target/LLVMIR/Import/instructions.ll
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index d5116bf5881ad..015bff8a9f840 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2430,7 +2430,9 @@ LogicalResult AtomicCmpXchgOp::verify() {
return emitOpError("expected LLVM IR pointer type for operand #0");
auto cmpType = getCmp().getType();
auto valType = getVal().getType();
- if (cmpType != ptrType.getElementType() || cmpType != valType)
+ if (cmpType != valType)
+ return emitOpError("expected both value operands to have the same type");
+ if (!ptrType.isOpaque() && cmpType != ptrType.getElementType())
return emitOpError("expected LLVM IR element type for operand #0 to "
"match type for all other operands");
auto intType = valType.dyn_cast<IntegerType>();
diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 7d130b202bf1f..fe76979c9808a 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -645,6 +645,13 @@ func.func @cmpxchg_mismatched_operands(%i64_ptr : !llvm.ptr<i64>, %i32 : i32) {
// -----
+func.func @cmpxchg_mismatched_value_operands(%ptr : !llvm.ptr, %i32 : i32, %i64 : i64) {
+ // expected-error at +1 {{expected both value operands to have the same type}}
+ %0 = "llvm.cmpxchg"(%ptr, %i32, %i64) {success_ordering=2,failure_ordering=2} : (!llvm.ptr, i32, i64) -> !llvm.struct<(i32, i1)>
+ llvm.return
+}
+// -----
+
func.func @cmpxchg_unexpected_type(%i1_ptr : !llvm.ptr<i1>, %i1 : i1) {
// expected-error at +1 {{unexpected LLVM IR type}}
%0 = llvm.cmpxchg %i1_ptr, %i1, %i1 monotonic monotonic : i1
diff --git a/mlir/test/Target/LLVMIR/Import/instructions.ll b/mlir/test/Target/LLVMIR/Import/instructions.ll
index 305ffe8c60fde..4557944ef23c8 100644
--- a/mlir/test/Target/LLVMIR/Import/instructions.ll
+++ b/mlir/test/Target/LLVMIR/Import/instructions.ll
@@ -402,11 +402,11 @@ define void @atomic_rmw(ptr %ptr1, i32 %val1, ptr %ptr2, float %val2) {
; CHECK-SAME: %[[PTR1:[a-zA-Z0-9]+]]
; CHECK-SAME: %[[VAL1:[a-zA-Z0-9]+]]
; CHECK-SAME: %[[VAL2:[a-zA-Z0-9]+]]
-define void @atomic_cmpxchg(i32* %ptr1, i32 %val1, i32 %val2) {
+define void @atomic_cmpxchg(ptr %ptr1, i32 %val1, i32 %val2) {
; CHECK: llvm.cmpxchg %[[PTR1]], %[[VAL1]], %[[VAL2]] seq_cst seq_cst : i32
- %1 = cmpxchg i32* %ptr1, i32 %val1, i32 %val2 seq_cst seq_cst
+ %1 = cmpxchg ptr %ptr1, i32 %val1, i32 %val2 seq_cst seq_cst
; CHECK: llvm.cmpxchg %[[PTR1]], %[[VAL1]], %[[VAL2]] monotonic seq_cst : i32
- %2 = cmpxchg i32* %ptr1, i32 %val1, i32 %val2 monotonic seq_cst
+ %2 = cmpxchg ptr %ptr1, i32 %val1, i32 %val2 monotonic seq_cst
ret void
}
More information about the Mlir-commits
mailing list