[mlir][arith] Add initial integer bitwidth narrowing pass
authorJakub Kuderski <kubak@google.com>
Wed, 26 Apr 2023 02:25:11 +0000 (22:25 -0400)
committerJakub Kuderski <kubak@google.com>
Wed, 26 Apr 2023 02:33:11 +0000 (22:33 -0400)
commitda0730b908a43e490430717beda8486598667ab8
tree7b9ab26929c98d886c851fed154d431a8b86bde8
parent5b869f3e2af485b2b97368e36dbff1c4e28c0d7e
[mlir][arith] Add initial integer bitwidth narrowing pass

This pass reduces the logical complexity of arith ops by choosing
narrowest supported operand bitwidth. On some targets like mobile GPUs,
narrower bitwidths also bring better runtime performance.

The first batch of rewrites handles a simple case of `arith.sitofp`
and `arith.uitofp` with zero/sign-extended inputs. In future revisions,
I plan to extend it with the following:
-  Propagating sign/zero-extensions through bit-pattern-preserving ops,
   e.g., vector transpose, broadcast, insertions/extractions.
-  Handling `linalg.index` using the `ValueBounds` interface.
-  Handling more arith ops.

Reviewed By: springerm, antiagainst

Differential Revision: https://reviews.llvm.org/D149118
mlir/include/mlir/Dialect/Arith/Transforms/Passes.h
mlir/include/mlir/Dialect/Arith/Transforms/Passes.td
mlir/lib/Dialect/Arith/Transforms/CMakeLists.txt
mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp [new file with mode: 0644]
mlir/test/Dialect/Arith/int-narrowing.mlir [new file with mode: 0644]