Skip to content
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

[SR-8621] SILGen creates destroys for tuple assignment at the wrong places #51136

Closed
eeckstein opened this issue Aug 23, 2018 · 2 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance SILGen Area → compiler: The SIL generation stage

Comments

@eeckstein
Copy link
Member

Previous ID SR-8621
Radar None
Original Reporter @eeckstein
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance, SILGen
Assignee @atrick
Priority Medium

md5: 6c4169f4697030be7a66f80eb6fc2a20

Issue Description:

Removing array pinning (#18922 exposes a performance problem caused by SILGen.
Consider this code where two array elements are assigned in the same statement.

func swap(_ x: inout [Int]) {
  return (x[0], x[1]) = (0, 1)
}

The generated SIL looks like this:

begin_access for x[0]
(&x[0], owner0) = nativeOwningMutableAddressor(for x[0])
assign to &x[0]
end_access for x[0]

begin_access for x[1]
(&x[1], owner1) = nativeOwningMutableAddressor(for x[1])
assign to &x[1]
end_access for x[1]

destroy owner1
destroy owner0

The accesses are not overlapping, but the lifetimes of the owners are. This triggers a unnecessary copy-on-write.
The destroys to be emitted at the same place as the end_accesses.
See the attached SIL file for a full version.

This problem is exposed by the Prims and PrimsSplit and probably also by the Array2D benchmarks.

@eeckstein
Copy link
Member Author

John, you said you could look at this.

@atrick
Copy link
Member

atrick commented Aug 25, 2018

Fix: #18969

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

2 participants