This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferize] Do not insert useless casts for newly allocated buffers
ClosedPublic

Authored by springerm on Apr 8 2022, 1:46 AM.

Details

Summary

Newly allocated buffers do not have a layout map. Bufferization patterns can add a fully dynamic layout map via casting. This should be done only if the layout map is actually needed and not by default on every allocation.

When bufferizing scf.for ops, such layout maps may actually be needed. E.g., after bufferizing an scf.for loop:

scf.for ... -> memref<?xf32, #map> {
  // We alloc because of an out-of-place bufferization.
  %0 = memref.alloc : memref<?xf32>
  // Here we actually need a cast.
  scf.yield %0 : memref<?xf32>
}

Depends On D123321

Diff Detail

Event Timeline

springerm created this revision.Apr 8 2022, 1:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 1:46 AM
springerm requested review of this revision.Apr 8 2022, 1:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 1:46 AM
akuegel accepted this revision.Apr 8 2022, 1:51 AM
This revision is now accepted and ready to land.Apr 8 2022, 1:51 AM
springerm edited the summary of this revision. (Show Details)Apr 8 2022, 1:51 AM

Also just curious, does this really depend on the other patch?

springerm edited the summary of this revision. (Show Details)Apr 8 2022, 1:54 AM

Also just curious, does this really depend on the other patch?

Yes, it does. The diffbase commit fixes an issue with missing arith.select casts that it triggered when removing the unneeded casts in here.