You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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)
```
0 commit comments