This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Convert memref_reshape to memref_reinterpret_cast.
ClosedPublic

Authored by pifon2a on Oct 27 2020, 8:09 AM.

Details

Summary

I had to remove some checks in MemRefReinterpretCastOp::verify. It might make
sense to convert to LLVM directly to avoid that.

https://llvm.discourse.group/t/rfc-standard-memref-cast-ops/1454/15

Diff Detail

Event Timeline

pifon2a created this revision.Oct 27 2020, 8:09 AM
pifon2a requested review of this revision.Oct 27 2020, 8:09 AM
Harbormaster completed remote builds in B76562: Diff 300999.
ekatz added a subscriber: ekatz.Oct 28 2020, 12:45 AM
ekatz added inline comments.
mlir/lib/Dialect/StandardOps/Transforms/ExpandMemRefReshape.cpp
27

This comment is incorrect

pifon2a marked an inline comment as done.Oct 28 2020, 1:59 AM
pifon2a updated this revision to Diff 301199.Oct 28 2020, 2:00 AM

Fix the comment

herhut added inline comments.Oct 28 2020, 7:12 AM
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
2270

Missing space after comma.

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2293

Why use an assign here and not construct directly?

2395

Can you explain why these checks needed to go?

pifon2a updated this revision to Diff 301287.Oct 28 2020, 7:57 AM
pifon2a marked 2 inline comments as done.

Address the comments, add integration test.

pifon2a added inline comments.Oct 28 2020, 8:04 AM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2395

I put the checks back, but only when the result has an affine map specified.

What was happening is the following:

when

%result = memref_reshape %input(%shape)
              : (memref<*xf32>, memref<3xi32>) -> memref<?x?x?xf32>

is transformed into

%result = memref_reinterpret_cast %input
   to offset: [0], sizes: [%s0, %s1, %s2],
   strides: [%str0, %str1, %c1] : memref<*xf32> to memref<?x?x?xf32>

the verifier would fail because it would try to compare strides and offsets in the affine map of the result.

pifon2a marked an inline comment as done.Oct 28 2020, 8:04 AM
herhut accepted this revision.Oct 28 2020, 8:33 AM

Please address comments, otherwise lgtm.

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2434

Remove tabs and the comment could state that this checks whether the offsets and strides match the map in the type, if any is present.

This revision is now accepted and ready to land.Oct 28 2020, 8:33 AM
pifon2a updated this revision to Diff 301404.Oct 28 2020, 1:06 PM
pifon2a marked an inline comment as done.

Address the comments.

pifon2a updated this revision to Diff 301406.Oct 28 2020, 1:10 PM

Remove tabs

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2434

those are not the tabs :) I think that's how diff is rendered here.

This revision was landed with ongoing or failed builds.Oct 28 2020, 1:15 PM
This revision was automatically updated to reflect the committed changes.