[MLIR] `promote-buffers-to-stack` fails to promote small allocation
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
`promote-buffers-to-stack` fails to convert a small heap allocation (`1xi8`, 1 byte) into a stack allocation (`memref.alloca`) even though `max-alloc-size-in-bytes` is set to a sufficiently large threshold (512 MB). The expected optimization (replacing `memref.alloc` with `memref.alloca`) is missed.
**Input Program**
**input.mlir**
```llvm
module {
func.func @threshold_overflow(%value: i8) -> i8 {
%c0 = arith.constant 0 : index
%buffer = memref.alloc() : memref<1xi8>
memref.store %value, %buffer[%c0] : memref<1xi8>
%result = memref.load %buffer[%c0] : memref<1xi8>
return %result : i8
}
}
```
**Command**
```bash
mlir-opt input.mlir -promote-buffers-to-stack="max-alloc-size-in-bytes=536870912"
```
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
Contributor guide
Research direction
Start by locating the MLIR implementation and tests for the promote-buffers-to-stack pass, then reproduce the issue with the provided input.mlir and mlir-opt command. Done means the 1xi8 memref.alloc is converted to memref.alloca when max-alloc-size-in-bytes is set to 536870912, with a regression test covering the case.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100