Tessera Pattern Matching with Struct Arguments#2437
Draft
jessicacotturone21 wants to merge 7 commits into
Draft
Conversation
wsmoses
reviewed
Apr 17, 2026
| if (getOperand(i - startIdx).getType() == fnType.getInput(i)) | ||
| continue; | ||
| if (isa<LLVM::LLVMPointerType>(fnType.getInput(i)) && | ||
| fn.getArgAttr(i, LLVM::LLVMDialect::getReadonlyAttrName())) |
Member
There was a problem hiding this comment.
you also need to check nocapture, and it can be readonly or readnone
wsmoses
reviewed
Apr 17, 2026
wsmoses
reviewed
Apr 17, 2026
Member
wsmoses
left a comment
There was a problem hiding this comment.
consider a fn
double* pointeradd(double* x, int y) {
return &x[y];
}
we could define an opt pointeradd(pointeradd(x, y), z) -> pointeradd(x, y+z)
double x[10] -> double* [ptr]
64e632d to
9edf2eb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2437 +/- ##
=======================================
Coverage 25.47% 25.47%
=======================================
Files 220 220
Lines 44600 44600
=======================================
Hits 11364 11364
Misses 33236 33236 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
02a826d to
d0393b4
Compare
d0393b4 to
dc87129
Compare
…o allow for pattern matching
dc87129 to
703d97a
Compare
703d97a to
cb0df8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal of this pull request is to allow for more pattern matching to occur by eliminating intermediate stores when we have struct arguments and returns. We also allow users to specify whether arguments are byref in the source code (as well as the size of the arguments), and any arguments specified as byref will be loaded and converted to byval in our tessera passes.
The user can now specify that an argument is byref like this:
tessera_op = eigen.inv(x: byref, sizeof(Mat))where Mat is a struct and x is the matrix we want to take the inverse of.
Previously, after running the
llvm-to-tesserapass and pulling out the sret argument, we would end up with something that looks like this:By loading the struct value from the pointer if it is byref and checking that the
tessera.callop does not capture the pointer, we can perform store-to-load forwarding with thepolygeist-mem2regpass and end up with:which our PDL pattern can match. This pull request updates the
polygeist-mem2regpass with additional type conversion logic and adds a canonicalization on tessera calls to allow this to happen.Any operands that were changed from pointers to loaded values are kept track of and new
llvm.allocainstances are created and pointer operands are reinserted when lowering back to LLVM.The
MemoryEffectOpInterfacehas also been implemented andpure_tessera_opsadded, so that a user can declare a function as side effect free. This will allow for the elimination of lingeringtessera.callops that remain after the optimization rewrite has been performed.