Skip to content

[SIL] Make owned function arguments lexical. #41228

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

nate-chandler
Copy link
Contributor

The destroys of owned arguments must not be hoisted over deinit barriers to respect the semantics of lexical lifetimes. Here, owned SILValues which are SILFunctionArguments are made to be lexical. Code which hoists destroys will check this field and not hoist destroys.

@nate-chandler nate-chandler marked this pull request as draft February 5, 2022 18:45
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch 5 times, most recently from d0dac47 to 97df9a3 Compare February 7, 2022 20:20
@nate-chandler nate-chandler marked this pull request as ready for review February 7, 2022 20:20
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch from 97df9a3 to 959aeb6 Compare February 7, 2022 20:28
@nate-chandler nate-chandler requested a review from atrick February 7, 2022 20:32
@atrick
Copy link
Contributor

atrick commented Feb 7, 2022

As discussed, we should fix ownership RAUW before doing this so most of the CSE/SILCombine optimizations will still work on owned arguments... although adjusting the tests to handle local variables instead was very clever and we may want to keep some of those new tests too

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch from 959aeb6 to f007b8b Compare February 8, 2022 03:35
@swiftlang swiftlang deleted a comment from swift-ci Feb 8, 2022
@swiftlang swiftlang deleted a comment from swift-ci Feb 8, 2022
@swiftlang swiftlang deleted a comment from swift-ci Feb 8, 2022
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch 2 times, most recently from 3827ab7 to e8ff4ae Compare February 8, 2022 03:59
@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2022

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
Set.subtracting.Box.Empty 31 50 +61.3% 0.62x
Set.subtracting.Int.Empty 37 55 +48.6% 0.67x
Set.subtracting.Seq.Box.Empty 273 359 +31.5% 0.76x
Set.subtracting.Seq.Int.Empty 239 282 +18.0% 0.85x
NSStringConversion.MutableCopy.Rebridge.UTF8 738 843 +14.2% 0.88x (?)
DictionaryBridgeToObjC_Bridge 15 17 +13.3% 0.88x (?)
NSStringConversion.MutableCopy.UTF8 974 1084 +11.3% 0.90x (?)
 
Improvement OLD NEW DELTA RATIO
AnyHashableWithAClass 127500 96500 -24.3% 1.32x (?)
StringFromLongWholeSubstring 5 4 -20.0% 1.25x
Set.subtracting.Seq.Empty.Int 221 194 -12.2% 1.14x (?)
Set.subtracting.Empty.Int 44 40 -9.1% 1.10x (?)
String.replaceSubrange.RepChar.Small 515 469 -8.9% 1.10x (?)
EqualSubstringSubstring 42 39 -7.1% 1.08x (?)
EqualStringSubstring 42 39 -7.1% 1.08x (?)
EqualSubstringString 42 39 -7.1% 1.08x (?)
EqualSubstringSubstringGenericEquatable 43 40 -7.0% 1.07x (?)

Code size: -O

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2817 2881 +2.3% 0.98x
FlattenList.o 3841 3921 +2.1% 0.98x
RangeAssignment.o 3275 3331 +1.7% 0.98x
RomanNumbers.o 6812 6924 +1.6% 0.98x
BucketSort.o 8551 8679 +1.5% 0.99x

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
Set.subtracting.Box.Empty 30 50 +66.7% 0.60x
Set.subtracting.Int.Empty 39 56 +43.6% 0.70x
Combos 417 488 +17.0% 0.85x
DictionaryBridgeToObjC_Bridge 15 17 +13.3% 0.88x (?)
ArrayAppendLatin1Substring 28512 30924 +8.5% 0.92x (?)
ArrayAppendUTF16Substring 27972 30312 +8.4% 0.92x (?)
ArrayAppendAsciiSubstring 27972 30276 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
AnyHashableWithAClass 124000 96500 -22.2% 1.28x (?)
Set.isSubset.Seq.Int.Empty 231 195 -15.6% 1.18x
Set.isStrictSuperset.Seq.Empty.Int 230 198 -13.9% 1.16x
Set.isStrictSubset.Seq.Int.Empty 222 198 -10.8% 1.12x
DictionaryKeysContainsCocoa 25 23 -8.0% 1.09x (?)
String.replaceSubrange.RepChar.Small 514 476 -7.4% 1.08x (?)
LessSubstringSubstring 43 40 -7.0% 1.07x (?)
EqualSubstringSubstring 43 40 -7.0% 1.07x (?)
EqualStringSubstring 43 40 -7.0% 1.07x (?)
EqualSubstringSubstringGenericEquatable 43 40 -7.0% 1.07x (?)

