Skip to content

[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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jamieQ
Copy link
Contributor

@jamieQ jamieQ commented Jun 17, 2025

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.

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.
@jamieQ
Copy link
Contributor Author

jamieQ commented Jun 17, 2025

@swift-ci please smoke test

@jamieQ
Copy link
Contributor Author

jamieQ commented Jun 17, 2025

@swift-ci please test compiler performance

@jamieQ
Copy link
Contributor Author

jamieQ commented Jun 17, 2025

@swift-ci Please smoke test compiler performance

1 similar comment
@jamieQ
Copy link
Contributor Author

jamieQ commented Jun 17, 2025

@swift-ci Please smoke test compiler performance

Copy link
Contributor

@nate-chandler nate-chandler left a 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.

Copy link
Contributor

@nate-chandler nate-chandler left a 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;
Copy link
Contributor Author

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.

Copy link
Contributor

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"

Copy link
Contributor

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.

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.

2 participants