Commit 7a8bff4
authored
[mlir][tosa-to-linalg] fix arithmetic_right_shift conversion with round (#159930)
Fixed: #154259
According to TOSA spec, `tosa.arithmetic_right_shift` should handle
round.
```
if (round == true && static_cast<int32_t>(value2) > 0 &&
(apply_arith_rshift<in_out_t>(value1, apply_sub_s<in_out_t>(value2, 1)) & 1 != 0)) {
result = result + 1;
}
```
The original conversion is the similar as definition, and will convert
to pseudo code
```c++
result = (value1 >> value2) +
( (i1)(value2 > 0) & (i1)((value1 >> (value2 - 1)) & 1) )
```
But when value2 is 0,`value1 >> (value2 - 1)` will produce poison value
because performing arithmetic right shift on a negative number. Then the
poison value propagate to the final result.
This PR wants to change the conversion to `arith.select` to stop poison
propagation.
```c++
result = (value1 >> value2) +
(value2 > 0) ? (i1)((value1 >> (value2 - 1)) & 1) : (i1)(0)
```1 parent d08e445 commit 7a8bff4
File tree
2 files changed
+7
-4
lines changed- mlir
- lib/Conversion/TosaToLinalg
- test/Conversion/TosaToLinalg
2 files changed
+7
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
| 309 | + | |
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
| |||
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
325 | | - | |
326 | | - | |
327 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
328 | 330 | | |
329 | 331 | | |
330 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
| 701 | + | |
701 | 702 | | |
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
705 | 706 | | |
706 | 707 | | |
707 | | - | |
| 708 | + | |
708 | 709 | | |
709 | 710 | | |
710 | 711 | | |
| |||
0 commit comments