Skip to content

Conversation

@eeckstein
Copy link
Contributor

Why include an optimization improvement and a correctness fix in one PR?
Unfortunately the correctness fix makes TempRValueElimination more conservative and this can cause some performance regressions. To compensate for this, I improved the handling of apply instructions in MemBehavior.

This change fixes a miscompile in case the source of the optimized copy_addr is modified in a called function via an invisible alias. This can happen with class properties or global variables.

This fix removes the special handling of function parameters, which was just wrong.
Instead it simply uses the alias analysis API to check for modifications of the source object.

The changes to improve MemBehavior for apply instructions include:

  1. Do a better alias analysis for "function-local" objects, like alloc_stack and inout parameters
  2. Fully support try_apply and begin/end/abort_apply

For details, see the commit messages.

rdar://problem/69605657

The InspectionMode was never set to anything else than "IgnoreRetains"
1. Do a better alias analysis for "function-local" objects, like alloc_stack and inout parameters
2. Fully support try_apply and begin/end/abort_apply

So far we fully relied on escape analysis. But escape analysis has some shortcomings with SIL address-types.
Therefore, handle two common cases, alloc_stack and inout parameters, with alias analysis.
This gives better results.
The biggest change here is to do a quick check if the address escapes via an address_to_pointer instructions.
…rce in a called functions correctly.

This fixes a miscompile in case the source of the optimized copy_addr is modified in a called function with to a not visible alias.
This can happen with class properties or global variables.

This fix removes the special handling of function parameters, which was just wrong.
Instead it simply uses the alias analysis API to check for modifications of the source object.

The fix makes TempRValueElimination more conservative and this can cause some performance regressions, but this is unavoidable.

rdar://problem/69605657
…ine.

This can compensate the performance regression of the more conservative handling of function calls in TempRValueOpt (see previous commit).
The pass runs after the inlining passes and can therefore optimize in some cases where it's not possible before inlining.
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein eeckstein requested review from atrick and meg-gupta October 9, 2020 19:21
@swift-ci
Copy link
Contributor

swift-ci commented Oct 9, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 2696 18495 +586.0% 0.15x
NopDeinit 9900 29100 +193.9% 0.34x
RandomShuffleLCG2 368 544 +47.8% 0.68x
MapReduceString 35 49 +40.0% 0.71x
LessSubstringSubstring 22 30 +36.4% 0.73x
EqualSubstringSubstring 22 30 +36.4% 0.73x
EqualSubstringSubstringGenericEquatable 22 30 +36.4% 0.73x
EqualSubstringString 22 30 +36.4% 0.73x
LessSubstringSubstringGenericComparable 22 30 +36.4% 0.73x
EqualStringSubstring 23 31 +34.8% 0.74x
AngryPhonebook.ASCII2 109 145 +33.0% 0.75x
Dictionary4OfObjects 187 235 +25.7% 0.80x
UTF8Decode_InitDecoding 139 170 +22.3% 0.82x
UTF8Decode_InitFromCustom_contiguous 141 170 +20.6% 0.83x
DictionarySwapAtOfObjects 5060 5808 +14.8% 0.87x (?)
StringComparison_longSharedPrefix 327 364 +11.3% 0.90x (?)
DictionarySwapOfObjects 5880 6520 +10.9% 0.90x (?)
UTF8Decode_InitFromCustom_noncontiguous 296 326 +10.1% 0.91x (?)
MapReduceAnyCollectionShort 1360 1480 +8.8% 0.92x (?)
SortStringsUnicode 2110 2290 +8.5% 0.92x (?)
MapReduceNSDecimalNumber 201 218 +8.5% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ArrayAppendLazyMap 1570 680 -56.7% 2.31x
Data.append.Sequence.64kB.Count.RE.I 44 21 -52.3% 2.10x
Data.append.Sequence.64kB.Count.RE 44 21 -52.3% 2.10x
FindString.Loop1.Substring 656 347 -47.1% 1.89x
ParseInt.UIntSmall.Binary 823 508 -38.3% 1.62x
ObjectiveCBridgeStubDataAppend 3140 1940 -38.2% 1.62x
FindString.Rec3.Substring 219 144 -34.2% 1.52x
Data.append.Sequence.809B.Count.RE.I 91 60 -34.1% 1.52x
FindString.Rec3.String 186 125 -32.8% 1.49x
DataAppendSequence 9500 6500 -31.6% 1.46x
Data.append.Sequence.809B.Count.RE 94 65 -30.9% 1.45x
Data.init.Sequence.64kB.Count0.I 197 140 -28.9% 1.41x
Data.init.Sequence.64kB.Count0.RE 203 145 -28.6% 1.40x
Data.init.Sequence.64kB.Count0 195 140 -28.2% 1.39x
Data.init.Sequence.2047B.Count0.I 364 263 -27.7% 1.38x
Data.init.Sequence.2049B.Count0.I 367 268 -27.0% 1.37x
Data.append.Sequence.64kB.Count0 189 141 -25.4% 1.34x
Data.append.Sequence.64kB.Count0.I 189 141 -25.4% 1.34x
ArrayAppendRepeatCol 670 500 -25.4% 1.34x
Data.init.Sequence.64kB.Count0.RE.I 203 152 -25.1% 1.34x
Dictionary3 182 139 -23.6% 1.31x
ParseInt.UInt64.Decimal 224 172 -23.2% 1.30x
CharIteration_tweet_unicodeScalars 4840 3720 -23.1% 1.30x
CharIteration_ascii_unicodeScalars 2440 1880 -23.0% 1.30x
Data.append.Sequence.809B.Count0 262 202 -22.9% 1.30x
CSVParsing.Char 312 241 -22.8% 1.29x
RemoveWhereQuadraticString 262 203 -22.5% 1.29x
Data.append.Sequence.809B.Count0.I 260 203 -21.9% 1.28x
Data.append.Sequence.64kB.Count0.RE.I 197 154 -21.8% 1.28x
ParseInt.UInt64.Hex 380 298 -21.6% 1.28x
RemoveWhereSwapInts 15 12 -20.0% 1.25x
Data.append.Sequence.64kB.Count0.RE 193 155 -19.7% 1.25x
Data.init.Sequence.513B.Count0.I 327 266 -18.7% 1.23x (?)
Data.init.Sequence.809B.Count0.RE.I 310 254 -18.1% 1.22x (?)
Data.init.Sequence.809B.Count0.I 305 251 -17.7% 1.22x (?)
String.replaceSubrange.ArrChar 47 39 -17.0% 1.21x
Data.init.Sequence.809B.Count0.RE 304 254 -16.4% 1.20x (?)
Data.append.Sequence.809B.Count0.RE 265 222 -16.2% 1.19x
Data.append.Sequence.809B.Count0.RE.I 266 223 -16.2% 1.19x
Data.init.Sequence.809B.Count0 305 256 -16.1% 1.19x (?)
Set.isDisjoint.Seq.Int.Empty 51 43 -15.7% 1.19x
ReversedBidirectional 11055 9408 -14.9% 1.18x
CharIteration_punctuated_unicodeScalars 560 480 -14.3% 1.17x
MapReduceLazyCollectionShort 30 26 -13.3% 1.15x (?)
PrefixAnyCollectionLazy 78303 67940 -13.2% 1.15x
SuffixAnyCollectionLazy 26102 22859 -12.4% 1.14x
DropFirstAnyCollectionLazy 79520 69680 -12.4% 1.14x
DropLastAnyCollectionLazy 26079 23052 -11.6% 1.13x
Data.init.Sequence.511B.Count0.I 317 282 -11.0% 1.12x (?)
String.replaceSubrange.Substring 71 64 -9.9% 1.11x (?)
StringHashing_fastPrenormal 630 570 -9.5% 1.11x (?)
ReversedDictionary2 241 220 -8.7% 1.10x (?)
Set.isStrictSuperset.Seq.Box25 902 829 -8.1% 1.09x (?)
Set.isStrictSuperset.Seq.Box0 8971 8255 -8.0% 1.09x
StringToDataMedium 2550 2350 -7.8% 1.09x (?)
Set.isStrictSubset.Seq.Box0 901 832 -7.7% 1.08x (?)
CharIteration_chinese_unicodeScalars 2320 2160 -6.9% 1.07x (?)
Set.isStrictSubset.Seq.Box25 1018 948 -6.9% 1.07x (?)

Code size: -O

Regression OLD NEW DELTA RATIO
ObjectiveCBridgingStubs.o 14101 16245 +15.2% 0.87x
main.o 57911 62407 +7.8% 0.93x
DictionaryRemove.o 12600 13568 +7.7% 0.93x
PrimsNonStrongRef.o 117756 126596 +7.5% 0.93x
Prims.o 12243 12827 +4.8% 0.95x
PrimsSplit.o 12295 12879 +4.7% 0.95x
COWTree.o 10444 10804 +3.4% 0.97x
RandomShuffle.o 3382 3494 +3.3% 0.97x
DictionarySwap.o 17013 17549 +3.2% 0.97x
PopFrontGeneric.o 2548 2628 +3.1% 0.97x
RemoveWhere.o 15187 15651 +3.1% 0.97x
SortIntPyramids.o 8892 9142 +2.8% 0.97x
ArraySubscript.o 2316 2380 +2.8% 0.97x
ArrayOfGenericRef.o 8158 8366 +2.5% 0.98x
Queue.o 11853 12149 +2.5% 0.98x
DictTest2.o 10253 10501 +2.4% 0.98x
CSVParsing.o 53307 54595 +2.4% 0.98x
DictionaryGroup.o 11539 11811 +2.4% 0.98x
DictTest4.o 15322 15674 +2.3% 0.98x
PopFront.o 3604 3684 +2.2% 0.98x
Hanoi.o 3030 3094 +2.1% 0.98x
ArrayOfRef.o 8587 8747 +1.9% 0.98x
DictTest.o 13580 13828 +1.8% 0.98x
DictTest4Legacy.o 15796 16076 +1.8% 0.98x
DictTest3.o 14725 14973 +1.7% 0.98x
SetTests.o 117829 119813 +1.7% 0.98x
DictionarySubscriptDefault.o 18435 18739 +1.6% 0.98x
Array2D.o 2971 3019 +1.6% 0.98x
ArrayInClass.o 4277 4341 +1.5% 0.99x
ClassArrayGetter.o 3396 3444 +1.4% 0.99x
ArraySetElement.o 1174 1190 +1.4% 0.99x
SortArrayInClass.o 2664 2696 +1.2% 0.99x
RGBHistogram.o 21054 21294 +1.1% 0.99x
NibbleSort.o 13041 13176 +1.0% 0.99x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 3745 3505 -6.4% 1.07x
FlattenList.o 3914 3690 -5.7% 1.06x
ChaCha.o 15595 14923 -4.3% 1.05x
Prefix.o 15472 14824 -4.2% 1.04x
DropFirst.o 17324 16660 -3.8% 1.04x
DriverUtils.o 135039 129999 -3.7% 1.04x
Mirror.o 10854 10454 -3.7% 1.04x
StringMatch.o 4394 4250 -3.3% 1.03x
TestsUtils.o 28832 27904 -3.2% 1.03x
DropLast.o 21079 20415 -3.2% 1.03x
Suffix.o 21317 20669 -3.0% 1.03x
RangeReplaceableCollectionPlusDefault.o 5484 5324 -2.9% 1.03x
ArrayAppend.o 23015 22407 -2.6% 1.03x
IntegerParsing.o 55693 54301 -2.5% 1.03x
ReversedCollections.o 8822 8638 -2.1% 1.02x
ObjectiveCNoBridgingStubs.o 8024 7864 -2.0% 1.02x
CaptureProp.o 883 867 -1.8% 1.02x
DictOfArraysToArrayOfDicts.o 22877 22573 -1.3% 1.01x
BinaryFloatingPointConversionFromBinaryInteger.o 29176 28848 -1.1% 1.01x