Code size: -Osize

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2797 2865 +2.4% 0.98x
RangeAssignment.o 3173 3241 +2.1% 0.98x
FlattenList.o 3744 3821 +2.1% 0.98x
ArraySetElement.o 1267 1287 +1.6% 0.98x
RomanNumbers.o 5149 5230 +1.6% 0.98x
COWArrayGuaranteedParameterOverhead.o 1327 1347 +1.5% 0.99x
Sim2DArray.o 1332 1352 +1.5% 0.99x
BucketSort.o 8385 8497 +1.3% 0.99x
Join.o 1580 1600 +1.3% 0.99x
ReversedCollections.o 7436 7521 +1.1% 0.99x
StringRemoveDupes.o 3720 3760 +1.1% 0.99x
Memset.o 1901 1921 +1.1% 0.99x
RangeOverlaps.o 6362 6428 +1.0% 0.99x
Array2D.o 2726 2754 +1.0% 0.99x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 4633 4269 -7.9% 1.09x

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
RecursiveOwnedParameter 7430 8613 +15.9% 0.86x (?)
Dictionary2 1695 1900 +12.1% 0.89x (?)
Set.subtracting.Box.Empty 155 170 +9.7% 0.91x (?)
Set.subtracting.Int.Empty 166 182 +9.6% 0.91x (?)
NSStringConversion.Rebridge 501 540 +7.8% 0.93x (?)
StringBuilderLong 1940 2090 +7.7% 0.93x (?)
Hanoi 12950 13950 +7.7% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
AnyHashableWithAClass 165500 136000 -17.8% 1.22x (?)
ProtocolDispatch2 9924 9083 -8.5% 1.09x (?)
DictionaryKeysContainsNative 48 44 -8.3% 1.09x (?)
CharIndexing_korean_unicodeScalars_Backwards 187120 173480 -7.3% 1.08x (?)
CharIndexing_japanese_unicodeScalars_Backwards 223560 207400 -7.2% 1.08x (?)
CharIndexing_punctuated_unicodeScalars_Backwards 41200 38280 -7.1% 1.08x (?)
Set.isDisjoint.Seq.Int100 2435 2264 -7.0% 1.08x (?)

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch from e8ff4ae to 99f9f57 Compare February 8, 2022 20:31
@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2022

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 3423 5746 +67.9% 0.60x (?)
Set.subtracting.Box.Empty 27 45 +66.7% 0.60x
FlattenListLoop 1479 2197 +48.5% 0.67x (?)
Set.subtracting.Int.Empty 33 49 +48.5% 0.67x
Set.subtracting.Seq.Box.Empty 245 326 +33.1% 0.75x (?)
ObjectiveCBridgeStubFromNSDateRef 3770 4520 +19.9% 0.83x (?)
Set.subtracting.Seq.Int.Empty 213 253 +18.8% 0.84x (?)
Combos 366 409 +11.7% 0.89x (?)
MapReduceShortString 12 13 +8.3% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
AnyHashableWithAClass 114000 87000 -23.7% 1.31x (?)
Set.subtracting.Seq.Empty.Int 197 174 -11.7% 1.13x (?)
String.replaceSubrange.RepChar.Small 463 422 -8.9% 1.10x (?)
DictionaryBridgeToObjC_Access 859 786 -8.5% 1.09x (?)
LessSubstringSubstring 38 35 -7.9% 1.09x (?)
EqualSubstringSubstring 38 35 -7.9% 1.09x (?)
EqualStringSubstring 38 35 -7.9% 1.09x (?)
EqualSubstringString 38 35 -7.9% 1.09x (?)
Set.subtracting.Empty.Int 39 36 -7.7% 1.08x (?)

