This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferize] Always bufferize top-to-bottom
ClosedPublic

Authored by springerm on Mar 3 2022, 4:53 AM.

Details

Summary

This ensures that we generate memref types with matching layout maps. (Especially when using partial bufferization passes.)

Diff Detail

Event Timeline

springerm created this revision.Mar 3 2022, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 4:53 AM
springerm requested review of this revision.Mar 3 2022, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 4:53 AM
pifon2a accepted this revision.Mar 3 2022, 5:05 AM
This revision is now accepted and ready to land.Mar 3 2022, 5:05 AM
This revision was automatically updated to reflect the committed changes.
bkramer added a subscriber: bkramer.Mar 7 2022, 3:34 AM
bkramer added inline comments.
mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
313

You have to pass the config to applyPatternsAndFoldGreedily or it'll just be ignored.

The commit description seems to indicate that this is a behavior change, is it? Can you expose it in a test?

More importantly what may be concerning is the use of the greedy pattern rewrite with an expectation of order of traversal that would be semantically meaningful.

You have to pass the config to applyPatternsAndFoldGreedily or it'll just be ignored.

My bad, thx for letting me know.

The commit description seems to indicate that this is a behavior change, is it? Can you expose it in a test?

Actually no change in behavior. Even without config, the traversal happened to be top-to-bottom. But I guess it was not guaranteed. This is just making it explicit.

More importantly what may be concerning is the use of the greedy pattern rewrite with an expectation of order of traversal that would be semantically meaningful.

Can you elaborate a bit? Why is it concerning to specify a traversal order? It looks like the API has been designed with this in mind.

Can you elaborate a bit? Why is it concerning to specify a traversal order? It looks like the API has been designed with this in mind.

The API is designed to not make it a semantics change. I believe the original intent was motivated by benchmarks showing that one order may produce drastically faster convergence than an other one.
What is important to understand is that the algorithm is iterative and worklist based. The only impact of this flag is how the worklist is "primed", it does not guarantee anything beyond that: the algorithm will update the worklist as it goes (revisiting operands/results somehow after rewriting an operation).

Basically for semantically driven rewrites, DialectConversion has a controlled order of traversal, but isn't greedy / iterative.

Can you elaborate a bit? Why is it concerning to specify a traversal order? It looks like the API has been designed with this in mind.

The API is designed to not make it a semantics change. I believe the original intent was motivated by benchmarks showing that one order may produce drastically faster convergence than an other one.
What is important to understand is that the algorithm is iterative and worklist based. The only impact of this flag is how the worklist is "primed", it does not guarantee anything beyond that: the algorithm will update the worklist as it goes (revisiting operands/results somehow after rewriting an operation).

Basically for semantically driven rewrites, DialectConversion has a controlled order of traversal, but isn't greedy / iterative.

OK, then we probably want a custom Operation::walk here.

Can you elaborate a bit? Why is it concerning to specify a traversal order? It looks like the API has been designed with this in mind.

The API is designed to not make it a semantics change. I believe the original intent was motivated by benchmarks showing that one order may produce drastically faster convergence than an other one.
What is important to understand is that the algorithm is iterative and worklist based. The only impact of this flag is how the worklist is "primed", it does not guarantee anything beyond that: the algorithm will update the worklist as it goes (revisiting operands/results somehow after rewriting an operation).

Basically for semantically driven rewrites, DialectConversion has a controlled order of traversal, but isn't greedy / iterative.

OK, then we probably want a custom Operation::walk here.

As a side note, the only reason why "top-to-bottom" traversal is a semantics change is because we are missing canonicalization patterns. The generated code is always correct, regardless of the pattern application order. It's just that some orders generate less efficient code. This could be cleaned up by canonicalization patterns (some of which do not currently exist).