Performance: -Osize

Regression OLD NEW DELTA RATIO
NopDeinit 9900 31200 +215.2% 0.32x
DropLastArray 4 9 +125.0% 0.44x
DropFirstArrayLazy 13 26 +100.0% 0.50x
ArrayAppendLazyMap 1020 1970 +93.1% 0.52x
RGBHistogramOfObjects 11200 21000 +87.5% 0.53x
Set.isStrictSubset.Box25 124 198 +59.7% 0.63x
SetIsSubsetBox25 124 196 +58.1% 0.63x
ParseInt.UIntSmall.Binary 540 810 +50.0% 0.67x
MapReduceString 34 48 +41.2% 0.71x
Dictionary4OfObjects 232 318 +37.1% 0.73x
EqualSubstringSubstring 22 30 +36.4% 0.73x
EqualSubstringSubstringGenericEquatable 22 30 +36.4% 0.73x (?)
EqualSubstringString 22 30 +36.4% 0.73x
Set.isDisjoint.Box25 405 551 +36.0% 0.74x
DropFirstAnyCollection 73 99 +35.6% 0.74x
LessSubstringSubstring 23 31 +34.8% 0.74x
LessSubstringSubstringGenericComparable 23 31 +34.8% 0.74x
ArrayAppendSequence 500 670 +34.0% 0.75x (?)
AngryPhonebook.ASCII2 109 145 +33.0% 0.75x
DropWhileAnyCollection 86 113 +31.4% 0.76x (?)
RandomShuffleLCG2 368 480 +30.4% 0.77x
EqualStringSubstring 23 30 +30.4% 0.77x
SetUnionBox25 245 319 +30.2% 0.77x
SetIntersectionBox25 176 228 +29.5% 0.77x
SetSymmetricDifferenceBox25 319 410 +28.5% 0.78x
SetIntersectionBox0 98 125 +27.6% 0.78x
PrefixWhileAnyCollection 99 126 +27.3% 0.79x
SetExclusiveOr_OfObjects 4350 5420 +24.6% 0.80x
SetSymmetricDifferenceBox0 435 542 +24.6% 0.80x (?)
Set.isDisjoint.Box0 503 625 +24.3% 0.80x
ChaCha 96 117 +21.9% 0.82x
ArrayAppendAsciiSubstring 19044 23148 +21.6% 0.82x
ArrayAppendLatin1Substring 19440 23616 +21.5% 0.82x
ArrayAppendUTF16Substring 19080 23148 +21.3% 0.82x
UTF8Decode_InitDecoding 143 172 +20.3% 0.83x
UTF8Decode_InitFromCustom_contiguous 144 173 +20.1% 0.83x
SetSubtractingBox0 111 133 +19.8% 0.83x (?)
Set.intersection.Seq.Box25 360 431 +19.7% 0.84x
Set.subtracting.Seq.Box0 549 656 +19.5% 0.84x (?)
SetUnion_OfObjects 3670 4380 +19.3% 0.84x
MapReduceAnyCollection 143 170 +18.9% 0.84x (?)
SetUnionBox0 371 438 +18.1% 0.85x (?)
Set.isStrictSubset.Seq.Box25 1021 1205 +18.0% 0.85x
Set.isSubset.Seq.Box25 1020 1203 +17.9% 0.85x (?)
Dictionary3OfObjects 427 501 +17.3% 0.85x
Set.subtracting.Seq.Box25 921 1077 +16.9% 0.86x (?)
ObjectiveCBridgeStubDateAccess 130 152 +16.9% 0.86x
Set.intersection.Seq.Box0 280 327 +16.8% 0.86x
DataSubscriptMedium 37 43 +16.2% 0.86x (?)
DropLastAnyCollection 33 38 +15.2% 0.87x
CharIteration_ascii_unicodeScalars_Backwards 3120 3560 +14.1% 0.88x
SetSubtractingBox25 193 220 +14.0% 0.88x (?)
DictionarySwapAtOfObjects 5093 5797 +13.8% 0.88x (?)
CharIteration_tweet_unicodeScalars_Backwards 6280 7120 +13.4% 0.88x (?)
SequenceAlgosContiguousArray 1600 1810 +13.1% 0.88x (?)
DictionaryRemoveOfObjects 16300 18400 +12.9% 0.89x
MapReduceAnyCollectionShort 1370 1540 +12.4% 0.89x (?)
Dictionary4OfObjectsLegacy 479 538 +12.3% 0.89x (?)
Set.isStrictSuperset.Seq.Box25 902 1010 +12.0% 0.89x (?)
MapReduceClass2 135 151 +11.9% 0.89x (?)
DataCountMedium 17 19 +11.8% 0.89x (?)
Set.isStrictSubset.Seq.Box0 903 1006 +11.4% 0.90x (?)
Set.isSubset.Seq.Box0 901 1002 +11.2% 0.90x (?)
Set.isStrictSuperset.Seq.Box0 9002 9995 +11.0% 0.90x (?)
TypeName 829 918 +10.7% 0.90x (?)
StringComparison_longSharedPrefix 328 363 +10.7% 0.90x (?)
SequenceAlgosRange 2170 2390 +10.1% 0.91x (?)
CharIteration_korean_unicodeScalars_Backwards 4280 4680 +9.3% 0.91x (?)
DictionaryOfObjects 1555 1700 +9.3% 0.91x (?)
MapReduceNSDecimalNumber 202 220 +8.9% 0.92x (?)
Walsh 637 693 +8.8% 0.92x (?)
DictionarySwapOfObjects 5920 6440 +8.8% 0.92x (?)
Dictionary2OfObjects 1520 1645 +8.2% 0.92x (?)
ParseInt.UInt64.Decimal 171 185 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
FindString.Loop1.Substring 658 353 -46.4% 1.86x
ObjectiveCBridgeStubDataAppend 3140 1980 -36.9% 1.59x
FindString.Rec3.Substring 220 144 -34.5% 1.53x
Data.init.Sequence.64kB.Count0.RE.I 199 131 -34.2% 1.52x
Data.append.Sequence.64kB.Count.I 44 29 -34.1% 1.52x
Data.append.Sequence.64kB.Count 44 29 -34.1% 1.52x
Data.append.Sequence.64kB.Count0.RE 195 131 -32.8% 1.49x
Data.init.Sequence.64kB.Count 43 29 -32.6% 1.48x
Data.append.Sequence.64kB.Count0.RE.I 195 132 -32.3% 1.48x
Data.init.Sequence.64kB.Count0.RE 195 133 -31.8% 1.47x
Data.append.Sequence.64kB.Count0 195 134 -31.3% 1.46x
FindString.Rec3.String 186 128 -31.2% 1.45x
Data.append.Sequence.64kB.Count0.I 195 136 -30.3% 1.43x
Data.init.Sequence.64kB.Count.I 43 30 -30.2% 1.43x
Data.init.Sequence.2047B.Count.I 77 54 -29.9% 1.43x
FlattenListLoop 1395 987 -29.2% 1.41x (?)
Data.init.Sequence.64kB.Count0 195 139 -28.7% 1.40x
Data.init.Sequence.64kB.Count0.I 195 139 -28.7% 1.40x
DropFirstAnySeqCRangeIterLazy 134 96 -28.4% 1.40x
DropFirstAnySeqCntRangeLazy 134 96 -28.4% 1.40x
SuffixAnyCollection 39 28 -28.2% 1.39x
Data.init.Sequence.2049B.Count.I 77 56 -27.3% 1.37x
Data.append.Sequence.809B.Count0.RE.I 267 195 -27.0% 1.37x
Data.append.Sequence.809B.Count0.RE 266 195 -26.7% 1.36x (?)
ArrayAppendRepeatCol 680 500 -26.5% 1.36x (?)
PrefixAnyCollection 99 73 -26.3% 1.36x
SetSymmetricDifferenceInt100 146 109 -25.3% 1.34x
Data.append.Sequence.809B.Count0.I 266 199 -25.2% 1.34x
Data.append.Sequence.809B.Count0 267 201 -24.7% 1.33x
Data.init.Sequence.809B.Count.I 73 55 -24.7% 1.33x
Data.init.Sequence.2047B.Count0.I 350 264 -24.6% 1.33x (?)
Data.init.Sequence.2049B.Count0.I 351 266 -24.2% 1.32x
Data.init.Sequence.809B.Count 72 55 -23.6% 1.31x
Data.init.Sequence.809B.Count0.I 312 241 -22.8% 1.29x
Data.init.Sequence.809B.Count0 313 242 -22.7% 1.29x
Data.init.Sequence.809B.Count0.RE.I 304 237 -22.0% 1.28x
Data.init.Sequence.809B.Count0.RE 305 238 -22.0% 1.28x
CSVParsing.Char 312 244 -21.8% 1.28x
Data.init.Sequence.511B.Count0.I 327 260 -20.5% 1.26x (?)
RemoveWhereQuadraticString 262 210 -19.8% 1.25x
Data.init.Sequence.511B.Count.I 84 68 -19.0% 1.24x
Data.append.Sequence.809B.Count 85 69 -18.8% 1.23x
Data.append.Sequence.809B.Count.I 85 69 -18.8% 1.23x
DropWhileAnyCollectionLazy 139 113 -18.7% 1.23x
String.replaceSubrange.ArrChar 47 39 -17.0% 1.21x
Data.init.Sequence.513B.Count.I 83 69 -16.9% 1.20x
RemoveWhereSwapInts 18 15 -16.7% 1.20x
Data.init.Sequence.513B.Count0.I 319 266 -16.6% 1.20x (?)
ReversedBidirectional 13198 11121 -15.7% 1.19x
UTF8Decode_InitFromCustom_noncontiguous_ascii 760 645 -15.1% 1.18x (?)
SetSymmetricDifferenceInt50 143 122 -14.7% 1.17x (?)
String.replaceSubrange.Substring 72 62 -13.9% 1.16x (?)
PrefixWhileAnyCollectionLazy 94 81 -13.8% 1.16x (?)
PrefixWhileAnySeqCRangeIterLazy 94 81 -13.8% 1.16x (?)
PrefixWhileAnySeqCntRangeLazy 94 81 -13.8% 1.16x (?)
UTF8Decode_InitFromCustom_noncontiguous_ascii_as_ascii 846 731 -13.6% 1.16x (?)
SuffixAnyCollectionLazy 26360 22824 -13.4% 1.15x (?)
ReversedDictionary2 262 228 -13.0% 1.15x (?)
DropLastAnyCollectionLazy 26097 22766 -12.8% 1.15x (?)
DropFirstAnyCollectionLazy 78978 68919 -12.7% 1.15x (?)
DataMutateBytesSmall 160 140 -12.5% 1.14x (?)
PrefixAnySeqCntRange 107 94 -12.1% 1.14x (?)
NibbleSort 2510 2230 -11.2% 1.13x (?)
SetSymmetricDifferenceInt25 136 121 -11.0% 1.12x (?)
PrefixAnyCollectionLazy 78850 70433 -10.7% 1.12x (?)
String.replaceSubrange.RepChar 2595 2324 -10.4% 1.12x (?)
Set.isDisjoint.Seq.Box.Empty 89 80 -10.1% 1.11x (?)
StringHashing_fastPrenormal 630 570 -9.5% 1.11x (?)
StringMatch 5400 4900 -9.3% 1.10x (?)
StringToDataEmpty 550 500 -9.1% 1.10x (?)
Set.isStrictSuperset.Seq.Int0 3374 3082 -8.7% 1.09x (?)
CharIteration_korean_unicodeScalars 3000 2760 -8.0% 1.09x (?)
CharIndexing_punctuatedJapanese_unicodeScalars_Backwards 1560 1440 -7.7% 1.08x (?)
StringToDataSmall 650 600 -7.7% 1.08x (?)
CharIndexing_chinese_unicodeScalars_Backwards 6400 5920 -7.5% 1.08x (?)
ArrayAppendReserved 270 250 -7.4% 1.08x (?)
CharIteration_russian_unicodeScalars 2880 2680 -6.9% 1.07x (?)
DataAccessBytesMedium 58 54 -6.9% 1.07x (?)
CharIndexing_korean_unicodeScalars_Backwards 8880 8280 -6.8% 1.07x (?)
CharIndexing_tweet_unicodeScalars 8320 7760 -6.7% 1.07x (?)
CharIndexing_ascii_unicodeScalars 4240 3960 -6.6% 1.07x (?)
ArrayAppendAscii 2074 1938 -6.6% 1.07x (?)
ArrayAppendLatin1 2074 1938 -6.6% 1.07x (?)

Code size: -Osize

Regression OLD NEW DELTA RATIO
Sim2DArray.o 1141 1236 +8.3% 0.92x
Array2D.o 2570 2739 +6.6% 0.94x
RGBHistogram.o 19101 20341 +6.5% 0.94x
SequenceAlgos.o 19910 21083 +5.9% 0.94x
DictTest2.o 8278 8751 +5.7% 0.95x
Memset.o 1712 1802 +5.3% 0.95x
Mirror.o 9602 9995 +4.1% 0.96x
DictTest.o 11561 12034 +4.1% 0.96x
DictionaryGroup.o 10006 10409 +4.0% 0.96x
RandomShuffle.o 3449 3585 +3.9% 0.96x
ArraySubscript.o 2105 2185 +3.8% 0.96x
DictTest3.o 12863 13336 +3.7% 0.96x
ClassArrayGetter.o 3148 3259 +3.5% 0.97x
RC4.o 3069 3172 +3.4% 0.97x
NopDeinit.o 4049 4175 +3.1% 0.97x
DictTest4.o 12792 13175 +3.0% 0.97x
ArrayAppend.o 21833 22461 +2.9% 0.97x
PopFrontGeneric.o 2464 2534 +2.8% 0.97x
DictionaryRemove.o 10678 10972 +2.8% 0.97x
ObserverClosure.o 2481 2548 +2.7% 0.97x
ObserverPartiallyAppliedMethod.o 2547 2614 +2.6% 0.97x
ArrayOfGenericRef.o 8018 8218 +2.5% 0.98x
Prims.o 11222 11500 +2.5% 0.98x
PrimsSplit.o 11274 11552 +2.5% 0.98x
SetTests.o 109223 111896 +2.4% 0.98x
ArrayOfRef.o 8299 8499 +2.4% 0.98x
COWTree.o 10693 10948 +2.4% 0.98x
DictionarySwap.o 15828 16204 +2.4% 0.98x
Hanoi.o 2919 2986 +2.3% 0.98x
PopFront.o 3171 3240 +2.2% 0.98x
DictionarySubscriptDefault.o 15395 15706 +2.0% 0.98x
Walsh.o 4018 4095 +1.9% 0.98x
SortArrayInClass.o 2649 2699 +1.9% 0.98x
SortIntPyramids.o 8751 8906 +1.8% 0.98x
ArraySetElement.o 1089 1108 +1.7% 0.98x
Queue.o 11738 11924 +1.6% 0.98x
DictTest4Legacy.o 13557 13766 +1.5% 0.98x
ObserverForwarderStruct.o 2728 2767 +1.4% 0.99x
ArrayInClass.o 4359 4421 +1.4% 0.99x
SortLargeExistentials.o 19721 19999 +1.4% 0.99x
Breadcrumbs.o 36161 36641 +1.3% 0.99x
RangeAssignment.o 2988 3027 +1.3% 0.99x
ObjectiveCBridgingStubs.o 13818 13978 +1.2% 0.99x
RemoveWhere.o 13917 14073 +1.1% 0.99x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 3555 3360 -5.5% 1.06x
DropFirst.o 16274 15608 -4.1% 1.04x
Prefix.o 16670 16004 -4.0% 1.04x
DropLast.o 20070 19419 -3.2% 1.03x
Suffix.o 20371 19738 -3.1% 1.03x
IntegerParsing.o 52386 51254 -2.2% 1.02x
StringMatch.o 4208 4144 -1.5% 1.02x
CSVParsing.o 51178 50447 -1.4% 1.01x
DictOfArraysToArrayOfDicts.o 20765 20485 -1.3% 1.01x
RangeReplaceableCollectionPlusDefault.o 4351 4305 -1.1% 1.01x
BinaryFloatingPointConversionFromBinaryInteger.o 28166 27877 -1.0% 1.01x
ReversedCollections.o 8205 8123 -1.0% 1.01x

