-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Enable CSE on OSSA #34895
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
Enable CSE on OSSA #34895
Conversation
I started perusing maybe I missed, do you have a bunch of tests with guaranteed values? |
8c462b5
to
e9a610b
Compare
@gottesmm I added some tests with guaranteed values now. |
@swift-ci test |
Build failed |
Build failed |
lib/SILOptimizer/Transforms/CSE.cpp
Outdated
// new opened archetype already registered in | ||
// CSE::processOpenExistentialRefInst. | ||
auto *oldOpenedArchetypeDef = oldUse->getUser(); | ||
auto &Builder = Cloner.getBuilder(); |
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.
nit: Builder -> builder.
lib/SILOptimizer/Transforms/CSE.cpp
Outdated
RunsOnHighLevelSil(RunsOnHighLevelSil) {} | ||
OpenedArchetypesTracker(OpenedArchetypesTracker), Cloner(Cloner), | ||
RunsOnHighLevelSil(RunsOnHighLevelSil) { | ||
auto &Builder = Cloner.getBuilder(); |
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.
Nit: also no captial. Or maybe even: Cloner.getBuilder().setOpenedArchetypesTracker...
9cbf2cd
to
85cfe43
Compare
@swift-ci test |
Build failed |
b5be2e3
to
e999492
Compare
@swift-ci test |
@swift-ci test |
Build failed |
@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.
This lgtm now. Thanks for all your work on this :)
auto *innerBorrow = | ||
reborrowBuilder.createBeginBorrow(bi->getLoc(), innerCopy); | ||
auto *outerEndBorrow = reborrowBuilder.createEndBorrow(bi->getLoc(), value); | ||
SILLocation loc = RegularLocation(bi->getLoc().getSourceLoc()); |
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.
Nit: couldn't this just be bi->getLoc()
?
lib/SILOptimizer/Transforms/CSE.cpp
Outdated
@@ -1284,22 +1372,32 @@ class SILCSE : public SILFunctionTransform { | |||
auto *SEA = PM->getAnalysis<SideEffectAnalysis>(); | |||
SILOptFunctionBuilder FuncBuilder(*this); | |||
|
|||
CSE C(RunsOnHighLevelSil, SEA, FuncBuilder); | |||
auto *func = getFunction(); | |||
SILOpenedArchetypesTracker OpenedArchetypesTracker(func); |
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.
Nit: camelCase
not TitleCase
.
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.
Some additional comments. I need to read this locally before giving it my +1. I am doing that now.
lib/SILOptimizer/Transforms/CSE.cpp
Outdated
auto Operands = X->getOperandValues(); | ||
SmallVector<SILValue, 4> OperandValues; | ||
llvm::transform( | ||
Operands, std::back_inserter(OperandValues), |
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.
One thought. Is it possible to create a range that does this transform and pass that to hash_combine instead? That way we do not intermediate arrays (and potential mallocs).
(Keep in mind I am just tagging this one, but I am talking about all of the places that this was done.
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.
I'll try to do this
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.
I added a transform function as an optional argument to SILInstruction::getOperandValues. It may be useful in other code as well.
@@ -73,6 +73,10 @@ Optional<SILBasicBlock::iterator> swift::getInsertAfterPoint(SILValue val) { | |||
if (isa<SingleValueInstruction>(val)) { |
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.
why not:
if (auto *inst = val->getDefiningInstruction()) {
return std::next(inst->getIterator());
}
@meg-gupta I was talking with Andy about this issue around ValueLifetimeAnalysis and returns. I think we are hacking around bugs here. We need a way to have a /real/ location given a terminator insert pt and value lifetime analysis should be smart enough about return inst. |
bool result = lifetimeAnalysis.computeFrontier( | ||
frontier, ValueLifetimeAnalysis::DontModifyCFG, &ctx.deBlocks); | ||
assert(result); | ||
bool noCriticalEdges = lifetimeAnalysis.computeFrontier( |
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.
I think this is the wrong way to do this. Why is this needed?
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.
Specifically, if it is needed due to the terminator issue we spoke about before, I think that Andy's recent change adding UnownedInstantaneousUse makes that not necessary for unowned things
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 are right, this was not needed. It turned out to be a bug where the ownership rauw was considering transitive uses of none ownership as well.
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.
More initial comments.
b97dbb1
to
138b4e8
Compare
…value/destroy_value etc Branch instructions and frontiers can have LocationKind::ReturnKind/ImplicitReturnKind which are not correct locations to use for copy_value/destroy_value etc
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.
Some more final comments! Looks pretty good! I think we are close!
@swift-ci test |
@swift-ci benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code 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
|
transformed values of the operands
…auw of guaranteed values When we are populating transitive users while handling guaranteed values in ownership rauw, we were including values with none ownership. Example : rauw of %2 with a dominating value Here %arg1 was also considered a transitive use %2 = struct_extract %0 : $StructWithEnum2, #StructWithEnum2.val %copy = copy_value %2 : $FakeOptional2 switch_enum %2 : $FakeOptional2, case #FakeOptional2.some1!enumelt:bb5, case #FakeOptional2.some2!enumelt:bb6 bb5(%arg1 : $UInt): br bb7(%arg1 : $UInt) bb6(%arg2 : @guaranteed $Klass): %4 = unchecked_trivial_bit_cast %arg2 : $Klass to $UInt br bb7(%4 : $UInt) This is incorrect because %arg1 is a trivial value, and this also leads to ValueLifetimeAnalysis needing a split for finding a frontier for the use of %arg1 in the branch instruction. In ossa, we should never have to split edges for finding frontiers, because we do not have critical edges.
@swift-ci test |
@swift-ci test |
@gottesmm I am merging this. I'll add a follow on commit if there are any other comments. |
Woohoo! So excited to see ownership making its way through the SILOptimizer. Thanks for all your work on this, @meg-gupta. |
No description provided.