[Mlir-commits] [mlir] 3c70a82 - [mlir] fix integer type mismatch in alloc conversion to LLVM

Alex Zinenko llvmlistbot at llvm.org
Tue Jun 8 02:11:39 PDT 2021


Author: Alex Zinenko
Date: 2021-06-08T11:11:28+02:00
New Revision: 3c70a82e2891949801bd5da68159cd8156659f6f

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

LOG: [mlir] fix integer type mismatch in alloc conversion to LLVM

Some places in the alloc-like op conversion use the converted index type
whereas other places use the pointer-sized integer type, which may not be the
same. Consistently use the converted index type, similarly to other address
calculations.

Reviewed By: pifon2a

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

Added: 
    

Modified: 
    mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
    mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index 6ddc333a011c0..dcbb4b336213f 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -1878,10 +1878,9 @@ struct AllocOpLowering : public AllocLikeOpLLVMLowering {
 
     Value alignedPtr = allocatedPtr;
     if (alignment) {
-      auto intPtrType = getIntPtrType(memRefType.getMemorySpaceAsInt());
       // Compute the aligned type pointer.
       Value allocatedInt =
-          rewriter.create<LLVM::PtrToIntOp>(loc, intPtrType, allocatedPtr);
+          rewriter.create<LLVM::PtrToIntOp>(loc, getIndexType(), allocatedPtr);
       Value alignmentInt =
           createAligned(rewriter, loc, allocatedInt, alignment);
       alignedPtr =

diff  --git a/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir b/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
index 82dddeb962cc5..27623393148f3 100644
--- a/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -convert-std-to-llvm %s | FileCheck %s
+// RUN: mlir-opt -convert-std-to-llvm -split-input-file %s | FileCheck %s
 // RUN: mlir-opt -convert-std-to-llvm='use-bare-ptr-memref-call-conv=1' -split-input-file %s | FileCheck %s --check-prefix=BAREPTR
 
 // BAREPTR-LABEL: func @check_noalias
@@ -402,3 +402,28 @@ func @check_unranked_memref_func_call(%in: memref<*xi8>) -> memref<*xi8> {
   // BAREPTR-NEXT: return %{{.*}} : memref<*xi8>
   return %res : memref<*xi8>
 }
+
+// -----
+
+// Check that consistent types are emitted in address arithemic in presence of
+// a data layout specification.
+module attributes { dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<index, 32>> } {
+  func @address() {
+    %c1 = constant 1 : index
+    %0 = memref.alloc(%c1) : memref<? x vector<2xf32>>
+    // CHECK: %[[CST:.*]] = llvm.mlir.constant(1 : index) : i32
+    // CHECK: llvm.mlir.null
+    // CHECK: llvm.getelementptr %{{.*}}[[CST]]
+    // CHECK: llvm.ptrtoint %{{.*}} : !llvm.ptr<{{.*}}> to i32
+    // CHECK: llvm.ptrtoint %{{.*}} : !llvm.ptr<{{.*}}> to i32
+    // CHECK: llvm.add %{{.*}} : i32
+    // CHECK: llvm.call @malloc(%{{.*}}) : (i32) -> !llvm.ptr
+    // CHECK: llvm.ptrtoint %{{.*}} : !llvm.ptr<{{.*}}> to i32
+    // CHECK: llvm.sub {{.*}} : i32
+    // CHECK: llvm.add {{.*}} : i32
+    // CHECK: llvm.urem {{.*}} : i32
+    // CHECK: llvm.sub {{.*}} : i32
+    // CHECK: llvm.inttoptr %{{.*}} : i32 to !llvm.ptr
+    return
+  }
+}


        


More information about the Mlir-commits mailing list