Performance: -Onone

Regression OLD NEW DELTA RATIO
SetSubtractingInt0 166 225 +35.5% 0.74x
AngryPhonebook.ASCII2 110 145 +31.8% 0.76x
SetSubtractingInt25 218 279 +28.0% 0.78x
SetSubtractingInt50 250 309 +23.6% 0.81x
SetSubtractingInt100 297 354 +19.2% 0.84x
UTF8Decode_InitDecoding 149 177 +18.8% 0.84x
UTF8Decode_InitFromCustom_contiguous 152 180 +18.4% 0.84x
SetSubtractingBox0 399 454 +13.8% 0.88x
SortStrings 1468 1647 +12.2% 0.89x (?)
SetSubtractingBox25 519 575 +10.8% 0.90x (?)
ArraySetElement 1234 1334 +8.1% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
ReversedArray2 3663 918 -74.9% 3.99x
StringComparison_ascii 2635 1138 -56.8% 2.32x
Chars2 11000 6450 -41.4% 1.71x
DropFirstArrayLazy 54456 33229 -39.0% 1.64x
Breadcrumbs.UTF16ToIdx.longASCII 385 236 -38.7% 1.63x
AngryPhonebook 658 406 -38.3% 1.62x
StringComparison_fastPrenormal 2170 1350 -37.8% 1.61x
SuffixArrayLazy 17414 10922 -37.3% 1.59x
StringComparison_latin1 1492 940 -37.0% 1.59x
PrefixArrayLazy 52051 32814 -37.0% 1.59x
AngryPhonebook.ASCII2.Small 300 196 -34.7% 1.53x
DropLastArrayLazy 17301 11495 -33.6% 1.51x
StringHashing_ascii 74 50 -32.4% 1.48x
ObjectiveCBridgeStubDataAppend 3680 2540 -31.0% 1.45x
PrefixArray 5960 4140 -30.5% 1.44x
SuffixArray 1994 1394 -30.1% 1.43x
DropFirstArray 5947 4163 -30.0% 1.43x
DropLastArray 1973 1383 -29.9% 1.43x
ReversedDictionary2 10684 7649 -28.4% 1.40x
StringComparison_longSharedPrefix 846 615 -27.3% 1.38x
String.replaceSubrange.ArrChar 63 47 -25.4% 1.34x
StringComparison_slowerPrenormal 1810 1360 -24.9% 1.33x
ClosedRangeOverlapsClosedRange 9473 7189 -24.1% 1.32x
DropWhileArray 10027 7623 -24.0% 1.32x
Breadcrumbs.UTF16ToIdx.longMixed 585 446 -23.8% 1.31x
SuperChars2 555 426 -23.2% 1.30x
SuffixCountableRangeLazy 24095 18560 -23.0% 1.30x
IterateData 2791 2150 -23.0% 1.30x
FlattenListLoop 40554 31279 -22.9% 1.30x
RangeOverlapsRange 10260 7928 -22.7% 1.29x
PrefixCountableRangeLazy 72274 56115 -22.4% 1.29x
StringComparison_emoji 920 720 -21.7% 1.28x
StringComparison_nonBMPSlowestPrenormal 1670 1310 -21.6% 1.27x
ParseFloat.Double.Exp 14 11 -21.4% 1.27x
ParseFloat.Float.Exp 14 11 -21.4% 1.27x (?)
DropFirstCountableRangeLazy 72227 56800 -21.4% 1.27x
CharIteration_russian_unicodeScalars 50720 40040 -21.1% 1.27x
Breadcrumbs.IdxToUTF16.longASCII 725 573 -21.0% 1.27x
CharIteration_tweet_unicodeScalars 116400 92160 -20.8% 1.26x
CharIteration_ascii_unicodeScalars 59520 47160 -20.8% 1.26x
RangeOverlapsClosedRange 11064 8779 -20.7% 1.26x
ArrayValueProp2 8939 7096 -20.6% 1.26x
NormalizedIterator_ascii 131 104 -20.6% 1.26x
CharIteration_chinese_unicodeScalars 46200 36800 -20.3% 1.26x
CharIteration_korean_unicodeScalars_Backwards 125880 100320 -20.3% 1.25x
CharIteration_korean_unicodeScalars 59520 47520 -20.2% 1.25x (?)
CharIteration_japanese_unicodeScalars 71760 57320 -20.1% 1.25x
CharIteration_punctuated_unicodeScalars 14800 11840 -20.0% 1.25x
CharIteration_russian_unicodeScalars_Backwards 105640 85040 -19.5% 1.24x (?)
CharIteration_punctuatedJapanese_unicodeScalars_Backwards 23080 18600 -19.4% 1.24x
CharIndexing_ascii_unicodeScalars 144040 116120 -19.4% 1.24x
CharIteration_tweet_unicodeScalars_Backwards 243520 196400 -19.3% 1.24x
SuffixAnyCollectionLazy 47452 38320 -19.2% 1.24x
DropLastCountableRangeLazy 24001 19422 -19.1% 1.24x
CharIteration_punctuated_unicodeScalars_Backwards 28760 23280 -19.1% 1.24x
FindString.Loop1.Substring 787 638 -18.9% 1.23x
CharIteration_punctuatedJapanese_unicodeScalars 11520 9360 -18.7% 1.23x
Breadcrumbs.UTF16ToIdxRange.longASCII 144 117 -18.7% 1.23x
CharIndexing_chinese_unicodeScalars 109520 89040 -18.7% 1.23x
Breadcrumbs.IdxToUTF16Range.longASCII 150 122 -18.7% 1.23x
CharIteration_japanese_unicodeScalars_Backwards 150280 122720 -18.3% 1.22x
DropFirstAnyCollectionLazy 138167 112850 -18.3% 1.22x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 83 68 -18.1% 1.22x
DropLastAnyCollectionLazy 46054 37760 -18.0% 1.22x
PrefixWhileArray 18091 14850 -17.9% 1.22x
CharIteration_utf16_unicodeScalars_Backwards 119040 97720 -17.9% 1.22x
CharIteration_ascii_unicodeScalars_Backwards 124800 102480 -17.9% 1.22x
CharIndexing_chinese_unicodeScalars_Backwards 219440 180440 -17.8% 1.22x (?)
CharIteration_chinese_unicodeScalars_Backwards 96480 79440 -17.7% 1.21x
PrefixAnyCollectionLazy 137687 113539 -17.5% 1.21x
CharIndexing_japanese_unicodeScalars 173120 143080 -17.4% 1.21x
CharIndexing_tweet_unicodeScalars 282080 235240 -16.6% 1.20x
CharIndexing_punctuatedJapanese_unicodeScalars 25880 21600 -16.5% 1.20x
NormalizedIterator_latin1 304 254 -16.4% 1.20x
Dictionary 1200 1005 -16.2% 1.19x
CharIndexing_russian_unicodeScalars 120920 101280 -16.2% 1.19x
CharIndexing_korean_unicodeScalars 140960 118520 -15.9% 1.19x
StringBuilder 3536 2981 -15.7% 1.19x
StringHashing_latin1 294 248 -15.6% 1.19x
StringBuilderSmallReservingCapacity 3536 2987 -15.5% 1.18x
Breadcrumbs.MutatedIdxToUTF16.ASCII 13 11 -15.4% 1.18x (?)
StringUTF16Builder 3540 3010 -15.0% 1.18x
PrefixWhileAnySequence 11915 10144 -14.9% 1.17x
CharIndexing_punctuated_unicodeScalars_Backwards 62560 53320 -14.8% 1.17x (?)
ConvertFloatingPoint.MockFloat64ToDouble 1270 1087 -14.4% 1.17x (?)
CharIndexing_ascii_unicodeScalars_Backwards 275640 237240 -13.9% 1.16x (?)
CharIndexing_punctuated_unicodeScalars 32520 28040 -13.8% 1.16x
CharIndexing_punctuatedJapanese_unicodeScalars_Backwards 49120 42400 -13.7% 1.16x
PrefixWhileSequence 11916 10290 -13.6% 1.16x
ObserverForwarderStruct 2160 1870 -13.4% 1.16x (?)
CharIteration_utf16_unicodeScalars 61400 53440 -13.0% 1.15x
CharIndexing_utf16_unicodeScalars 147440 128600 -12.8% 1.15x (?)
ArrayAppendSequence 64180 56060 -12.7% 1.14x (?)
UTF8Decode_InitFromCustom_noncontiguous_ascii_as_ascii 90684 79320 -12.5% 1.14x
StringHashing_fastPrenormal 720 630 -12.5% 1.14x
ConvertFloatingPoint.MockFloat64Exactly 400 350 -12.5% 1.14x
UTF8Decode_InitFromCustom_noncontiguous 28569 25011 -12.5% 1.14x
RemoveWhereQuadraticString 2243 1964 -12.4% 1.14x
ProtocolConformance 105 92 -12.4% 1.14x (?)
MapReduceString 1940 1704 -12.2% 1.14x (?)
SumUsingReduce 196243 172539 -12.1% 1.14x (?)
UTF8Decode_InitFromCustom_noncontiguous_ascii 90053 79235 -12.0% 1.14x
Breadcrumbs.UTF16ToIdxRange.longMixed 234 206 -12.0% 1.14x
SumUsingReduceInto 194522 171304 -11.9% 1.14x (?)
CharIndexing_japanese_unicodeScalars_Backwards 337280 297280 -11.9% 1.13x
CharIndexing_utf16_unicodeScalars_Backwards 282200 249280 -11.7% 1.13x
Breadcrumbs.CopyUTF16CodeUnits.Mixed 123 109 -11.4% 1.13x (?)
CharIndexing_korean_unicodeScalars_Backwards 273240 242280 -11.3% 1.13x
SubstringEqualString 1043 925 -11.3% 1.13x (?)
Breadcrumbs.IdxToUTF16.longMixed 1360 1207 -11.2% 1.13x (?)
CharIndexing_tweet_unicodeScalars_Backwards 545880 484880 -11.2% 1.13x (?)
MapReduceAnyCollection 37438 33264 -11.1% 1.13x (?)
ParseFloat.Float80.Exp 36 32 -11.1% 1.12x (?)
Breadcrumbs.MutatedUTF16ToIdx.ASCII 9 8 -11.1% 1.12x (?)
NSStringConversion.LongUTF8 2699 2400 -11.1% 1.12x (?)
MapReduce 37412 33294 -11.0% 1.12x (?)
SequenceAlgosArray 951070 846760 -11.0% 1.12x
CharacterPropertiesStashed 1660 1480 -10.8% 1.12x (?)
CharIndexing_russian_unicodeScalars_Backwards 232400 207440 -10.7% 1.12x
ObjectAllocation 755 674 -10.7% 1.12x
String.replaceSubrange.Substring 75 67 -10.7% 1.12x
UTF8Decode 35544 31772 -10.6% 1.12x (?)
RangeAssignment 16900 15116 -10.6% 1.12x (?)
SequenceAlgosContiguousArray 883260 790490 -10.5% 1.12x (?)
SubstringComparable 1905 1710 -10.2% 1.11x (?)
MapReduceClass2 3969 3563 -10.2% 1.11x (?)
QueueConcrete 10150 9120 -10.1% 1.11x (?)
DropWhileArrayLazy 19390 17457 -10.0% 1.11x (?)
MapReduceNSDecimalNumber 4144 3731 -10.0% 1.11x (?)
ObserverPartiallyAppliedMethod 4240 3820 -9.9% 1.11x (?)
MapReduceShort 44030 39690 -9.9% 1.11x (?)
CSVParsingAltIndices2 3872 3498 -9.7% 1.11x (?)
LazilyFilteredArrayContains 958300 867800 -9.4% 1.10x (?)
NSStringConversion.MutableCopy.LongUTF8 1548 1404 -9.3% 1.10x (?)
CharacterPropertiesStashedMemo 2520 2290 -9.1% 1.10x (?)
Set.isSuperset.Seq.Int25 1066 969 -9.1% 1.10x (?)
Set.isSuperset.Seq.Int100 4202 3820 -9.1% 1.10x (?)
Set.isSuperset.Seq.Int50 2103 1912 -9.1% 1.10x (?)
MapReduceAnyCollectionShort 43120 39210 -9.1% 1.10x (?)
NSStringConversion.Long 10109 9202 -9.0% 1.10x (?)
MapReduceNSDecimalNumberShort 4747 4323 -8.9% 1.10x (?)
PrefixWhileArrayLazy 15736 14351 -8.8% 1.10x (?)
Set.isDisjoint.Seq.Int25 3198 2922 -8.6% 1.09x (?)
RemoveWhereFilterInts 2171 1984 -8.6% 1.09x (?)
MapReduceClassShort2 4580 4189 -8.5% 1.09x (?)
String.replaceSubrange.RepChar 2623 2400 -8.5% 1.09x (?)
MapReduceShortString 204 187 -8.3% 1.09x (?)
RandomShuffleLCG2 37312 34208 -8.3% 1.09x (?)
NSStringConversion.Medium 3768 3458 -8.2% 1.09x (?)
SubstringEquatable 5472 5033 -8.0% 1.09x (?)
ArrayAppendLazyMap 210660 193840 -8.0% 1.09x (?)
LazilyFilteredArrays2 90900 83700 -7.9% 1.09x (?)
MapReduceLazyCollectionShort 32794 30238 -7.8% 1.08x (?)
StringComparison_abnormal 780 720 -7.7% 1.08x (?)
ParseFloat.Float.Uniform 26 24 -7.7% 1.08x (?)
NSStringConversion.UTF8 3215 2968 -7.7% 1.08x (?)
CharacterPropertiesPrecomputed 2230 2060 -7.6% 1.08x (?)
ChainedFilterMap 245619 227088 -7.5% 1.08x (?)
ParseFloat.Double.Uniform 40 37 -7.5% 1.08x (?)
SuffixSequence 10176 9421 -7.4% 1.08x (?)
RemoveWhereFilterStrings 2631 2437 -7.4% 1.08x (?)
ErrorHandling 4040 3750 -7.2% 1.08x (?)
MapReduceLazyCollection 27773 25793 -7.1% 1.08x (?)
NormalizedIterator_fastPrenormal 720 670 -6.9% 1.07x (?)
MapReduceSequence 31312 29148 -6.9% 1.07x (?)
Set.isSuperset.Seq.Empty.Int 510 475 -6.9% 1.07x (?)
Set.isSubset.Seq.Int0 5208 4858 -6.7% 1.07x (?)
Set.isStrictSuperset.Seq.Int0 51710 48280 -6.6% 1.07x (?)
Set.isStrictSuperset.Seq.Int25 5171 4829 -6.6% 1.07x (?)
ObserverUnappliedMethod 4430 4140 -6.5% 1.07x (?)

