| Issue |
166958
|
| Summary |
func.func fails to lower to llvm.func when arguments or return types contain dynamic or boolean tensors
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Subway2023
|
**Description**
While testing lowering MLIR `func.func` to LLVM IR, we found that functions with **dynamic tensors**, **boolean tensors**, or other special types in arguments or return values often fail to lower.
### Case 1
```mlir
module {
func.func nested @func1() -> vector<30xi64> {
%cst = arith.constant 3.472000e+04 : f16
...
}
func.func @func2() -> tensor<?xi64> {
%cst = arith.constant 3.472000e+04 : f16
...
}
}
```
Lowering command:
```bash
/llvm-project-llvmorg-21.1.2/build/bin/mlir-opt \
--arith-expand \
--arith-unsigned-when-equivalent \
--convert-vector-to-scf \
--convert-scf-to-cf \
--convert-vector-to-llvm \
--one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" \
--finalize-memref-to-llvm \
--convert-arith-to-llvm \
--convert-cf-to-llvm \
--convert-func-to-llvm \
--reconcile-unrealized-casts \
program_352287.mlir
```
Result:
* `@func1` is successfully lowered to `llvm.func` because it returns a `vector<30xi64>`.
* `@func2` is **not lowered**, remains as `func.func` because it returns a dynamic `tensor<?xi64>`.
---
### Case 2
```mlir
module {
func.func private @func1() { ... }
func.func private @func2(%arg0: vector<10xf32>, %arg1: memref<?xi32>, %arg2: tensor<?x21xi32>) -> tensor<21x21xi1> {
...
}
}
```
Lowering command:
```bash
/llvm-project-llvmorg-21.1.2/build/bin/mlir-opt \
--one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" \
--canonicalize \
--buffer-deallocation-pipeline \
--convert-vector-to-scf \
--convert-scf-to-cf \
--convert-vector-to-llvm \
--convert-arith-to-llvm \
--finalize-memref-to-llvm \
--convert-cf-to-llvm \
--convert-arith-to-llvm \
--finalize-memref-to-llvm \
--convert-func-to-llvm \
--reconcile-unrealized-casts \
program_3279.mlir
```
Result:
* `@func1` is successfully lowered.
* `@func2` **remains as `func.func`**, because it has arguments and return values with **vector**, **memref**, and **tensor<?xiN> / tensor<...xi1>** types, which are not fully supported for lowering.
---
**Expected Behavior**
* All `func.func` should lower to `llvm.func`, even if arguments or return types include dynamic tensors, boolean tensors, or vectors.
* Alternatively, documentation should clearly indicate which types cannot be lowered and suggest proper handling (e.g., bufferization).
---
**Actual Behavior**
* Functions with dynamic tensor or boolean tensor types are not lowered.
* Functions with vector or memref types can be lowered correctly.
---
**Environment**
* MLIR version: LLVM 21.1.2
* OS: Linux
* Command-line flags: as above
---
[program_352287.txt](https://github.com/user-attachments/files/23420739/program_352287.txt)
[program_3279.txt](https://github.com/user-attachments/files/23420738/program_3279.txt)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs