I suspect that if you, Daniel B., and I were to have an in person meeting this would take 5~10 minutes
For everyone to (in terms D.B. will appreciate) “converge to a fixed point” (:-)! of understanding. Meanwhile we
are stuck with limited email bandwidth, but a meet-up at the next llvm Bay Area social might be a good idea.
Whether GVN is an appropriate place for this opt is going to hinge on the precise details of the calling
Convention, which you are still being vague about. You are simultaneously saying
- the memcpy are necessary
- the memcpy can and should be opt away
But these two statements are mutually exclusive, so you need to be more precise about the CC.
Why is this important?, because even if Daniel B. can enhance GVN to “look through” the memcpys
And optimize the loads from the local-stack-copy into loads through the original pointer argument,
And optimize the stores into the local-stack-copy into stores through the original pointer argument,
There is still the issue of deleting the memcpys themselves, which is the actual performance problem.
But the rules of the C/C++ programming language aren’t typically going to allow these deletions,
For example if the original pointer argument is passed to another function, or the address of any
Or all of the local stack copy are passed to another function, or simply calling any function because
It could by the C/C++ rules modify the original data, requiring the memcpys to be preserved.
Also the same logical arguments apply to the loads and stores that Daniel B. thinks he can optimize
In GVN, it depends on where they occur relative to calls to other functions within this function.
The only thing that allows the deletion of the memcpys is intimate knowledge of the Julia-specific
Calling convention. Again similar conclusions apply to even the loads and stores.
And that, IMHO, is inappropriate to include in GVN, which is otherwise a purely C/C++ optimizer,
So a separate Julia calling convention pass is indicated.
PS, Don’t be intimidated by writing an IR-to-IR pass, I’ve already written one, they are easy.
Yours will be particularly easy (after verifying the transform is legal) as it is just a “replace-all-
Uses-of” which already exists, deleting the memcpys, and finally deleting the stack object.