This is an archive of the discontinued LLVM Phabricator instance.

[mlir][memref] Tighten verification of memref.reinterpret_cast
ClosedPublic

Authored by herhut on Jan 4 2022, 8:19 AM.

Details

Summary

We allow the omission of a map in memref.reinterpret_cast under the assumption, that the cast might cast to an identity layout. This change adds verification that the static knowledge that is present in the reinterpret_cast supports this assumption.

Diff Detail

Event Timeline

herhut created this revision.Jan 4 2022, 8:19 AM
herhut requested review of this revision.Jan 4 2022, 8:19 AM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1166

Can you just replace the condition by: if (isStrided(resultType)) ?

herhut updated this revision to Diff 398068.Jan 7 2022, 12:56 AM

Simplified as suggested

herhut added inline comments.Jan 7 2022, 12:58 AM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1166

Good point, I combined the two cases. I was not aware that getStridesAndOffset also works for identity maps. But of course it needs to.

nicolasvasilache accepted this revision.Jan 7 2022, 1:10 AM

Nice cleanup!

mlir/test/mlir-cpu-runner/copy.mlir
38–40

This looks pretty dangerous.
Why not just use memref.transpose which has better static guarantees?

This revision is now accepted and ready to land.Jan 7 2022, 1:10 AM

Side note: I think we could also drop memref.view and just use this instead.
This would be a good starter task.

mlir/test/Dialect/MemRef/canonicalize.mlir
154

doesn't this fundamentally break the ability to do the "stride-0" trick?

herhut added a comment.Jan 7 2022, 4:36 AM

Thanks!

mlir/test/Dialect/MemRef/canonicalize.mlir
154

We never do the stride-0 trick in the static case, so the 0 is always a dynamic value. Because we cannot express the static case properly. It would require an affine map with a 0 constant (otherwise the type is a lie).

The stride-0 trick if fishy anyway and we need to move away from it.

mlir/test/mlir-cpu-runner/copy.mlir
38–40

I prefer this form, as it makes it explicit what strides we have. This is just to test that the copy honors that information.

pifon2a accepted this revision.Jan 10 2022, 1:52 AM