Skip to content

[SILGen] Used move_value for more lexical values. #64789

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 16 commits into from
Dec 15, 2023

Conversation

nate-chandler
Copy link
Contributor

Use it rather than begin_borrow [lexical] and copy_value. Allows for more aggressive lifetime optimization.

@nate-chandler nate-chandler force-pushed the more-move-values branch 4 times, most recently from 0f71dd2 to 53ca82e Compare April 6, 2023 22:46
@nate-chandler nate-chandler force-pushed the more-move-values branch 2 times, most recently from b23cd42 to 17e2901 Compare April 12, 2023 22:05
@nate-chandler nate-chandler force-pushed the more-move-values branch 2 times, most recently from e87df13 to 88143d7 Compare April 25, 2023 04:08
@nate-chandler nate-chandler force-pushed the more-move-values branch 3 times, most recently from 6ce0374 to 2328b36 Compare July 7, 2023 01:39
@nate-chandler nate-chandler force-pushed the more-move-values branch 5 times, most recently from 8cdaf78 to 71107fb Compare December 5, 2023 16:55
Now that SILGen almost always represents a lexical lifetime with

    move_value [lexical]

the fact that the checker doesn't consider such lifetimes is exposed.
Fix it to look for such lifetimes.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please apple silicon benchmark

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler nate-chandler marked this pull request as ready for review December 15, 2023 03:53
@nate-chandler nate-chandler requested review from adrian-prantl and a team as code owners December 15, 2023 03:53
@nate-chandler nate-chandler requested review from atrick and meg-gupta and removed request for a team and adrian-prantl December 15, 2023 03:53
@nate-chandler
Copy link
Contributor Author

nate-chandler commented Dec 15, 2023

Let's lock in the representation change now. The forthcoming owned forwarding copy canonicalization will eliminate the few minor regressions this introduces:

### Performance (arm64): -O

**Regression**                          | **OLD**  | **NEW** | **DELTA** | **RATIO**
:---                                    | ---:     | ---:    | ---:   | ---:
KeyPathNestedStructs                    | 3.625    | 4.177   | +15.2% | **0.87x**
KeyPathsSmallStruct                     | 11.341   | 12.953  | +14.2% | **0.88x**
ObserverForwarderStruct                 | 181.154  | 202.045 | +11.5% | **0.90x (?)**
DictionaryOfAnyHashableStrings_insert   | 1860.353 | 2001.0  | +7.6%  | **0.93x (?)**
  | | | |
**Improvement**                         | **OLD**  | **NEW** | **DELTA** | **RATIO**
EqualSubstringSubstring                 | 21.833   | 18.88   | -13.5% | **1.16x (?)**
LessSubstringSubstringGenericComparable | 21.833   | 18.885  | -13.5% | **1.16x (?)**
EqualSubstringSubstringGenericEquatable | 21.825   | 18.884  | -13.5% | **1.16x (?)**
LessSubstringSubstring                  | 21.83    | 18.889  | -13.5% | **1.16x**
EqualSubstringString                    | 21.833   | 19.021  | -12.9% | **1.15x**
EqualStringSubstring                    | 21.829   | 19.019  | -12.9% | **1.15x**
StringFromLongWholeSubstring            | 2.172    | 2.018   | -7.1%  | **1.08x (?)**

### Code size: -O

**Improvement**  | **OLD** | **NEW** | **DELTA** | **RATIO**
:---             | ---:  | ---:  | ---:  | ---:
DictionarySwap.o | 15063 | 14691 | -2.5% | **1.03x**

### Performance (arm64): -Osize

**Regression**                          | **OLD** | **NEW** | **DELTA** | **RATIO**
:---                                    | ---:   | ---:   | ---:   | ---:
KeyPathsSmallStruct                     | 11.462 | 13.789 | +20.3% | **0.83x (?)**
KeyPathNestedStructs                    | 3.68   | 4.302  | +16.9% | **0.86x**
KeyPathReadPerformance                  | 20.882 | 22.667 | +8.5%  | **0.92x (?)**
  | | | |
