-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
Description
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
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:
/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.mlirResult:
@func1is successfully lowered tollvm.funcbecause it returns avector<30xi64>.@func2is not lowered, remains asfunc.funcbecause it returns a dynamictensor<?xi64>.
Case 2
module {
func.func private @func1() { ... }
func.func private @func2(%arg0: vector<10xf32>, %arg1: memref<?xi32>, %arg2: tensor<?x21xi32>) -> tensor<21x21xi1> {
...
}
}Lowering command:
/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.mlirResult:
@func1is successfully lowered.@func2remains asfunc.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.funcshould lower tollvm.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