diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp --- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp @@ -602,6 +602,8 @@ unsigned sizeInBits; if (elementType.isIntOrFloat()) { sizeInBits = elementType.getIntOrFloatBitWidth(); + } else if (elementType.isIndex()) { + sizeInBits = IndexType::kInternalStorageBitWidth; } else { auto vectorType = elementType.cast(); sizeInBits = @@ -642,7 +644,8 @@ if (!memRefType.hasStaticShape()) return std::nullopt; auto elementType = memRefType.getElementType(); - if (!elementType.isIntOrFloat() && !elementType.isa()) + if (!elementType.isIntOrFloat() && !elementType.isa() && + !elementType.isIndex()) return std::nullopt; uint64_t sizeInBytes = getMemRefEltSizeInBytes(memRefType); diff --git a/mlir/test/Dialect/Affine/affine-data-copy.mlir b/mlir/test/Dialect/Affine/affine-data-copy.mlir --- a/mlir/test/Dialect/Affine/affine-data-copy.mlir +++ b/mlir/test/Dialect/Affine/affine-data-copy.mlir @@ -1,6 +1,7 @@ // RUN: mlir-opt %s -split-input-file -affine-data-copy-generate="generate-dma=false fast-mem-space=0 skip-non-unit-stride-loops" | FileCheck %s // Small buffer size to trigger fine copies. // RUN: mlir-opt %s -split-input-file -affine-data-copy-generate="generate-dma=false fast-mem-space=0 fast-mem-capacity=1" | FileCheck --check-prefix=CHECK-SMALL %s +// RUN: mlir-opt %s -split-input-file -affine-data-copy-generate | FileCheck --check-prefix=CHECK-INDEX %s // Test affine data copy with a memref filter. We use a test pass that invokes // affine data copy utility on the input loop nest. @@ -286,3 +287,35 @@ // CHECK-NOT: memref.alloc // CHECK: return } + +// ----- +func.func @index_element_memref(%arg0: memref<1x2x4x8xindex>) { + // Not to fail with an index element memref + affine.for %arg1 = 0 to 1 { + affine.for %arg2 = 0 to 2 { + affine.for %arg3 = 0 to 4 { + affine.for %arg4 = 0 to 8 { + affine.store %arg4, %arg0[%arg1, %arg2, %arg3, %arg4] : memref<1x2x4x8xindex> + } + } + } + } + return +} + +// CHECK-INDEX-LABEL: func @index_element_memref +// CHECK-INDEX: %[[ALLOC:.*]] = memref.alloc() : memref<1x2x4x8xindex, 1> +// CHECK-INDEX-NEXT: %[[ALLOC1:.*]] = memref.alloc() : memref<1xi32> +// CHECK-INDEX-NEXT: affine.for %{{.*}} = 0 to 1 { +// CHECK-INDEX-NEXT: affine.for %{{.*}} = 0 to 2 { +// CHECK-INDEX-NEXT: affine.for %{{.*}} = 0 to 4 { +// CHECK-INDEX-NEXT: affine.for %{{.*}} = 0 to 8 { +// CHECK-INDEX-NEXT: affine.store %{{.*}}, %[[ALLOC]][%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}] : memref<1x2x4x8xindex, 1> +// CHECK-INDEX-NEXT: } +// CHECK-INDEX-NEXT: } +// CHECK-INDEX-NEXT: } +// CHECK-INDEX-NEXT: } + +// CHECK-INDEX: memref.dealloc %[[ALLOC1]] : memref<1xi32> +// CHECK-INDEX-NEXT: memref.dealloc %[[ALLOC]] : memref<1x2x4x8xindex, 1> +// CHECK-INDEX-NEXT: return