Code size: -O

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2817 2881 +2.3% 0.98x
FlattenList.o 3841 3921 +2.1% 0.98x
RangeAssignment.o 3275 3331 +1.7% 0.98x
RomanNumbers.o 6812 6924 +1.6% 0.98x
BucketSort.o 8551 8679 +1.5% 0.99x

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
Set.subtracting.Box.Empty 27 45 +66.7% 0.60x
Set.subtracting.Int.Empty 35 50 +42.9% 0.70x
Combos 377 437 +15.9% 0.86x (?)
ArrayAppendLatin1Substring 25560 27756 +8.6% 0.92x (?)
ArrayAppendUTF16Substring 25092 27180 +8.3% 0.92x (?)
ArrayAppendAsciiSubstring 25092 27144 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
AnyHashableWithAClass 111500 86500 -22.4% 1.29x (?)
Set.isSubset.Seq.Int.Empty 207 175 -15.5% 1.18x (?)
Set.isStrictSuperset.Seq.Empty.Int 205 178 -13.2% 1.15x
Set.isStrictSubset.Seq.Int.Empty 200 178 -11.0% 1.12x (?)
String.replaceSubrange.RepChar.Small 464 423 -8.8% 1.10x (?)
Breadcrumbs.MutatedUTF16ToIdx.Mixed 258 238 -7.8% 1.08x (?)
ObjectiveCBridgeToNSDictionary 17250 16050 -7.0% 1.07x (?)
InsertCharacterEndIndex 159 148 -6.9% 1.07x (?)

Code size: -Osize

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2797 2865 +2.4% 0.98x
RangeAssignment.o 3173 3241 +2.1% 0.98x
FlattenList.o 3744 3821 +2.1% 0.98x
ArraySetElement.o 1267 1287 +1.6% 0.98x
RomanNumbers.o 5149 5230 +1.6% 0.98x
COWArrayGuaranteedParameterOverhead.o 1327 1347 +1.5% 0.99x
Sim2DArray.o 1332 1352 +1.5% 0.99x
BucketSort.o 8385 8497 +1.3% 0.99x
Join.o 1580 1600 +1.3% 0.99x
ReversedCollections.o 7436 7521 +1.1% 0.99x
StringRemoveDupes.o 3720 3760 +1.1% 0.99x
Memset.o 1901 1921 +1.1% 0.99x
RangeOverlaps.o 6362 6428 +1.0% 0.99x
Array2D.o 2726 2754 +1.0% 0.99x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 4633 4269 -7.9% 1.09x

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
RecursiveOwnedParameter 6677 7729 +15.8% 0.86x (?)
Set.subtracting.Box.Empty 139 153 +10.1% 0.91x (?)
Breadcrumbs.MutatedIdxToUTF16.ASCII 10 11 +10.0% 0.91x (?)
Set.subtracting.Int.Empty 149 163 +9.4% 0.91x (?)
UTF8Decode_InitFromCustom_contiguous 184 199 +8.2% 0.92x (?)
Hanoi 11630 12510 +7.6% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
FloatingPointPrinting_Double_description_small 26200 21100 -19.5% 1.24x (?)
AnyHashableWithAClass 147000 122500 -16.7% 1.20x (?)
DictionaryBridgeToObjC_Access 1192 1019 -14.5% 1.17x (?)
StringBuilderWithLongSubstring 4590 4030 -12.2% 1.14x (?)
DataAppendDataMediumToMedium 5080 4560 -10.2% 1.11x (?)
ProtocolDispatch2 8902 8146 -8.5% 1.09x (?)
StackPromo 54200 49800 -8.1% 1.09x (?)
CharIndexing_russian_unicodeScalars_Backwards 141240 129800 -8.1% 1.09x (?)
CharIndexing_chinese_unicodeScalars_Backwards 126480 117600 -7.0% 1.08x (?)
CharIndexing_japanese_unicodeScalars_Backwards 200600 187040 -6.8% 1.07x (?)
CharIndexing_punctuatedJapanese_unicodeScalars_Backwards 30960 28880 -6.7% 1.07x (?)

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch 2 times, most recently from 11b4548 to 6147b89 Compare February 9, 2022 02:27
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@eeckstein
Copy link
Contributor

@nate-chandler Can you please document that in SIL.rst? E.g. under "Function Types" and/or "Ownership SSA".
It would be nice to have a paragraph explaining lexical lifetimes in general (e.g. under "Ownership SSA").

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2022

Build failed
Swift Test OS X Platform
Git Sha - 6147b899b2116b5a67c57d9fed775d57e53c8aa4

@nate-chandler
Copy link
Contributor Author

