[all-commits] [llvm/llvm-project] 7a8bff: [mlir][tosa-to-linalg] fix arithmetic_right_shift ...

Congcong Cai via All-commits all-commits at lists.llvm.org
Mon Sep 22 16:06:50 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7a8bff48c1ad5f4fdfd8cd6b947a1fc50e144642
      https://github.com/llvm/llvm-project/commit/7a8bff48c1ad5f4fdfd8cd6b947a1fc50e144642
  Author: Congcong Cai <congcongcai0907 at 163.com>
  Date:   2025-09-23 (Tue, 23 Sep 2025)

  Changed paths:
    M mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
    M mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

  Log Message:
  -----------
  [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)
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list