Issue |
150302
|
Summary |
[MLIR][TOSA] Folding cast to bool gives wrong value
|
Labels |
mlir:tosa
|
Assignees |
|
Reporter |
GleasonK
|
I'm fixing what I believe to be a bug in StableHLO with our type convert folder, and I believe it may exist in other dialects as well?
Looking at https://www.mlplatform.org/tosa/tosa_spec.html#_cast:
```
if (is_same<out_t,bool_t>()) {
out = (in != 0) ? true : false;
}
```
However with a lack of special casing bools Convert / Cast-like ops these are folded incorrectly:
```
$ cat /tmp/t.mlir
func.func @const_f32_bool() -> tensor<i1> {
%cst = arith.constant dense<10> : tensor<i32>
%0 = tosa.cast %cst : (tensor<i32>) -> tensor<i1>
func.return %0 : tensor<i1>
}
$ mlir-opt /tmp/t.mlir --canonicalize
module {
func.func @const_f32_bool() -> tensor<i1> {
%0 = "tosa.const"() <{values = dense<false> : tensor<i1>}> : () -> tensor<i1>
return %0 : tensor<i1>
}
}
```
Input was `10 != 0` so probably should be folded to `true`(?) Not sure if there are other cast-like ops in upstream dialects that may have this issue as well?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs