Skip to content

Commit c45457d

Browse files
AlexandreEichenbergerclingfei
authored andcommitted
[MLIR] Define memory effects for memref.prefetch operation (llvm#151261)
Currently `memref.prefetch` has no memory side effects, which are necessary for some optimizations. This PR adds the needed side effect, as recommended in https://discourse.llvm.org/t/modeling-volatility-with-memory-effects/67946 This PR was created after a discussion on this specific topic here https://discourse.llvm.org/t/memref-prefetch-op-has-no-memory-side-effects-decoration-in-the-def-td-file/87482 --------- Signed-off-by: Alexandre Eichenberger <[email protected]>
1 parent fa016a1 commit c45457d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,14 @@ def MemRef_PrefetchOp : MemRef_Op<"prefetch"> {
14141414
instruction cache.
14151415
}];
14161416

1417-
let arguments = (ins AnyMemRef:$memref, Variadic<Index>:$indices,
1417+
// The memref argument is labeled with a side effect to enforce a
1418+
// relative ordering of the prefetch and other memory operations targeting
1419+
// that memory stream.
1420+
// We need it to be a write otherwise the operation would be trivially removed
1421+
// since it does not produce a value.
1422+
1423+
let arguments = (ins Arg<AnyMemRef, "prefetch address", [MemWrite]> :$memref,
1424+
Variadic<Index>:$indices,
14181425
BoolAttr:$isWrite,
14191426
ConfinedAttr<I32Attr, [IntMinValue<0>,
14201427
IntMaxValue<3>]>:$localityHint,

mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/misc-other.mlir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ func.func @func_with_assert(%arg0: index, %arg1: index) {
1717
func.func @func_with_assume_alignment(%arg0: memref<128xi8>) {
1818
%0 = memref.assume_alignment %arg0, 64 : memref<128xi8>
1919
return
20-
}
20+
}
21+
22+
// CHECK-LABEL: func @func_with_prefetch(
23+
// CHECK: memref.prefetch %arg0[%c0, %c0], read, locality<1>, data : memref<4x8xf32>
24+
func.func @func_with_prefetch(%arg0: memref<4x8xf32>) {
25+
%c0 = arith.constant 0 : index
26+
memref.prefetch %arg0[%c0, %c0], read, locality<1>, data : memref<4x8xf32>
27+
return
28+
}

0 commit comments

Comments
 (0)