**Improvement**                         | **OLD** | **NEW** | **DELTA** | **RATIO**
StringWithCString2                      | 0.001  | 0.0    | -50.0% | **2.00x (?)**
DataAccessBytesMedium                   | 46.786 | 34.303 | -26.7% | **1.36x (?)**
DataAccessBytesSmall                    | 49.909 | 37.432 | -25.0% | **1.33x**
EqualSubstringSubstring                 | 22.259 | 19.167 | -13.9% | **1.16x (?)**
LessSubstringSubstring                  | 22.27  | 19.205 | -13.8% | **1.16x**
EqualStringSubstring                    | 22.029 | 19.0   | -13.7% | **1.16x (?)**
EqualSubstringString                    | 22.0   | 19.027 | -13.5% | **1.16x**
EqualSubstringSubstringGenericEquatable | 22.167 | 19.185 | -13.5% | **1.16x (?)**
LessSubstringSubstringGenericComparable | 22.162 | 19.185 | -13.4% | **1.16x (?)**
StringFromLongWholeSubstring            | 2.333  | 2.176  | -6.7%  | **1.07x (?)**

### Code size: -Osize

**Regression**     | **OLD** | **NEW** | **DELTA** | **RATIO**
:---               | ---:  | ---:  | ---:  | ---:
StringComparison.o | 22928 | 23188 | +1.1% | **0.99x**
  | | | |
**Improvement**    | **OLD** | **NEW** | **DELTA** | **RATIO**
DictionarySwap.o   | 13043 | 12671 | -2.9% | **1.03x**

### Performance (arm64): -Onone

**Regression**                          | **OLD** | **NEW** | **DELTA** | **RATIO**
:---                                    | ---:   | ---:    | ---:   | ---:
ArrayAppendGenericStructs               | 698.75 | 897.692 | +28.5% | **0.78x (?)**
  | | | |
**Improvement**                         | **OLD** | **NEW** | **DELTA** | **RATIO**
LessSubstringSubstringGenericComparable | 24.789 | 21.364  | -13.8% | **1.16x (?)**
EqualSubstringSubstringGenericEquatable | 24.778 | 21.411  | -13.6% | **1.16x**
EqualStringSubstring                    | 26.185 | 22.775  | -13.0% | **1.15x**
EqualSubstringSubstring                 | 25.486 | 22.273  | -12.6% | **1.14x**
EqualSubstringString                    | 26.308 | 23.027  | -12.5% | **1.14x (?)**
LessSubstringSubstring                  | 25.593 | 22.458  | -12.2% | **1.14x (?)**

@nate-chandler nate-chandler merged commit 680c737 into swiftlang:main Dec 15, 2023
@nate-chandler nate-chandler deleted the more-move-values branch December 15, 2023 15:07
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Dec 16, 2023
Run OSLogMandatoryOptTest.swift only in configurations with release
stdlibs.

swiftlang#64789 introduced a simple but
widespread change to SIL.  It required updating a number of tests.  The
updates primarily involved replacing `begin_borrow` + `copy_value` with
`move_value` instructions.

In particular, OSLogMandatoryOptTest.swift had to be updated as well:
several new `move_value` instructions had to be FileCheck'd.  These
instructions all came from inlining code from the OSLogTestHelper
target, a target which is built in the same configuration as the stdlib.
In fact, they all came from inlining the
`_osLogTestHelper(_:assertion:)` function.

When building OSLogTestHelper for release, no optimization passes are
run on the function because it is marked `@_optimize(none)`.
`SemanticARCOpts` would have deleted these `move_value`s, but it doesn't
run on the function.

