From 28244e9e6ed649011f5154a5b17ac821d3bfddc3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Jan 2023 11:12:54 +0100 Subject: [PATCH] [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. --- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 4 +++- mlir/test/Dialect/LLVMIR/invalid.mlir | 7 +++++++ mlir/test/Target/LLVMIR/Import/instructions.ll | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index d5116bf..015bff8 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(); diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir index 7d130b2..fe76979 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, %i32 : i32) { // ----- +func.func @cmpxchg_mismatched_value_operands(%ptr : !llvm.ptr, %i32 : i32, %i64 : i64) { + // expected-error@+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) { // expected-error@+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 305ffe8..4557944 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 } -- 2.7.4