[mlir][tosa] Canonicalize concatenate->slice sequence
authorLuke Hutton <luke.hutton@arm.com>
Wed, 22 Mar 2023 00:54:15 +0000 (00:54 +0000)
committerRobert Suderman <suderman@google.com>
Wed, 22 Mar 2023 16:52:44 +0000 (16:52 +0000)
commit9e3ca7987a4dc33cdf847b79a6304b117651d21f
tree38c61504c37d8261d7028b898723c08ff299fb40
parent83e420c65f4a6c0b693af82cfd81ae58fd033f97
[mlir][tosa] Canonicalize concatenate->slice sequence

Adds a canonicalizer for the concatenate->slice sequence where
an output of slice can be replaced with an input of concatenate.

This is useful in the context of operations with complex inputs
and outputs that are legalized from a framework such as TFL.
For example, a TFL graph (FFT->FFT) will be legalized to the
following TOSA graph:

     <complex input>
         /     \
     slice    slice
         \     /
           FFT
          /   \     -+
       concatenate   |
         /     \     |  Redundant
     slice    slice  |
         \     /    -+
           FFT
         /     \
       concatenate
            |
     <complex output>

Concatenate and slice operations at the boundaries of the graph are
useful as they maintain the correct correspondance of input/output
tensors to the original TFL graph. However, consecutive
complex operations will result in redundant concatenate->slice
sequences which should be removed from the final TOSA graph.

The canonicalization does not currently handle dynamic types.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D144545
mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
mlir/test/Dialect/Tosa/canonicalize.mlir