Skip to content

Teach stripCasts (and getUnderlyingObject) about begin_access. #32842

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 1 commit into from
Jul 13, 2020

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 11, 2020

This was blocking EscapeAnalysis and many other analyses from handling
access markers.

This was blocking EscapeAnalysis and many other analyses from handling
access markers.
@atrick atrick requested a review from eeckstein July 11, 2020 23:33
@@ -145,7 +146,8 @@ SILValue swift::stripCasts(SILValue v) {
auto k = v->getKind();
if (isRCIdentityPreservingCast(k)
|| k == ValueKind::UncheckedTrivialBitCastInst
|| k == ValueKind::MarkDependenceInst) {
|| k == ValueKind::MarkDependenceInst
|| k == ValueKind::BeginAccessInst) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eeckstein I don't know why stripCasts does not check EndCOWMutation

Copy link
Contributor

@eeckstein eeckstein Jul 12, 2020

Choose a reason for hiding this comment

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

It's a longer story: when I added end_cow_mutation, I came to the conclusion that those global stripWhatEver utility functions are not such a good idea.
Let's take stripCasts as example: every optimization has (or could have) a different view of what a cast instruction is. For EscapeAnalysis a begin_access is the same as a cast. But that's not necessarily true for other optimizations, which might need to treat begin_access separately.

I think it's better to let each optimization/analysis contain there own strip... functions, even if this means some code duplication.
Then it's much easier to modify them and add instructions as needed without worrying about other optimizations.

That's why I added end_cow_mutation only at those places where it was really needed and not in the global strip functions.
... and unfortunately, never came back to remove the global strip functions at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The strip utilities are not good abstractions for a high-level IR like SIL. I also did not want to modify them when adding the access markers. But not handling access markers has been blocking progress recently, and migrating passes away from the strip functions will take more time.

We now have an AccessUseDefVisitor that more properly abstracts over address and pointer operations, allowing passes to override some of the behavior without copying a giant switch statement everywhere. I'll demonstrate this in some upcoming PRs... And for every use-def abstraction, we need a matching def-use abstraction.

More importantly, an abstraction is useful if we can use it impose some order on SIL, defining which patterns are valid SIL and enforcing that in the verifier. In some situations, we can't simply bail-out on unrecognized patterns, so we need an abstraction that's guaranteed to work everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't get me wrong: I think this PR is fine. I just wanted to answer the question why end_cow_mutation is not handled in stripCasts.

@atrick
Copy link
Contributor Author

atrick commented Jul 11, 2020

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Jul 11, 2020

@swift-ci benchmark

@atrick
Copy link
Contributor Author

atrick commented Jul 11, 2020

@swift-ci test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3766962

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
CharacterLiteralsLarge 63 75 +19.0% 0.84x
ObjectiveCBridgeStubFromNSString 505 579 +14.7% 0.87x (?)
PrefixArrayLazy 13 14 +7.7% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
Set.isSuperset.Seq.Empty.Int 50 46 -8.0% 1.09x (?)

Code size: -O

Improvement OLD NEW DELTA RATIO
ObserverClosure.o 2446 2398 -2.0% 1.02x
ObserverPartiallyAppliedMethod.o 2509 2461 -1.9% 1.02x
Prims.o 12763 12635 -1.0% 1.01x
PrimsSplit.o 12815 12687 -1.0% 1.01x

Performance: -Osize

Improvement OLD NEW DELTA RATIO
MapReduceLazyCollectionShort 50 30 -40.0% 1.67x
FlattenListFlatMap 4410 2832 -35.8% 1.56x (?)
MapReduceString 40 35 -12.5% 1.14x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
ObjectiveCBridgeStubToNSDateRef 2540 2780 +9.4% 0.91x (?)
ObjectiveCBridgeStubToNSDate2 390 420 +7.7% 0.93x (?)

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

@atrick
Copy link
Contributor Author

atrick commented Jul 12, 2020

@swift-ci test macos platform

@atrick atrick merged commit 89f0f5d into swiftlang:master Jul 13, 2020
@atrick atrick deleted the strip-access-casts branch July 13, 2020 20:19
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