[Mlir-commits] [mlir] [mlir][bufferization] Use Type instead of Value in unknown conversion (PR #144658)

Han-Chung Wang llvmlistbot at llvm.org
Mon Jun 30 11:59:59 PDT 2025


hanhanW wrote:

> Generally, bufferization should be able to create a memref from a tensor without needing to know more than just a mlir::Type.

Is it true?

In [IREE](https://github.com/iree-org/iree/blob/63f625d428a31e6ccf2fd594e544c3bef659c63f/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp#L143-L164), we have special logic for constants. I don't remember all the details, my guess is that we'd like to use private memory for small constants. I can try to make our project happy, but the change itself looks off to me. We name the function as `unknownTypeConverterFn`, but you always pass tensor types. I was thinking if passing Value  allows you doing custom tensor types better because you can define and use your own type system in your dialect.

The lit test failure in IREE is that we always expect [identity layout for constants](https://github.com/iree-org/iree/blob/63f625d428a31e6ccf2fd594e544c3bef659c63f/compiler/src/iree/compiler/Codegen/Common/test/iree_comprehensive_bufferize.mlir#L1404-L1406). Without passing the value and check if it is constant, we'll create a memref type with fully dynamic layout, while the constant is known static identity layout. Is there a way to recover the behavior?

Original output:

```mlir
    %cst_0 = arith.constant dense<[1, 2, 3, 4, 5]> : tensor<5xi32>
    %0 = bufferization.to_buffer %cst_0 : tensor<5xi32> to memref<5xi32>
```

With the change, we always create dynamic layout for constants:

```mlir
    %cst_0 = arith.constant dense<[1, 2, 3, 4, 5]> : tensor<5xi32>
    %0 = bufferization.to_buffer %cst_0 : tensor<5xi32> to memref<5xi32, strided<[?], offset: ?>>
```



https://github.com/llvm/llvm-project/pull/144658


More information about the Mlir-commits mailing list