Skip to content

Optimizer: Improve performance of large InlineArrays at Onone #81706

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 4 commits into from
May 26, 2025

Conversation

eeckstein
Copy link
Contributor

We need to avoid copying large InlineArrays at Onone, because even for Onone the performance suffers too much if such copies are not eliminated.

The solution to this to run the TempRValueElimination at Onone.
In this PR I added a new MandatoryTempRValueElimination pass, which works as the original TempRValueElimination, except that it does not remove any alloc_stack instruction which are associated with source variables.

In addition it's required to simplify mark_dependence instructions at Onone. I re-implement the SILCombine peephole as a Swift instruction simplification and let run this simplification also in the OnoneSimplification pass.

rdar://151629149

@eeckstein
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@nate-chandler nate-chandler left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

LGTM but there should be a comment at the top of SimplifyMarkDependence that it cannot run before dependency diagnostics. Dependencies on trivial values are meaningful for diagnostics.

eeckstein added 3 commits May 23, 2025 18:53
* Move the mutating APIs into Context.swift, because SIL can only be mutated through a MutatingContext
* move the `baseOperand` and `base` properties from the instruction classes to the `MarkDependenceInstruction` protocol
* add `valueOrAddressOperand` and `valueOrAddress` in the `MarkDependenceInstruction` protocol
* re-implement the SILCombine peephole as a Swift instruction simplification
* run this simplification also in the OnoneSimplification pass
This is a workaround for a bug in the move-only checker: rdar://151841926.
The move-only checker sometimes inserts destroy_addr within read-only static access scopes.
Therefore don't consider static access scopes as immutable scopes.
Introduce a new pass MandatoryTempRValueElimination, which works as the original TempRValueElimination, except that it does not remove any alloc_stack instruction which are associated with source variables.

Running this pass at Onone helps to reduce copies of large structs, e.g. InlineArrays or structs containing InlineArrays.
Copying large structs can be a performance problem, even at Onone.

rdar://151629149
@eeckstein eeckstein force-pushed the mandatory-temprvalue-elimination branch from efc01b8 to 198d4ab Compare May 23, 2025 16:57
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci clean apple silicon benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci test macos

@eeckstein eeckstein merged commit ddca2ba into swiftlang:main May 26, 2025
7 checks passed
@eeckstein eeckstein deleted the mandatory-temprvalue-elimination branch May 26, 2025 05:56
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.

3 participants