Skip to content

Handle a special case of borrowed from instruction in CopyToBorrowOptimization #80733

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
merged 1 commit into from
Apr 12, 2025

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Apr 10, 2025

In CopyToBorrowOptimization, a copy_value with a guaranteed operand can be optimized away if all uses of copy_value can be replaced by the guaranteed operand and if the guaranteed operand's scope outlives the copy_value liveness.

For this, it uses lookThroughForwardingInstructions. Until now, for borrowed from instructions this utility returned its singleForwardedOperand which is a phi and not handled in isFullyContainedIn.

If the borrowed from instruction has a single enclosing value, we can return this instead enabling more optimizations if it turns out to be handled by isFullyContainedIn .

@meg-gupta meg-gupta requested a review from eeckstein as a code owner April 10, 2025 19:40
@meg-gupta meg-gupta force-pushed the updatectb branch 2 times, most recently from 51ca3c5 to f161a08 Compare April 10, 2025 20:21
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@@ -360,6 +360,14 @@ private extension Value {
}

var lookThroughForwardingInstructions: Value {
if let bfi = definingInstruction as? BorrowedFromInst,
let forwardedOp = bfi.singleForwardedOperand,
let phi = Phi(forwardedOp.value), !phi.isReborrow,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use bfi.borrowedPhi instead of getting it through the singleForwardedOperand

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta enabled auto-merge April 11, 2025 20:22
@meg-gupta meg-gupta merged commit 2c462ba into swiftlang:main Apr 12, 2025
4 of 5 checks passed
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