@eeckstein Absolutely! Sorry for leaving that out.

@nate-chandler
Copy link
Contributor Author

Added some documentation to SIL.rst.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

The documentation in SIL.rst looks very good!

Do you know the cause of the benchmark regressions?

@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch from 2fbfbe6 to cade25f Compare February 10, 2022 20:04
@nate-chandler nate-chandler requested a review from atrick February 10, 2022 20:19
UpdateSSA was being used to rewrite destroys, not for its intended
purpose.  Besides being a misuse, it's also wasteful.  Instead, just
rewrite the destroys that it would have updated.
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch 2 times, most recently from b95785f to 6a99b7e Compare February 10, 2022 23:27
RAUWing a lexical value with a non-lexical value is illegal because it
would result in the value's lifetime being shortened without regard to
deinit barriers.  RAUWing _with_ a lexical value is LEGAL so long as
doing so doesn't extend its lifetime.
The destroys of owned arguments must not be hoisted over deinit barriers
to respect the semantics of lexical lifetimes.  Here, owned SILValues
which are SILFunctionArguments are made to be lexical.  Code which
hoists destroys will check this field and not hoist destroys.

Allowed more RAUWing to be done with lexical values; specifically,
allowed the replacement of a non-lexical value with a lexical value if
the replacing value's lifetime wouldn't be extended as a result.

Updated tests to get owned values via applies rather than having them
passed as arguments.
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/owned_function_args_are_lexical branch from 6a99b7e to 2da6ac1 Compare February 11, 2022 00:28
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
Set.subtracting.Box.Empty 23 37 +60.9% 0.62x
Set.subtracting.Int.Empty 28 43 +53.6% 0.65x
Set.subtracting.Seq.Box.Empty 210 274 +30.5% 0.77x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 186 222 +19.4% 0.84x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 184 219 +19.0% 0.84x
Set.subtracting.Seq.Int.Empty 184 212 +15.2% 0.87x
NormalizedIterator_nonBMPSlowestPrenormal 370 410 +10.8% 0.90x
DictionaryBridgeToObjC_Bridge 11 12 +9.1% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 29 22 -24.1% 1.32x
EqualSubstringSubstring 29 22 -24.1% 1.32x
EqualStringSubstring 29 22 -24.1% 1.32x
EqualSubstringString 29 22 -24.1% 1.32x
EqualSubstringSubstringGenericEquatable 30 23 -23.3% 1.30x
LessSubstringSubstringGenericComparable 29 23 -20.7% 1.26x
ConvertFloatingPoint.MockFloat64Exactly2 16 14 -12.5% 1.14x
FlattenListLoop 1582 1385 -12.5% 1.14x (?)
StringComparison_longSharedPrefix 333 296 -11.1% 1.12x (?)
SortStringsUnicode 2215 2030 -8.4% 1.09x
BridgeString.find.native.longNonASCII 434 402 -7.4% 1.08x (?)
ObjectiveCBridgeStringHash 95 88 -7.4% 1.08x (?)
Set.isStrictSubset.Seq.Box0 286 266 -7.0% 1.08x
Diffing.Similar 376 350 -6.9% 1.07x (?)

