Skip to content

SIL: fix problems in findJointPostDominatingSet and some refactoring #35684

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

Merged
merged 3 commits into from
Feb 2, 2021

Conversation

eeckstein
Copy link
Contributor

  1. dead-end blocks (= blocks which eventually end up in an unreachable):

We cannot just ignore all dead-end blocks. This causes crashes for some corner cases (see the "infinite_loop_and_unreachable" test case). Instead just handle the common case of a simple single dead-end block - like we do in DestroyHoisting.
For other (more complex) dead-end control flows, the analysis is not incorrect. In worst case we end up inserting a not-needed destroy instruction.

  1. sortUnique

I restructured the code a bit so that sortUnique is not needed anymore. sortUnique on pointer arrays can result in non-deterministic behavior.

  1. lower_bound

Also, using lower_bound on a vector is not good in this function, because it can result in quadratic behavior. Though, in practice, there are only very few elements in the vector. So it's more a theoretical thing.

The restructuring made the code a bit simpler, e.g. beside the worklist, no other vectors are needed anymore.

Also in this PR: remove the JointPostDominanceSetComputer helper struct.
Instead make findJointPostDominatingSet a stand-alone function.
There is no need to keep the temporary SmallVector alive across multiple calls of findJointPostDominatingSet for the purpose of re-using malloc'ed memory. The worklist usually contains way less elements than its small size.

@eeckstein eeckstein requested a review from gottesmm February 1, 2021 14:55
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein changed the title SIL: fix some problems in findJointPostDominatingSet some refactoring SIL: fix some problems in findJointPostDominatingSet and some refactoring Feb 1, 2021
@eeckstein eeckstein changed the title SIL: fix some problems in findJointPostDominatingSet and some refactoring SIL: fix problems in findJointPostDominatingSet and some refactoring Feb 1, 2021
@swift-ci
Copy link
Contributor

swift-ci commented Feb 1, 2021

Build failed
Swift Test OS X Platform
Git Sha - 409c82a7aa3b559b73c2b06b9b21cf30d61661d9

@@ -390,7 +390,15 @@ void DeadEndBlocks::compute() {
// Post Dominance Set Completion Utilities
//===----------------------------------------------------------------------===//

void JointPostDominanceSetComputer::findJointPostDominatingSet(
static bool endsInUnreachable(SILBasicBlock *block) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor out the immediate logic related to this in DeadEndBlocks (maybe into a helper static function?) and use that here so we have one implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why not just use dead end blocks here? I want @atrick to also look at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I moved it to a static utility function in DeadEndBlocks.

Also why not just use dead end blocks here?

Because it causes the problems I try to fix. E.g. in case the original dominatingBlock is already a dead-end block.

@gottesmm gottesmm requested a review from atrick February 1, 2021 23:49
1. dead-end blocks (= blocks which eventually end up in an unreachable):

We cannot just ignore all dead-end blocks. This causes crashes for some corner cases (see the "infinite_loop_and_unreachable" test case). Instead just handle the common case of a simple single dead-end block - like we do in DestroyHoisting.
For other (more complex) dead-end control flows, the analysis is not incorrect. In worst case we end up inserting a not-needed destroy instruction.

2. sortUnique

I restructured the code a bit so that sortUnique is not needed anymore. sortUnique on pointer arrays can result in non-deterministic behavior.

3. lower_bound

Also, using lower_bound on a vector is not good in this function, because it can result in quadratic behavior. Though, in practice, there are only very few elements in the vector. So it's more a theoretical thing.

The restructuring made the code a bit simpler, e.g. beside the worklist, no other vectors are needed anymore.
Instead make `findJointPostDominatingSet` a stand-alone function.
There is no need to keep the temporary SmallVector alive across multiple calls of findJointPostDominatingSet for the purpose of re-using malloc'ed memory. The worklist usually contains way less elements than its small size.
@eeckstein
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor

gottesmm commented Feb 2, 2021

@swift-ci test windows platform

@gottesmm
Copy link
Contributor

gottesmm commented Feb 2, 2021

ErikE and I were talking about some other changes here. Around transitive dead end blocks. The implementation change here will be more conservative. I wouldn't be surprised by using the dead end blocks utility we can get a more aggressive result but given that this is fixing a real issue. I want to merge it/iterate later.

@gottesmm
Copy link
Contributor

gottesmm commented Feb 2, 2021

@swift-ci test windows platform

@gottesmm
Copy link
Contributor

gottesmm commented Feb 2, 2021

Some sort of problem in the windows build that isn't from this (has something to do with parsing or the system itself). Merging!

@gottesmm gottesmm merged commit b16f340 into swiftlang:main Feb 2, 2021
@eeckstein eeckstein deleted the fix-find-jpds branch February 3, 2021 07:10
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.

3 participants