[mlir][MemRef] Canonicalize reinterpret_cast(extract_strided_metadata)
authorQuentin Colombet <quentin.colombet@gmail.com>
Sat, 27 Aug 2022 01:14:23 +0000 (01:14 +0000)
committerQuentin Colombet <quentin.colombet@gmail.com>
Mon, 29 Aug 2022 17:00:50 +0000 (17:00 +0000)
commitba916c0cf6d0149f81bf1137e88f7d6fd3b0cc76
treed9a1361d93009261546074784c35c78d68f31f6e
parent9af0a142e43625cb8478b83692510a5abd39f808
[mlir][MemRef] Canonicalize reinterpret_cast(extract_strided_metadata)

Add a canonicalizetion step for
reinterpret_cast(extract_strided_metadata).
This step replaces this sequence of operations by either:
- A noop, i.e., the original memref is directly used, or
- A plain cast of the original memref

The choice is ultimately made based on whether the original memref type
is equal to what the reinterpret_cast iss producing. For instance, the
reinterpret_cast could be changing some dimensions from static to
dynamic and in such case, we need to keep a cast.

The transformation is currently only performed when the reinterpret_cast
uses exactly the same arguments as what the extract_strided_metadata
produces. It may be possible to be more aggressive here but I wanted to
start with a relatively simple MLIR patch for my first one!

Differential Revision: https://reviews.llvm.org/D132776
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
mlir/test/Dialect/MemRef/canonicalize.mlir