This is an archive of the discontinued LLVM Phabricator instance.

[mlir][LLVM] Make `SplitStores` pattern capable of writing to sub-aggregates
ClosedPublic

Authored by zero9178 on Jul 7 2023, 5:29 AM.

Details

Summary

The pattern was previously only capable of storing into struct fields which are primitive types. If the struct contained a nested struct it immediately aborted the pattern rewrite.

This patch introduces the capability of recursively splitting stores into sub-aggregates as well. This is achieved by splitting an aggregate sized integer from the original store argument and letting repeated pattern applications further split it into field stores.

Additionally, the pattern is also capable of handling partial writes into aggregates, which is a pattern clang generates as well. Special care had to be taken to make sure no stores are created that weren't in the original code.

Diff Detail

Event Timeline

zero9178 created this revision.Jul 7 2023, 5:29 AM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
zero9178 requested review of this revision.Jul 7 2023, 5:29 AM
gysit added inline comments.Jul 9 2023, 9:14 AM
mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp
395

I guess there is a slight risk here that we may not be able to split the store into the nested array/struct?

508–515
zero9178 updated this revision to Diff 538522.Jul 10 2023, 12:19 AM
zero9178 marked an inline comment as done.

address review comments

mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp
395

Yes. This transformation is generally optimistic in that it always assumes that integer stores into structs it generates can be further split up. Checking otherwise would require doing a recursive check of the fields/elements of the aggregate.
That said, I think its a rather unlikely case that an integer store would create consistent stores into some fields followed by an inconsistent store into a subaggregate. And even if, the generated code stays correct.

zero9178 updated this revision to Diff 538594.Jul 10 2023, 5:42 AM

add explicit check making sure that when splitting an integer only partially storing into an aggregate that it can also be split afterwards

gysit accepted this revision.Jul 10 2023, 6:27 AM

Thanks LGTM modulo ultra nit.

mlir/test/Dialect/LLVMIR/type-consistency.mlir
552
This revision is now accepted and ready to land.Jul 10 2023, 6:27 AM
zero9178 marked an inline comment as done.Jul 10 2023, 6:29 AM