-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
Historically ARC code motion was also part of ARCSequenceOpts. Remove some stale comments regarding 'insertion points'
@swift-ci test |
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
7903882
to
3f6ccad
Compare
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
3f6ccad
to
4d2753b
Compare
@swift-ci smoke test |
@swift-ci benchmark |
@swift-ci please benchmark |
Performance: -O
Code size: -OPerformance: -OsizeCode size: -OsizePerformance: -Onone
Code size: -swiftlibsHow to read the dataThe 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 Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
@gottesmm thanks for the review. I'll resolve your comments in another PR |
@meg-gupta SGTM thanks! |
* 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
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