This is an archive of the discontinued LLVM Phabricator instance.

[mlir][MemRef] Simplify extract_strided_metadata(allocLikeOp)
ClosedPublic

Authored by qcolombet on Sep 23 2022, 5:18 PM.

Details

Summary

Teach the pass that simplifies extract_strided_metadata(other_op(memref))
how to get rid of extract_strided_metadata when they are fed by
allocLikeOp.

For the simplification to happen the allocLikeOp needs to have been
normalized. I.e., no weird offset and strides.

When this is the case, we replace:

base, offset, sizes, strides =
    extract_strided_metadata(allocLikeOp(allocSizes))

With

base = reinterpret_cast allocLikeOp(allocSizes) to a flat memref<eltTy>
offset = 0 
sizes = allocSizes
strides#i = prod(allocSizes#j, for j in {i+1..rank-1})

The computation involving dynamic sizes are expanded in affine.apply.

Diff Detail

Event Timeline

qcolombet created this revision.Sep 23 2022, 5:18 PM
qcolombet requested review of this revision.Sep 23 2022, 5:18 PM
This revision is now accepted and ready to land.Sep 26 2022, 4:42 AM
ftynse accepted this revision.Sep 26 2022, 5:57 AM
ftynse added a subscriber: ftynse.
ftynse added inline comments.
mlir/lib/Dialect/MemRef/Transforms/SimplifyExtractStridedMetadata.cpp
438

Nit: mlir usually uses triple-backticks for code blocks.

qcolombet added inline comments.Sep 26 2022, 8:03 AM
mlir/lib/Dialect/MemRef/Transforms/SimplifyExtractStridedMetadata.cpp
438

Thanks for the information, fixing!