[Mlir-commits] [mlir] [mlir][memref] Introduce `memref.distinct_objects` op (PR #156913)
Ivan Butygin
llvmlistbot at llvm.org
Thu Sep 25 08:18:23 PDT 2025
================
@@ -465,6 +465,50 @@ struct AssumeAlignmentOpLowering
}
};
+struct DistinctObjectsOpLowering
+ : public ConvertOpToLLVMPattern<memref::DistinctObjectsOp> {
+ using ConvertOpToLLVMPattern<
+ memref::DistinctObjectsOp>::ConvertOpToLLVMPattern;
+ explicit DistinctObjectsOpLowering(const LLVMTypeConverter &converter)
+ : ConvertOpToLLVMPattern<memref::DistinctObjectsOp>(converter) {}
+
+ LogicalResult
+ matchAndRewrite(memref::DistinctObjectsOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ ValueRange operands = adaptor.getOperands();
+ if (operands.size() <= 1) {
+ // Fast path.
+ rewriter.replaceOp(op, operands);
+ return success();
+ }
+
+ Location loc = op.getLoc();
+ SmallVector<Value> ptrs;
+ for (auto [origOperand, newOperand] :
+ llvm::zip_equal(op.getOperands(), operands)) {
+ auto memrefType = cast<MemRefType>(origOperand.getType());
+ Value ptr = getStridedElementPtr(rewriter, loc, memrefType, newOperand,
----------------
Hardcode84 wrote:
Copying comment from the other discussion
@krzysz00
> I'm not sure this is the right thing? I think we want bufferPtr on MemRefDescriptor.
That's a good question, imagine we have code like
```
%0 = memref.alloc
%1 = memref.subview %0[%c0]
%2 = memref.subview %0[%c1024]
%3, %4 = memrefs.distinct_objects %1, %2
```
If we just use `bufferPtr` without the offset we will en up with `assume separate_storage(%ptr, %ptr)`, i.e. same pointer, which makes no sense.
https://github.com/llvm/llvm-project/pull/156913
More information about the Mlir-commits
mailing list