When building OSLogTestHelper for debug, however, `MandatoryARCOpts` (a
subset of `SemanticARCOpts`) _does_ run despite the function being
marked `@_optimize(none)`.  That's because it's part of the
`OnonePassPipeline` which is mandatory, meaning that every pass runs on
each function, regardless of it being annotated `@_optimize(none)`.

As a result the `move_value` instructions--which FileCheck lines were
added to match--are deleted before FileCheck runs.  So the new check
lines fail to match the deleted instructions.  Besides the absence of
these new `move_value` instructions, there is no difference between the
function in debug vs release.  In particular, removing the newly added
check lines allows the test to pass in a configuration with a debug
stdlib.

Rather than duplicate the test for debug configurations, just disable it
in them.

rdar://119744393
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Dec 21, 2023
Run OSLogMandatoryOptTest.swift only in configurations with release
stdlibs.

swiftlang#64789 introduced a simple but
widespread change to SIL.  It required updating a number of tests.  The
updates primarily involved replacing `begin_borrow` + `copy_value` with
`move_value` instructions.

In particular, OSLogMandatoryOptTest.swift had to be updated as well:
several new `move_value` instructions had to be FileCheck'd.  These
instructions all came from inlining code from the OSLogTestHelper
target, a target which is built in the same configuration as the stdlib.
In fact, they all came from inlining the
`_osLogTestHelper(_:assertion:)` function.

When building OSLogTestHelper for release, no optimization passes are
run on the function because it is marked `@_optimize(none)`.
`SemanticARCOpts` would have deleted these `move_value`s, but it doesn't
run on the function.

When building OSLogTestHelper for debug, however, `MandatoryARCOpts` (a
subset of `SemanticARCOpts`) _does_ run despite the function being
marked `@_optimize(none)`.  That's because it's part of the
`OnonePassPipeline` which is mandatory, meaning that every pass runs on
each function, regardless of it being annotated `@_optimize(none)`.

As a result the `move_value` instructions--which FileCheck lines were
added to match--are deleted before FileCheck runs.  So the new check
lines fail to match the deleted instructions.  Besides the absence of
these new `move_value` instructions, there is no difference between the
function in debug vs release.  In particular, removing the newly added
check lines allows the test to pass in a configuration with a debug
stdlib.

Rather than duplicate the test for debug configurations, just disable it
in them.

rdar://119744393
Catfish-Man pushed a commit to Catfish-Man/swift that referenced this pull request Jan 19, 2024
Run OSLogMandatoryOptTest.swift only in configurations with release
stdlibs.

swiftlang#64789 introduced a simple but
widespread change to SIL.  It required updating a number of tests.  The
updates primarily involved replacing `begin_borrow` + `copy_value` with
`move_value` instructions.

In particular, OSLogMandatoryOptTest.swift had to be updated as well:
several new `move_value` instructions had to be FileCheck'd.  These
instructions all came from inlining code from the OSLogTestHelper
target, a target which is built in the same configuration as the stdlib.
In fact, they all came from inlining the
`_osLogTestHelper(_:assertion:)` function.

When building OSLogTestHelper for release, no optimization passes are
run on the function because it is marked `@_optimize(none)`.
`SemanticARCOpts` would have deleted these `move_value`s, but it doesn't
run on the function.

When building OSLogTestHelper for debug, however, `MandatoryARCOpts` (a
subset of `SemanticARCOpts`) _does_ run despite the function being
marked `@_optimize(none)`.  That's because it's part of the
`OnonePassPipeline` which is mandatory, meaning that every pass runs on
each function, regardless of it being annotated `@_optimize(none)`.

As a result the `move_value` instructions--which FileCheck lines were
added to match--are deleted before FileCheck runs.  So the new check
lines fail to match the deleted instructions.  Besides the absence of
these new `move_value` instructions, there is no difference between the
function in debug vs release.  In particular, removing the newly added
check lines allows the test to pass in a configuration with a debug
stdlib.

Rather than duplicate the test for debug configurations, just disable it
in them.

rdar://119744393
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.

1 participant