-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL optimizer: a collection of optimizer changes to prepare for COW representation #32023
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
Conversation
Constant folds the uniqueness result of begin_cow_mutation instructions, if it can be proved that the buffer argument is uniquely referenced. For example: %buffer = end_cow_mutation %mutable_buffer // ... // %buffer does not escape here // ... (%is_unique, %mutable_buffer2) = begin_cow_mutation %buffer cond_br %is_unique, ... is replaced with %buffer = end_cow_mutation [keep_unique] %mutable_buffer // ... (%not_used, %mutable_buffer2) = begin_cow_mutation %buffer %true = integer_literal 1 cond_br %true, ... Note that the keep_unique flag is set on the end_cow_mutation because the code now relies on that the buffer is really uniquely referenced. The optimization can also handle def-use chains between end_cow_mutation and begin_cow_mutation which involve phi-arguments. An additional peephole optimization is performed: if the begin_cow_mutation is the only use of the end_cow_mutation, the whole pair of instructions is eliminated.
… owned-to-guarantee transformation. If a function is annotated with @_semantics("optimize.sil.specialize.owned2guarantee.never") its arguments will not be converted from owned to guaranteed.
… are only destroyed. If the only use of an upcast, unchecked_ref_cast or end_cow_mutation is a destroy/release, just destroy the operand and remove the cast/end_cow_mutation.
(end_cow_mutation (upcast X)) -> (end_cow_mutation X) (end_cow_mutation (unchecked_ref_cast X)) -> (end_cow_mutation X)
…mantics Used to "finalize" an array literal. It's not used, yet. So this is NFC. Also handle the "array.finalize_intrinsic" function in various array specific optimizations.
…e optimizations. Mostly this is about "looking through" a begin_cow_mutation or end_cow_mutation.
This is in preparation for COW support. More optimizer tests require an optimized non-assert stdlib build.
…nction. Support a version of Array._checkSubscript which has no wasNativeTypeChecked parameter.
The COWOpts optimization relies more on LICM. This additional run of the pass ensures that there is no phase ordering issue between LICM and COWOpts
@swift-ci test |
@swift-ci benchmark |
Performance: -OCode size: -OPerformance: -Osize
Code size: -OsizePerformance: -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Build failed |
Build failed |
@swift-ci test |
Build failed |
@swift-ci test linux |
This PR contains a set of independent (and mostly small) optimizer changes which are needed - or beneficial - for the switch to the COW representation in Array types.
For details see the commit list.
I'd like to explicitly mention one larger addition: A new optimization pass which constant folds the uniqueness result of begin_cow_mutation instructions, if it can be proved that the buffer argument is uniquely referenced.
For example:
is replaced with
If someone is interested, https://github.com/apple/swift/pull/31730/commits contains all changes for supporting COW representation in Array types.