Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2332,17 +2332,21 @@ mlir::affine::affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
memref = storeOp.getMemRef();
memrefType = storeOp.getMemRefType();
}
// Neither load nor a store op.
// Not an affine.load/store op.
if (!memref)
return;

auto memorySpaceAttr =
dyn_cast_or_null<IntegerAttr>(memrefType.getMemorySpace());
if ((filterMemRef.has_value() && filterMemRef != memref) ||
(memorySpaceAttr &&
(isa_and_nonnull<IntegerAttr>(memrefType.getMemorySpace()) &&
memrefType.getMemorySpaceAsInt() != copyOptions.slowMemorySpace))
return;

if (!memref.getParentRegion()->isAncestor(block->getParent())) {
LLVM_DEBUG(llvm::dbgs() << "memref definition is inside of the depth at "
"which copy-in/copy-out would happen\n");
return;
}

// Compute the MemRefRegion accessed.
auto region = std::make_unique<MemRefRegion>(opInst->getLoc());
if (failed(region->compute(opInst, copyDepth, /*sliceState=*/nullptr,
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Dialect/Affine/affine-data-copy.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,15 @@ func.func @scalar_memref_copy_in_loop(%3:memref<480xi1>) {
// CHECK: memref.dealloc %[[FAST_MEMREF]] : memref<480xi1>
return
}

// CHECK-LABEL: func @memref_def_inside
func.func @memref_def_inside(%arg0: index) {
%0 = llvm.mlir.constant(1.000000e+00 : f32) : f32
// No copy generation can happen at this depth given the definition inside.
affine.for %arg1 = 0 to 29 {
%alloc_7 = memref.alloc() : memref<1xf32>
// CHECK: affine.store {{.*}} : memref<1xf32>
affine.store %0, %alloc_7[0] : memref<1xf32>
}
return
}