[mlir] Add folding of memref_cast inside another memref_cast
authorAlex Zinenko <zinenko@google.com>
Fri, 6 Nov 2020 09:20:08 +0000 (10:20 +0100)
committerAlex Zinenko <zinenko@google.com>
Fri, 6 Nov 2020 09:42:40 +0000 (10:42 +0100)
commit0c782c214b56102161c03ec5657455b7c73a5722
treed5a08498dd752264b98d25c9d95b2f9e7d7ee762
parent2dbcbd357d1da1adf9c512d150e68424faa46d75
[mlir] Add folding of memref_cast inside another memref_cast

There exists a generic folding facility that folds the operand of a memref_cast
into users of memref_cast that support this. However, it was not used for the
memref_cast itself. Fix it to enable elimination of memref_cast chains such as

  %1 = memref_cast %0 : A to B
  %2 = memref_cast %1 : B to A

that is achieved by combining the folding with the existing "A to A" cast
elimination.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D90910
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/Transforms/canonicalize.mlir