This is an archive of the discontinued LLVM Phabricator instance.

[mlir][MemRef] Canonicalize reinterpret_cast(extract_strided_metadata)
ClosedPublic

Authored by qcolombet on Aug 26 2022, 6:29 PM.

Details

Summary

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 is 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!

Diff Detail

Event Timeline

qcolombet created this revision.Aug 26 2022, 6:29 PM
qcolombet requested review of this revision.Aug 26 2022, 6:29 PM
nicolasvasilache accepted this revision.Aug 29 2022, 4:43 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1622

We're now allowed to use C++17 auto, something like this should work here and below.

for (auto [extractStride, reinterpretStride] : llvm::zip(extractStridedMetadata.getStrides(), op.getStrides()))))
  if (extractStride != reinterpretStride)
    return failure();
This revision is now accepted and ready to land.Aug 29 2022, 4:43 AM
qcolombet updated this revision to Diff 456354.Aug 29 2022, 8:29 AM

Use C++17 auto style

qcolombet marked an inline comment as done.Aug 29 2022, 8:30 AM
qcolombet added inline comments.
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1622

Nice!

This revision was automatically updated to reflect the committed changes.
qcolombet marked an inline comment as done.