Issue |
152287
|
Summary |
[MLIR][fp8] MLIR lowers incorrect code for unsupported LLVM float types
|
Labels |
mlir
|
Assignees |
|
Reporter |
Dasor
|
Taking this minimal code as an example which I took from the test [here](https://github.com/llvm/llvm-project/blob/dace67e941f309318b5ce200c1f4e180a4471d20/mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir#L4)
```mlir
func.func @vectors(%a: vector<4xf8E4M3FNUZ>) -> vector<4xf32> {
%b = arith.mulf %a, %a : vector<4xf8E4M3FNUZ>
%ret = arith.extf %b : vector<4xf8E4M3FNUZ> to vector<4xf32>
func.return %ret : vector<4xf32>
}
```
And then, running the optimizations as:
```
mlir-opt --arith-emulate-unsupported-floats="source-types=bf16,f8E4M3FNUZ target-type=f32"
```
I do get the conversion done. However, once I try lowering to LLVM by using `--convert-arith-to-llvm` I get:
```
error: 'llvm.fpext' op operand #0 must be floating point LLVM type or LLVM dialect-compatible vector of floating point LLVM type, but got 'vector<4xi8>'
%b = arith.mulf %a, %a : vector<4xf8E4M3FNUZ>
^
../test2.mlir:9:8: note: see current operation: %1 = "llvm.fpext"(%0) {fastmath = #arith.fastmath<contract>} : (vector<4xi8>) -> vector<4xf32>
```
The type conversion in MLIR found [here](https://github.com/llvm/llvm-project/blob/35110445081152f7f2d2a9d053bb6fa718216d7b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp#L301C61-L301C79) converts fp8 to int8 which should not be a problem as I believe this is intended since it's a storage-only type.
But, this pass creates a `llvm.fpext` and the f8 gets converted to i8 thus creating invalid LLVM IR. I'm not sure which part is wrong here the pass or the type conversion. Without the pass it obviously doesn't work as it happens the same where fp8 gets converted into i8 in the multiplication op that expects floats. But then, what is the correct approach when lowering MLIR to LLVM with unsupported types in LLVM?
Maybe @krzysz00 or @gysit can provide some clues about this? Thanks in advance.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs