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-11452] Swift Failing To Properly Optimize Inout Parameter Unless It's Manually Copied #53853

Open
swift-ci opened this issue Sep 11, 2019 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11452
Radar None
Original Reporter mdmorris (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance
Assignee None
Priority Medium

md5: cf5ea9a7793e87fea8c4b887c1b3440d

Issue Description:

Expected behavior: a function that directly uses an inout parameter is exactly equivalent to one that copies the inout variable into a local at the beginning then copies it back out at the end.

Actual behavior: the code that uses the inout parameter directly is an order of magnitude slower than the code that manually copies the inout variable.

Tested in Apple Swift 5.0

// Doesn't optimize.
func fx(_ allints: inout [Int],  _ j : inout Int) {
      for k in allints.indices {
        allints[k] = j
        j &+= 1
      }
 }

// Does optimize.
 func f(_ allints: inout [Int],  _ i : inout Int) {
      var j = i
      for k in allints.indices {
        allints[k] = j
        j &+= 1
      }
      i = j
 }
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

1 participant