-
-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in HeapToStack optimization pass #4341
Conversation
Opening this with no fix, just a regression test that we should see fail on Arm. |
Excellent our regression correctly fails in CI where expected. This means we can move forward with a fix once one is agreed upon. |
Interesting. We have x86 failing for this regression as well. I wasn't able to get it to fail locally on x86 but, there ya go! This failing on all platforms in CI is a much better result as that makes more sense. |
Fix bug in HeapToStack optimization
Our HeapToStack optimization pass was occassionally generating incorrect IR.
The following is the "annotated by Pony developers" IR after a HeapToStack
optimization pass run for the code from Issue #4340:
The calls such as:
are incorrect because,
tail
indicates that the function in question won'ttouch memory from any
alloca
. However, our HeapToStack pass was being toosimplistic in its analysis and not setting all calls to be "tail false" that
touches memory that comes from an alloca.
In the above example, you can see that
@Leaf_ref_get_value_Z
usestales a pointer to the
%_leaf_left
alloca but because it is marked as "tail",later optimizations like dead store elimination will see:
as dead code and remove the initialization of the object in question. From
there, we get incorrect code.
The problem arose because the HeapToStack pass wasn't doing any sort of alias
analysis when looking for functions within a function where we converted a
heap allocation to a stack one. This would cause it to incorrectly believe that
some functions that where marked as "tail" didn't need to be changed to
"not tail".
This commit, instead of adding a clever alias analysis step instead sets all
call
s within a function to "not tail" if we add analloca
to as part of aheap to stack optimization.
Fixes #4340