[Mlir-commits] [mlir] 1cf7b8f - Revert "[mlir][llvm] Fix elem type passing into `getelementptr` (#68136)"

Mehdi Amini llvmlistbot at llvm.org
Thu Oct 5 17:38:57 PDT 2023


Author: Mehdi Amini
Date: 2023-10-05T17:38:41-07:00
New Revision: 1cf7b8f5e21d679bf1cb0efa4e1b80d8966fa07b

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

LOG: Revert "[mlir][llvm] Fix elem type passing into `getelementptr` (#68136)"

This reverts commit fe283a1ff74fdfa46dd2bedf60e544d747d3416e.

Bot is broken.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    mlir/test/Target/LLVMIR/opaque-ptr.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 9d46c5b3bdc5e1b..25209ce4497455e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -303,13 +303,8 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
         indices.push_back(
             builder.getInt32(valueOrAttr.get<IntegerAttr>().getInt()));
     }
-
-    Type elemTypeFromAttr = op.getSourceElementType();
-    auto ptrType = ::llvm::cast<LLVMPointerType>(op.getType());
-    Type elemTypeFromPtrType = ptrType.getElementType();
-
-    llvm::Type *elementType = moduleTranslation.convertType(
-        elemTypeFromAttr ? elemTypeFromAttr : elemTypeFromPtrType);
+    Type baseElementType = op.getSourceElementType();
+    llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
     $res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
   }];
   let assemblyFormat = [{

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 62cb595069e6652..95c04098d05fc2f 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -287,17 +287,14 @@ ParseResult AllocaOp::parse(OpAsmParser &parser, OperationState &result) {
 }
 
 /// Checks that the elemental type is present in either the pointer type or
-/// the attribute, but not in none or both.
+/// the attribute, but not both.
 static LogicalResult verifyOpaquePtr(Operation *op, LLVMPointerType ptrType,
                                      std::optional<Type> ptrElementType) {
-  bool typePresentInPointerType = !ptrType.isOpaque();
-  bool typePresentInAttribute = ptrElementType.has_value();
-
-  if (!typePresentInPointerType && !typePresentInAttribute) {
+  if (ptrType.isOpaque() && !ptrElementType.has_value()) {
     return op->emitOpError() << "expected '" << kElemTypeAttrName
                              << "' attribute if opaque pointer type is used";
   }
-  if (typePresentInPointerType && typePresentInAttribute) {
+  if (!ptrType.isOpaque() && ptrElementType.has_value()) {
     return op->emitOpError()
            << "unexpected '" << kElemTypeAttrName
            << "' attribute when non-opaque pointer type is used";

diff  --git a/mlir/test/Target/LLVMIR/opaque-ptr.mlir b/mlir/test/Target/LLVMIR/opaque-ptr.mlir
index 3bde192b4cc4d02..c21f9b0542debc6 100644
--- a/mlir/test/Target/LLVMIR/opaque-ptr.mlir
+++ b/mlir/test/Target/LLVMIR/opaque-ptr.mlir
@@ -42,15 +42,6 @@ llvm.func @opaque_ptr_gep_struct(%arg0: !llvm.ptr, %arg1: i32) -> !llvm.ptr {
   llvm.return %0 : !llvm.ptr
 }
 
-// CHECK-LABEL: @opaque_ptr_elem_type
-llvm.func @opaque_ptr_elem_type(%0: !llvm.ptr) -> !llvm.ptr {
-  // CHECK: getelementptr ptr, ptr
-  %1 = llvm.getelementptr %0[0] { elem_type = !llvm.ptr } : (!llvm.ptr) -> !llvm.ptr
-  // CHECK: getelementptr ptr, ptr
-  %2 = llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr<ptr>
-  llvm.return %1 : !llvm.ptr
-}
-
 // CHECK-LABEL: @opaque_ptr_matrix_load_store
 llvm.func @opaque_ptr_matrix_load_store(%ptr: !llvm.ptr, %stride: i64) -> vector<48 x f32> {
   // CHECK: call <48 x float> @llvm.matrix.column.major.load.v48f32.i64


        


More information about the Mlir-commits mailing list