Issue |
148846
|
Summary |
[MLIR] Boolean true incorrectly cast to -1 via `tosa.cast` from i1 to i32
|
Labels |
mlir
|
Assignees |
|
Reporter |
sweead
|
test commit: [87e39c3](https://github.com/llvm/llvm-project/commit/87e39c399c96128307a826fd9168679f7c8c8d10)
## Description:
When using `tosa.cast` to convert a tensor of type `tensor<...xi1>` (i.e., 1-bit boolean values) to a wider integer type such as `tensor<...xi32>`, the cast operation performs `sign-extension` rather than zero-extension. As a result: A boolean value true (represented as 1 in i1) is sign-extended to -1 in i32 (i.e., 0xFFFFFFFF).
## Steps to Reproduce:
### Minimal MLIR program (test.mlir):
```
func.func private @printMemrefI32(tensor<*xi32>)
func.func @main() {
%0 = "tosa.const"() <{values = dense<true> : tensor<2x3x1x2xi1>}> : () -> tensor<2x3x1x2xi1>
%1 = tosa.cast %0 : (tensor<2x3x1x2xi1>) -> tensor<2x3x1x2xi32>
%cast = tensor.cast %1 : tensor<2x3x1x2xi32> to tensor<*xi32>
call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
return
}
}
```
#### Command:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir -tosa-to-linalg-pipeline -tosa-to-arith -sparsifier | \
/home/workdir/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so
```
#### Output:
```
[[[[-1, -1]],
[[-1, -1]],
[[-1, -1]]],
[[[-1, -1]],
[[-1, -1]],
[[-1, -1]]]]
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs