Skip to content

Fix ARCSequenceOpts bottom up handling of terminators #33504

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 3 commits into from
Aug 18, 2020

Conversation

meg-gupta
Copy link
Contributor

Historically TermInsts were handled specially while visiting blocks in bottom up order. TermInsts were not visited while traversing the block which they belong to. They were visited while traversing successors, and the most conservative terminator of all predecessors would affect the refcount state in the dataflow.

This was needed because ARCSequenceOpts also computed 'insertion points' for the purposes of ARC code motion. ARC code motion was then removed from ARCSequenceOpts and this code remained unchanged.

With this change, arc significant terminators are handled like all other instructions while processing basic blocks bottom up.

Also updateForSameLoopInst, updateForDifferentLoopInst, updateForPredTerminators all serve similar purpose with subtle differences. This change removes some code duplication due to this.

Why this change now ? #33267 improved guaranteed args handling in updateForSameLoopInst. It did not updateForPredTerminators, causing different top down and bottom up behavior for arc significant terminators.

Fixes rdar://66932268

Historically ARC code motion was also part of ARCSequenceOpts. Remove
some stale comments regarding 'insertion points'
@meg-gupta meg-gupta requested review from gottesmm and atrick August 17, 2020 17:23
@meg-gupta meg-gupta changed the title Fixarcseqopt Fix ARCSequenceOpts bottom up handling of terminators Aug 17, 2020
@meg-gupta
Copy link
Contributor Author

@swift-ci test

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.

Wow! This is a lot better. Thanks.

Just a couple comments.

if (isa<TermInst>(*II)) {
auto *terminator = &cast<TermInst>(*II);
if (terminator == BB.getTerminator() &&
!isARCSignificantTerminator(terminator)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like there's some extra logic here. Why not just

if (!isARCSignificantTerminator(cast<TermInt>(*II))
 ++II;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

bool isARCSignificantTerminator(TermInst *TI);
} // end namespace swift

#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to insert newlines at the end of the new files so tools don't warn us about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Historically TermInsts were handled specially while visiting blocks in
bottom up order. TermInsts were not visited while traversing a block.
They were visited while traversing successors, and the most conservative
terminator of all predecessors would affect the refcount state in the
dataflow.

This was needed because ARCSequenceOpts also computed 'insertion points'
for the purposes of ARC code motion. ARC code motion was then removed
from ARCSequenceOpts and this code remained unchanged.

With this change, arc significant terminators are handled like all other
instructions while processing basic blocks bottom up.

Also updateForSameLoopInst, updateForDifferentLoopInst,
updateForPredTerminators all serve similar purpose with subtle differences.
This change removes some code duplication due to this.

Remove code duplication of isARCSignificantTerminator. Create
ARCSequenceOptUtils for common utils used in ARCSequenceOpts
@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta
Copy link
Contributor Author

@swift-ci benchmark

@meg-gupta
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 4594 4012 -12.7% 1.15x (?)

Code size: -O

Performance: -Osize

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
String.data.Medium 127 138 +8.7% 0.92x (?)

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

@meg-gupta meg-gupta merged commit ee26fea into swiftlang:master Aug 18, 2020
Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Thanks for eliminating the references to insertion points! This code is really crusty and needed attention = ).


using namespace swift;
namespace swift {
bool isARCSignificantTerminator(TermInst *TI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@meg-gupta We generally do not create namespaces for stuff like this. Can you instead do swift::isARCSignificantTerminator. We are pretty consistent about it in the code-base.

#include "swift/SIL/SILInstruction.h"

namespace swift {
bool isARCSignificantTerminator(TermInst *TI);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not indent here. See LLVM Style: https://llvm.org/docs/CodingStandards.html#namespace-indentation

// For each terminator instruction I in BB visited in reverse...
for (auto II = std::next(BB.rbegin()), IE = BB.rend(); II != IE;) {
auto II = BB.rbegin();
if (isa<TermInst>(*II)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be a TermInst. I would change this to be a cast.

@meg-gupta
Copy link
Contributor Author

@gottesmm thanks for the review. I'll resolve your comments in another PR

meg-gupta added a commit to meg-gupta/swift that referenced this pull request Aug 21, 2020
@gottesmm
Copy link
Contributor

@meg-gupta SGTM thanks!

meg-gupta added a commit that referenced this pull request Aug 25, 2020
* Remove NewInsts from ARCSequenceOpts

* Remove more instances of InsertPts

* Address comments from #33504

* Make bottom up loop traversal simpler. Use better apis

* Update LoopRegion printer with more info
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