Code size: -O

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2817 2881 +2.3% 0.98x
FlattenList.o 3841 3921 +2.1% 0.98x
RangeAssignment.o 3275 3331 +1.7% 0.98x
RomanNumbers.o 6812 6924 +1.6% 0.98x
BucketSort.o 8551 8679 +1.5% 0.99x

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
Set.subtracting.Box.Empty 23 38 +65.2% 0.61x
Set.subtracting.Int.Empty 28 42 +50.0% 0.67x
DropFirstAnyCollection 84 124 +47.6% 0.68x (?)
PrefixAnySeqCRangeIterLazy 94 134 +42.6% 0.70x
PrefixAnySeqCntRangeLazy 94 134 +42.6% 0.70x
DropFirstAnySeqCRangeIterLazy 112 143 +27.7% 0.78x (?)
DropFirstAnySeqCntRangeLazy 112 143 +27.7% 0.78x (?)
PrefixWhileAnyCollection 142 178 +25.4% 0.80x
ArrayAppendRepeatCol 420 500 +19.0% 0.84x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 187 222 +18.7% 0.84x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 183 217 +18.6% 0.84x
DropWhileAnyCollectionLazy 148 174 +17.6% 0.85x (?)
DropLastAnyCollection 39 45 +15.4% 0.87x (?)
PrefixAnyCollection 111 127 +14.4% 0.87x
NormalizedIterator_fastPrenormal 430 480 +11.6% 0.90x (?)
FilterEvenUsingReduce 650 720 +10.8% 0.90x (?)
DropWhileAnySeqCntRangeLazy 142 157 +10.6% 0.90x (?)
DropWhileAnySeqCRangeIterLazy 142 156 +9.9% 0.91x (?)
DropWhileAnyCollection 122 134 +9.8% 0.91x (?)
NormalizedIterator_latin1 154 168 +9.1% 0.92x (?)
DictionaryBridgeToObjC_Bridge 11 12 +9.1% 0.92x (?)
OpenClose 58 63 +8.6% 0.92x (?)
DataReplaceMedium 2600 2800 +7.7% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
FlattenListLoop 1449 1039 -28.3% 1.39x (?)
LessSubstringSubstring 30 22 -26.7% 1.36x
EqualSubstringSubstringGenericEquatable 30 22 -26.7% 1.36x
EqualSubstringString 30 22 -26.7% 1.36x
LessSubstringSubstringGenericComparable 29 22 -24.1% 1.32x
EqualStringSubstring 30 23 -23.3% 1.30x
RecursiveOwnedParameter 284 221 -22.2% 1.29x (?)
EqualSubstringSubstring 29 23 -20.7% 1.26x
SequenceAlgosArray 2140 1710 -20.1% 1.25x
UTF8Decode_InitFromCustom_noncontiguous_ascii 688 569 -17.3% 1.21x (?)
ArrayAppendUTF16Substring 22032 18792 -14.7% 1.17x (?)
ArrayAppendLatin1Substring 22464 19188 -14.6% 1.17x (?)
ArrayAppendAsciiSubstring 22032 18828 -14.5% 1.17x (?)
UTF8Decode_InitFromCustom_noncontiguous_ascii_as_ascii 782 670 -14.3% 1.17x
StringComparison_longSharedPrefix 333 295 -11.4% 1.13x (?)
UTF8Decode_InitFromCustom_noncontiguous 283 253 -10.6% 1.12x (?)
ObjectiveCBridgeStringHash 95 87 -8.4% 1.09x
SortStringsUnicode 2210 2035 -7.9% 1.09x (?)
BridgeString.find.native.longNonASCII 433 402 -7.2% 1.08x (?)

Code size: -Osize

Regression OLD NEW DELTA RATIO
MonteCarloE.o 2797 2865 +2.4% 0.98x
RangeAssignment.o 3173 3241 +2.1% 0.98x
FlattenList.o 3744 3821 +2.1% 0.98x
ArraySetElement.o 1267 1287 +1.6% 0.98x
RomanNumbers.o 5149 5230 +1.6% 0.98x
COWArrayGuaranteedParameterOverhead.o 1327 1347 +1.5% 0.99x
Sim2DArray.o 1332 1352 +1.5% 0.99x
BucketSort.o 8385 8497 +1.3% 0.99x
Join.o 1580 1600 +1.3% 0.99x
ReversedCollections.o 7436 7521 +1.1% 0.99x
StringRemoveDupes.o 3720 3760 +1.1% 0.99x
Memset.o 1901 1921 +1.1% 0.99x
RangeOverlaps.o 6362 6428 +1.0% 0.99x
Array2D.o 2726 2754 +1.0% 0.99x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 4633 4269 -7.9% 1.09x

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
Breadcrumbs.MutatedIdxToUTF16.Mixed 195 231 +18.5% 0.84x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 186 220 +18.3% 0.85x
Set.subtracting.Box.Empty 99 112 +13.1% 0.88x (?)
COWArrayGuaranteedParameterOverhead 5350 6050 +13.1% 0.88x (?)
Set.subtracting.Int.Empty 110 122 +10.9% 0.90x (?)
Set.subtracting.Seq.Int.Empty 571 629 +10.2% 0.91x (?)
ArrayValueProp 3027 3283 +8.5% 0.92x (?)
CharIteration_tweet_unicodeScalars 94480 102360 +8.3% 0.92x (?)
Set.subtracting.Seq.Box.Empty 592 641 +8.3% 0.92x (?)
ArrayAppendGenericStructs 610 660 +8.2% 0.92x (?)
ArrayLiteral2 1746 1889 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
EqualSubstringSubstring 62 53 -14.5% 1.17x (?)
EqualSubstringString 62 53 -14.5% 1.17x (?)
LessSubstringSubstringGenericComparable 60 52 -13.3% 1.15x
LessSubstringSubstring 62 54 -12.9% 1.15x
EqualStringSubstring 62 54 -12.9% 1.15x (?)
EqualSubstringSubstringGenericEquatable 60 53 -11.7% 1.13x
ArrayOfPOD 735 669 -9.0% 1.10x (?)
DataReplaceLargeBuffer 12 11 -8.3% 1.09x (?)
String.replaceSubrange.ArrChar.Small 51 47 -7.8% 1.09x (?)
ObjectiveCBridgeStringHash 95 88 -7.4% 1.08x (?)
BridgeString.find.native.longNonASCII 433 402 -7.2% 1.08x (?)

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

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.

