-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix Mem2Reg for store [assign] #35805
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
Conversation
@swift-ci test |
@@ -459,6 +459,7 @@ StackAllocationPromoter::promoteAllocationInBlock(SILBasicBlock *BB) { | |||
// RunningVal is the current value in the stack location. | |||
// We don't know the value of the alloca until we find the first store. | |||
SILValue RunningVal = SILValue(); | |||
SILValue LastRunningVal = SILValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a comment here explaining what LastRunningVal is and why it is different than RunningVal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also change this to be called PreviousRunningVal
because "last" might mean "the last in a list" whereas previous always means "the one before this one".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The information that I would want here is something with the following information (feel free to wordsmith).
LastRunningVal is the value that we saw stored in the stack
location /immediately before/ we updated the RunningVal at the
last store. The reason why we track this information on top of
the current running value is that if the last store was an assign
and turns out to be dead, we need to insert a destroy_value on
that value.
assert(RunningVal); | ||
// We have to create a destroy_value of the RunningVal when we see a store | ||
// [assign]. | ||
// A RunningVal will be be available if : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clean up this comment. My thought:
// We have to create a destroy_value of the RunningVal when we see a store
// [assign].
//
// A RunningVal will be available if:
//
// 1. store [assign] was in an entry block.
// 2. store [assign] is not the first store in a non-entry block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the small comment, this looks good to me. Thanks!
@@ -459,6 +459,7 @@ StackAllocationPromoter::promoteAllocationInBlock(SILBasicBlock *BB) { | |||
// RunningVal is the current value in the stack location. | |||
// We don't know the value of the alloca until we find the first store. | |||
SILValue RunningVal = SILValue(); | |||
SILValue LastRunningVal = SILValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also change this to be called PreviousRunningVal
because "last" might mean "the last in a list" whereas previous always means "the one before this one".
This PR simplifies the handling of store [assign] in Mem2Reg by always converting it to a store [init]. Also fixes an edge case where store [assign] in a non entry block was not the first store of an alloc_stack with uses in multiple blocks.
@gottesmm thanks for suggesting transforming store [assign] -> store [init]. store [assign] handling is much simpler now. |
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks beautiful to me! Really happy with where this patch ended up!
@swift-ci test windows platform |
This PR simplifies the handling of store [assign] in Mem2Reg by always converting it to a store [init].
Also fixes an edge case where store [assign] in a non entry block was not the first store of an alloc_stack with uses in multiple blocks.