Skip to content

[allocbox-to-stack] Fix an ossa bug in PromotedParamCloner. #34888

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

Merged

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Nov 30, 2020

For those who are unfamiliar, alloc-box-to-stack while generally not
interprocedural, will look one level into the callgraph to see if a
partial_apply that captures a box really needs to capture the box due to an
escape. If not, allocbox-to-stack clones the closure with the address inside the
box being passed instead of the box itself. This can then allow us to promote
the box from the heap to the stack.

What went wrong here is that in OSSA, this promoted param cloner drops
copy_value, destroy_value, and project_box on the given box. Both the copy_value
and destroy_value cases correctly looked through copy_values, but when porting,
the author forgot to handle project_box as well. This then caused the cloner to
assert since:

  1. The project_box in the original function had a copy_value operand.

  2. When we visited that copy_value, we saw it was for the box, so we dropped the
    copy_value and did not add it to the cloner's Value -> op(Value) map.

  3. Then when the cloner tried to create op(project_box), it tries to lookup the
    value associated with the copy_value that is the project_box's operand... but we
    don't have any such value due to (2). =><=.

The test change exercises this code path by adding a (project_box (copy_value))
to one of the allocbox to stack tests.

For those who are unfamiliar, alloc-box-to-stack while generally not
interprocedural, will look one level into the callgraph to see if a
partial_apply that captures a box really needs to capture the box due to an
escape. If not, allocbox-to-stack clones the closure with the address inside the
box being passed instead of the box itself. This can then allow us to promote
the box from the heap to the stack.

What went wrong here is that in OSSA, this promoted param cloner drops
copy_value, destroy_value, and project_box on the given box. Both the copy_value
and destroy_value cases correctly looked through copy_values, but when porting,
the author forgot to handle project_box as well. This then caused the cloner to
assert since:

1. The project_box in the original function had a copy_value operand.

2. When we visited that copy_value, we saw it was for the box, so we dropped the
copy_value and did not add it to the cloner's Value -> op(Value) map.

3. Then when the cloner tried to create op(project_box), it tries to lookup the
value associated with the copy_value that is the project_box's operand... but we
don't have any such value due to (2). =><=.

The test change exercises this code path by adding a (project_box (copy_value))
to one of the allocbox to stack tests.
@gottesmm gottesmm requested review from atrick and meg-gupta November 30, 2020 07:53
@gottesmm
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b0676be

@gottesmm
Copy link
Contributor Author

@swift-ci test linux platform

@gottesmm gottesmm merged commit 220757b into swiftlang:main Nov 30, 2020
@gottesmm gottesmm deleted the pr-a2129e0b4b1dab6c92b0aabf6225819c6404a4ad branch November 30, 2020 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants