-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILOptimizer]: slow OSSA lifetime canonicalization mitigation #82313
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
base: main
Are you sure you want to change the base?
[SILOptimizer]: slow OSSA lifetime canonicalization mitigation #82313
Conversation
OSSA lifetime canonicalization can take a very long time in certain cases in which there are large basic blocks. to mitigate this, add logic to skip walking the liveness boundary for extending liveness extension to dead ends when there aren't any dead ends in the function.
@swift-ci please smoke test |
@swift-ci please test compiler performance |
@swift-ci Please smoke test compiler performance |
1 similar comment
@swift-ci Please smoke test compiler performance |
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.
Thank you for taking a stab at this @jamieQ ! I added a few comments.
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.
LGTM
@@ -68,6 +68,10 @@ class DeadEndBlocks { | |||
const SILFunction *f; |
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.
posting here for discussion threading purposes:
@nate-chandler any pointers as to where/what new tests should be added? i did confirm that an existing canonicalization test fails if the new hasAnyDeadEnds()
function is hard-coded to return false
, so it seems there is some existing coverage.
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.
Yeah, the existing coverage of canonicalization is sufficient, I think.
If you want, you could add a new FunctionTest
of the utility function DeadEndBlocks::isEmpty()
in BasicBlockUtils.cpp
. The full details for how to do that are in include/swift/SIL/Test.h
, but briefly you'd add something like
namespace swift::test {
FunctionTest HasAnyDeadEndBlocksTest("has_any_dead_dends",
[](auto &function, auto &arguments, auto &test) {
auto *deb = test.getDeadEndBlocks();
llvm::outs() << deb->isEmpty() ? "no dead ends\n" : "has dead ends\n";
});
} // end namespace swift::test
and then write a SIL test case
// test/SILOptimizer/dead-end-blocks.sil
// RUN: %target-sil-opt \
// RUN: -test-runner \
// RUN: %s \
// RUN: -sil-disable-input-verify \
// RUN: -o /dev/null \
// RUN: 2>&1 | %FileCheck %s
// CHECK-LABEL: begin running test {{.*}} on some_function_with_dead_ends
// CHECK: no dead ends
// CHECK-LABEL: end running test {{.*}} on some_function_with_dead_ends
sil @some_function_with_dead_ends ...
specify_test "has_any_dead_ends"
...
// CHECK-LABEL: begin running test {{.*}} on some_function_with_dead_ends
// CHECK: has dead ends
// CHECK-LABEL: end running test {{.*}} on some_function_with_dead_ends
sil @some_function_without_dead_ends ...
specify_test "has_any_dead_ends"
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.
If you want to add more canonicalization tests, they would go in test/SILOptimizer/canonicalize_ossa_lifetime_unit.sil
.
OSSA lifetime canonicalization can take a very long time in certain cases in which there are large basic blocks. to mitigate this, add logic to skip walking the liveness boundary for extending liveness to dead ends when there aren't any dead ends in the function.