Great!

@nate-chandler
Copy link
Contributor Author

The root cause of the Set.subtracting.Box.Empty benchmark regression is that we don't yet have the lexical destroy hoisting utility to run during copy propagation on owned lexical values (move_value [lexical] and @owned arguments). That results in extra ARC traffic in $sSh11subtractingyShyxGABF.

In detail, the problem is that CanonicalizeOSSALifetime, which doesn't respect lexical lifetimes, no longer hoists the destroys of %1 of

sil [serialized] [ossa] @$sSh11subtractingyShyxGABF : $@convention(method) <Element where Element : Hashable> (@guaranteed Set<Element>, @owned Set<Element>) -> @owned Set<Element> {
bb0(%0 : @guaranteed $Set<Element>, %1 : @owned $Set<Element>):

to just after its last uses. Specifically, the destroy is not hoisted up from the end of the function to just after the apply of $sSh12_subtractingyShyxGqd__7ElementQyd__RszSTRd__lF.

Before this change, SILCombine saw

  %102 = copy_value %1 : $Set<Element>
  %105 = function_ref @$sSh12_subtractingyShyxGqd__7ElementQyd__RszSTRd__lF : $@convention(method) <τ_0_0 where τ_0_0 : Hashable><τ_1_0 where τ_0_0 == τ_1_0.Element, τ_1_0 : Sequence> (@in_guaranteed τ_1_0, @owned Set<τ_0_0>) -> @owned Set<τ_0_0>
  %106 = apply %105<Element, Set<Element>>(%103, %102) : $@convention(method) <τ_0_0 where τ_0_0 : Hashable><τ_1_0 where τ_0_0 == τ_1_0.Element, τ_1_0 : Sequence> (@in_guaranteed τ_1_0, @owned Set<τ_0_0>) -> @owned Set<τ_0_0>
  destroy_value %1 : $Set<Element>

and was able to rewrite it as

  %85 = function_ref @$sSh12_subtractingyShyxGqd__7ElementQyd__RszSTRd__lF : $@convention(method) <τ_0_0 where τ_0_0 : Hashable><τ_1_0 where τ_0_0 == τ_1_0.Element, τ_1_0 : Sequence> (@in_guaranteed τ_1_0, @owned Set<τ_0_0>) -> @owned Set<τ_0_0>
  %86 = apply %85<Element, Set<Element>>(%83, %1) : $@convention(method) <τ_0_0 where τ_0_0 : Hashable><τ_1_0 where τ_0_0 == τ_1_0.Element, τ_1_0 : Sequence> (@in_guaranteed τ_1_0, @owned Set<τ_0_0>) -> @owned Set<τ_0_0>

Now, though, the destroy_value isn't in the same block, so the extra copy can't be eliminated.

@nate-chandler nate-chandler merged commit 63161e6 into swiftlang:main Feb 12, 2022
@nate-chandler nate-chandler deleted the lexical_lifetimes/owned_function_args_are_lexical branch February 12, 2022 02:12
@eeckstein
Copy link
Contributor

Is this something which is easy to fix?

@nate-chandler
Copy link
Contributor Author

nate-chandler commented Feb 14, 2022

It should be reasonably straightforward. ShrinkBorrowScope has been restructured ( #41358 ) to make it easy to create the new LexicalDestroyHoisting from it. Filed rdar://88903962 .

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.

4 participants