Code size: -swiftlibs

Regression OLD NEW DELTA RATIO
libswiftStdlibUnittest.dylib 311296 327680 +5.3% 0.95x
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

@eeckstein eeckstein merged commit 0f6f429 into swiftlang:main Oct 12, 2020
@eeckstein eeckstein deleted the temp-rvalue-opt branch October 12, 2020 09:12
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.

Out of curiosity, what do you mean by "the regressions are unavoidable"? Do you mean that the regressions are all cases where we can't possibly determine that the source of the copy is not written within the callee function? Is it because the source is a class property and the class reference was passed in as an argument to the current function?

I have two requests for change below, and one response to your code comment...

// for these.
//
// FIXME: Once we separate the notion of ref counts from reading/writing
// memory this will be unnecessary.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this FIXME supposed to go away now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. I removed it in #34289

// For exclusive/local addresses we can do a quick and good check with alias
// analysis. For everything else we use escape analysis (see below).
// TODO: The check for not-escaping can probably done easier with the upcoming
// API of AccessStorage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. Yes, AccessedStorage replaces getUnderlyingObject and my current branch has a "use visitor" that hasEscapingUses will trivially plug into. This is exactly how I expected the new API to be used, and this is specifically one of the things I wanted to do to improve alias analysis. The new utilities will remove remove some of the implementation here, ensure that the def-use/use-def logic is symmetric, complete and consistent with all the other address analysis in the compiler, and independently verified/tested.

// reference argument. In this case V clearly "aliases" the argument, but
// this is not reported by alias analysis.
if ((!nonEscapingAddress && !arg->getType().isAddress()) ||
mayAlias(arg)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code was carefully designed to avoid calling alias analysis unless the argument behavior changed. I think you should change it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did see the intention of the original code.
I did some experiments (for another reason) to check how often this code is actually called and found that it's not called very heavily.
Therefore I decided to "optimize" for clarity.

@eeckstein
Copy link
Contributor Author

About the regressions: some regressions are noise and (I believe) some regressions are due to inlining decisions.
But for example, NopDeinit is a case of passing a reference to a function.

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