Skip to content

OSSA utility incremental redesign and SILCombine fixes #39740

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 7 commits into from
Oct 18, 2021

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Oct 14, 2021

This PR significantly affects functionality. These commits are functionally interdependent. Improving the utilities exposes SILCombine bugs, and utility needs to be updated to fix SILCombine.

The main functional change is:
Migrate to OwnershipLifetimeExtender API: borrowCopyOverScope, etc.

Preparation for rewriting non-trivial terminators and generalizing
support for guaranteed phis.

Add guaranteedUsePoints to the RAUW context. This will replace ALL
existing context book-keeping once the old code is deleted.

Introduce a borrowCopyOverScope entry point to handle extending
lifetime over a BorrowedValue. This simply uses the
BorrowedLifetimeExtender.

Introduce higher-level APIs:

  • borrowOverValue to extened over a guaranteedValue
  • borrowOverSingleUse to extened over a single guaranteed use

These replace both createPlusZeroBorrow and createPlusOneBorrow.

Update RAUW-ctor, RAUW::handleUnowned, and replaceAddressUses to use
the new API.

Restructure RAUW::canFixUpOwnershipForRAUW. Simply use
findInnerTransitiveGuaranteedUses.

Replace RAUW::handleGuaranteed and rewriteReborrows with
OLE::borrowOverValue.

Use the BorrowedLifetimeExtender utility to handle all situations
correctly.

This exposes SILCombine issues.

In order to fix SILCombine, make the RAUW interface more flexible.

Divide the RAUW logic into smaller pieces. This allows passes to check for
replaceability before generating the replacement value.

@atrick
Copy link
Contributor Author

atrick commented Oct 14, 2021

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Oct 14, 2021

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Oct 14, 2021

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
DictionaryKeysContainsCocoa 31 34 +9.7% 0.91x (?)
RemoveWhereMoveInts 31 34 +9.7% 0.91x (?)
 
Improvement OLD NEW DELTA RATIO
StringFromLongWholeSubstring 5 4 -20.0% 1.25x (?)
ObjectiveCBridgeStubFromNSDate 7140 6280 -12.0% 1.14x (?)
Breadcrumbs.MutatedUTF16ToIdx.Mixed 309 280 -9.4% 1.10x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 314 285 -9.2% 1.10x (?)

Code size: -O

Improvement OLD NEW DELTA RATIO
Suffix.o 21916 21052 -3.9% 1.04x

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
SuffixSequence 162 197 +21.6% 0.82x
SuffixSequenceLazy 163 198 +21.5% 0.82x
RemoveWhereMoveInts 34 37 +8.8% 0.92x (?)
Array2D 6944 7520 +8.3% 0.92x (?)
RemoveWhereSwapInts 37 40 +8.1% 0.93x (?)
StringBuilderWithLongSubstring 1530 1650 +7.8% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 7024 6205 -11.7% 1.13x (?)
Data.append.Sequence.809B.Count.RE 114 103 -9.6% 1.11x (?)
Breadcrumbs.MutatedUTF16ToIdx.Mixed 309 280 -9.4% 1.10x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 313 285 -8.9% 1.10x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
Suffix.o 19480 18820 -3.4% 1.04x

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSString 1695 1875 +10.6% 0.90x (?)
 
Improvement OLD NEW DELTA RATIO
Breadcrumbs.MutatedIdxToUTF16.Mixed 331 301 -9.1% 1.10x (?)
Breadcrumbs.MutatedUTF16ToIdx.Mixed 316 288 -8.9% 1.10x (?)
DataToStringSmall 5000 4600 -8.0% 1.09x (?)

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

@atrick
Copy link
Contributor Author

atrick commented Oct 15, 2021

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Oct 15, 2021

@swift-ci test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - aa1263a9e9045c52b1dc2862494e58ec5ca0a929

@atrick
Copy link
Contributor Author

atrick commented Oct 16, 2021

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Oct 18, 2021

This passed SCK with OME running before Mem2Reg

Preparation for rewriting non-trivial terminators and generalizing
support for guaranteed phis.

Add guaranteedUsePoints to the RAUW context. This will replace ALL
existing context book-keeping once the old code is deleted.

Introduce a borrowCopyOverScope entry point to handle extending
lifetime over a BorrowedValue. This simply uses the
BorrowedLifetimeExtender.

Introduce higher-level APIs:
- borrowOverValue to extened over a guaranteedValue
- borrowOverSingleUse to extened over a single guaranteed use

These replace both createPlusZeroBorrow and createPlusOneBorrow.

Update RAUW-ctor, RAUW::handleUnowned, and replaceAddressUses to use
the new API.

Restructure RAUW::canFixUpOwnershipForRAUW. Simply use
findInnerTransitiveGuaranteedUses.

Replace RAUW::handleGuaranteed and rewriteReborrows with
OLE::borrowOverValue.

Use the BorrowedLifetimeExtender utility to handle all situations
correctly.

TODO: createPlusOneBorrow can be completely removed, and a massive
amount of confusing/incomplete code can be deleted in a follow-up
commit.
Required to fix SILCombine.

Divide the logic into smaller pieces. This allows passes to check for
replaceability before generating the replacement value.

Preparation for simplifying OSSA utilities into smaller logical
components making them flexibile and allowing improvements to be
staged in.
Avoid generating useless empty copies and borrow scopes.

Bypass all the use-checking logic when there are no uses to avoid
special cases and bugs.
These SILCombine patterns produce new instructions that use the the
original value after it is updated for OSSA. The RAUW utility needs to
copy/borrow the original value before SILCombine can generate the new
replacement. Then SILCombine can pass that replacement back to RAUW to
perform the final replaceAllUsesWith.

1. PointerToAddress and RawPointerToRef

Fixes bugs where RAUW inserts borrows in the wrong place.

2. UncheckedBitwiseCast

The OSSA RAUW helper is incorrect here for producing a new
UncheckedRefCast. Simply don't use it. Since a bitwise cast is an
"Unowned" pointer escape, simply convert the unchecked_bitwise_cast
opcode to unchecked_ref_cast with Unowned forwarding ownership.

3. ConvertFunction

Make sure RAUW is never called with a replacement value that has
different ownership than the original.
@atrick
Copy link
Contributor Author

atrick commented Oct 18, 2021

@swift-ci smoke test

@atrick atrick merged commit 275c341 into swiftlang:main Oct 18, 2021
@atrick atrick deleted the oou-borrow branch October 18, 2021 20:55
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.

2 participants