Skip to content

Commit 4b943e8

Browse files
committed
comments, reject 0-poerand version
1 parent 1e24829 commit 4b943e8

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ def DistinctObjectsOp : MemRef_Op<"distinct_objects", [
187187
]> {
188188
let summary = "assumption that acesses to specific memrefs will never alias";
189189
let description = [{
190-
The `distinct_objects` operation takes a list of memrefs and returns a list of
191-
memrefs of the same types, with the additional assumption that accesses to
192-
these memrefs will never alias with each other. This means that loads and
193-
stores to different memrefs in the list can be safely reordered.
194-
195-
If the memrefs do alias, the behavior is undefined. This operation doesn't
196-
affect the semantics of a program where the non-aliasing assumption holds
197-
true. It is intended for optimization purposes, allowing the compiler to
198-
generate more efficient code based on the non-aliasing assumption. The
199-
optimization is best-effort.
190+
The `distinct_objects` operation takes a list of memrefs and returns the same
191+
memrefs, with the additional assumption that accesses to them will never
192+
alias with each other. This means that loads and stores to different
193+
memrefs in the list can be safely reordered.
194+
195+
If the memrefs do alias, the load/store behavior is undefined. This
196+
operation doesn't affect the semantics of a valid program. It is
197+
intended for optimization purposes, allowing the compiler to generate more
198+
efficient code based on the non-aliasing assumption. The optimization is
199+
best-effort.
200200

201201
Example:
202202

mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,12 @@ struct DistinctObjectsOpLowering
476476
matchAndRewrite(memref::DistinctObjectsOp op, OpAdaptor adaptor,
477477
ConversionPatternRewriter &rewriter) const override {
478478
ValueRange operands = adaptor.getOperands();
479-
if (operands.empty()) {
480-
rewriter.eraseOp(op);
479+
if (operands.size() <= 1) {
480+
// Fast path.
481+
rewriter.replaceOp(op, operands);
481482
return success();
482483
}
484+
483485
Location loc = op.getLoc();
484486
SmallVector<Value> ptrs;
485487
for (auto [origOperand, newOperand] :

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ OpFoldResult AssumeAlignmentOp::fold(FoldAdaptor adaptor) {
549549
LogicalResult DistinctObjectsOp::verify() {
550550
if (getOperandTypes() != getResultTypes())
551551
return emitOpError("operand types and result types must match");
552+
553+
if (getOperandTypes().empty())
554+
return emitOpError("expected at least one operand");
555+
552556
return success();
553557
}
554558

mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ func.func @distinct_objects(%arg0: memref<?xf16>, %arg1: memref<?xf32>, %arg2: m
214214

215215
// -----
216216

217+
// ALL-LABEL: func @distinct_objects_noop
218+
// ALL-SAME: (%[[ARG0:.*]]: memref<?xf16>)
219+
func.func @distinct_objects_noop(%arg0: memref<?xf16>) -> memref<?xf16> {
220+
// 1-operand version is noop
221+
// ALL-NEXT: return %[[ARG0]]
222+
%1 = memref.distinct_objects %arg0 : memref<?xf16>
223+
return %1 : memref<?xf16>
224+
}
225+
226+
// -----
227+
217228
// CHECK-LABEL: func @assume_alignment_w_offset
218229
// CHECK-INTERFACE-LABEL: func @assume_alignment_w_offset
219230
func.func @assume_alignment_w_offset(%0 : memref<4x4xf16, strided<[?, ?], offset: ?>>) {

mlir/test/Dialect/MemRef/invalid.mlir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,16 @@ func.func @expand_shape_invalid_output_shape(
11721172

11731173
// -----
11741174

1175-
func.func @Invalid_distinct_objects(%arg0: memref<?xf32>, %arg1: memref<?xi32>) -> (memref<?xi32>, memref<?xf32>) {
1175+
func.func @distinct_objects_types_mismatch(%arg0: memref<?xf32>, %arg1: memref<?xi32>) -> (memref<?xi32>, memref<?xf32>) {
11761176
// expected-error @+1 {{operand types and result types must match}}
11771177
%0, %1 = "memref.distinct_objects"(%arg0, %arg1) : (memref<?xf32>, memref<?xi32>) -> (memref<?xi32>, memref<?xf32>)
11781178
return %0, %1 : memref<?xi32>, memref<?xf32>
11791179
}
1180+
1181+
// -----
1182+
1183+
func.func @distinct_objects_0_operands() {
1184+
// expected-error @+1 {{expected at least one operand}}
1185+
"memref.distinct_objects"() : () -> ()
1186+
return
1187+
}

0 commit comments

Comments
 (0)