-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix ExistentialSpecializer bugs for swiftpm and enable existential-specializer for sil-opt #20617
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
@slavapestov fix for swiftpm bugs.. |
df27d8f
to
29cbac7
Compare
@slavapestov test cases added and made into a single commit. Can you check this one? |
@slavapestov can you check this one now? |
ffd2d6f
to
6e32c8d
Compare
@@ -101,7 +101,8 @@ static bool findConcreteType(ApplySite AI, int ArgIdx, CanType &ConcreteType) { | |||
SILValue InitExistential = | |||
findInitExistentialFromGlobalAddrAndApply(GAI, AI, ArgIdx); | |||
/// If the Arg is already init_existential, return the concrete type. | |||
if (findConcreteTypeFromInitExistential(InitExistential, ConcreteType)) { | |||
if (InitExistential && |
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 fixes the case where global_addr analysis can not find an init_existential. See "global_addr_init" test case below.
@@ -257,6 +258,12 @@ bool ExistentialSpecializer::canSpecializeCalleeFunction(ApplySite &Apply) { | |||
if (Callee->getInlineStrategy() == Inline_t::AlwaysInline) | |||
return false; | |||
|
|||
/// Ignore externally linked functions with public_external or higher | |||
/// linkage. | |||
if (isAvailableExternally(Callee->getLinkage())) { |
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 fixes the swiftpm bug related to external linkage functions causing name mangling issues. See test case: s7dealloc20wrap_foo_ncp_another1aSiAA1P_pz_tF below.
ReturnInsts.insert(RI); | ||
} | ||
/// Find the set of return instructions in a function. | ||
for (auto &BB : NewF) { |
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 fixes the old code that was inserting dealloc_stack after destroy_addr which is wrong. dealloc_stack are now inserted just before return instructions. See test case: $s7dealloc12wrap_foo_ncp1a1bSiAA1P_pz_AaE_pztFTf4ee_n below.
include/swift/AST/SILOptions.h
Outdated
@@ -51,7 +51,7 @@ class SILOptions { | |||
bool RemoveRuntimeAsserts = false; | |||
|
|||
/// Enable existential specializer optimization. | |||
bool ExistentialSpecializer = false; | |||
bool ExistentialSpecializer = true; |
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.
default enable of ExistentialSpecializer.
Can you file a separate PR with the bug fixes before we enable this by default? |
@swift-ci Please test |
@swift-ci Please test source compatibility |
@swift-ci Please benchmark |
Build failed |
Build failed |
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
How 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
|
I notice that you ran tests. Do you still suggest I need to separate them into two PRs -- one with just ExistentialSpecializer set to true in SILOptions (this exists here #19820) and another with all bug fixes (I can modify this one to remove the set to ExistentialSpecializer=true)? A question: if I do not set "ExistentialSpecializer=true" in SILOptions.h, ExistentialSpecializer does not get invoked with sil-opt using the "-existential-specializer" (aka, "// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -existential-specializer | %FileCheck %s") used in my test case existential_transform_extras.sil. How do I enable this at sil-opt level? |
@slavapestov anything for me here? |
Since we have performance regressions here, I’d like you to merge the bug fixes separately. Did you figure out how to get the tests to pass even when the flag is off? |
Looking at Performance regression with -O for StringEqualPointerComparison: |
Similarly, none of the regressed one have anything to do with protocols. What am I missing? |
…ecializer in sil-opt
6e32c8d
to
c4df82b
Compare
@@ -167,6 +167,11 @@ static llvm::cl::opt<int> | |||
SILInlineThreshold("sil-inline-threshold", llvm::cl::Hidden, | |||
llvm::cl::init(-1)); | |||
|
|||
static llvm::cl::opt<bool> | |||
SILExistentialSpecializer("enable-sil-existential-specializer", |
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.
Add a flag to enable and disable existential-specializer from sil-opt.
@@ -328,6 +333,7 @@ int main(int argc, char **argv) { | |||
// Setup the SIL Options. | |||
SILOptions &SILOpts = Invocation.getSILOptions(); | |||
SILOpts.InlineThreshold = SILInlineThreshold; | |||
SILOpts.ExistentialSpecializer = SILExistentialSpecializer; |
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.
Store it in the module's Options.
OK. I committed some more changes to make it independent:
|
@slavapestov can we run tests on this one and accept these changes quickly? The default enabler of ExistentialSpecializer is a separate PR at #19820 |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please smoke test Linux |
No description provided.