[all-commits] [llvm/llvm-project] 2e4e21: [mlir] Avoid folding `index.remu` and `index.rems`...

Rik Huijzer via All-commits all-commits at lists.llvm.org
Wed May 31 10:45:41 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2e4e218474320abf480c39d3b968a5a09477ad03
      https://github.com/llvm/llvm-project/commit/2e4e218474320abf480c39d3b968a5a09477ad03
  Author: rikhuijzer <rikhuijzer at pm.me>
  Date:   2023-05-31 (Wed, 31 May 2023)

  Changed paths:
    M mlir/lib/Dialect/Index/IR/IndexOps.cpp
    M mlir/test/Dialect/Index/index-canonicalize.mlir

  Log Message:
  -----------
  [mlir] Avoid folding `index.remu` and `index.rems` for 0 rhs

As discussed in https://github.com/llvm/llvm-project/issues/59714#issuecomment-1369518768, the folder for the remainder operations should be resillient when the rhs is 0.
The file `IndexOps.cpp` was already checking for multiple divisions by zero, so I tried to stick to the code style from those checks.

Fixes #59714.

As a side note, is it correct that remainder operations are never optimized away? I would expect that the following code

```
func.func @remu_test() -> index {
  %c3 = index.constant 2
  %c0 = index.constant 1
  %0 = index.remu %c3, %c0
  return %0 : index
}
```
would be optimized to
```
func.func @remu_test() -> index {
  return index.constant 0 : index
}
```
when called with `mlir-opt --convert-scf-to-openmp temp.mlir`, but maybe I'm misunderstanding something.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D151476




More information about the All-commits mailing list