Skip to content
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

Bound the recursion depth of heuristic size_stmt in RTLgen #519

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

xavierleroy
Copy link
Contributor

The more_likely heuristic used in the RTLgen pass takes time O(n) where n is the size of the function and is called m times, where m = O(n) is the number of if-then-else statements in the function. This can result in O(n^2) behavior.

This PR avoids this problem by limiting the depth of recursive calls on if-then-else statements. It also puts a fixed upper limit on the return value of size_stmt, since comparing the sizes of two large statements is meaningless. (The interesting case performance-wise is when one of the statements is small.)

Limit recursive calls on if-then-else statements to avoid quadratic behaviors.

Also: put a fixed upper limit on the return value of size_stmt, since
large values of the size are meaningless and make the `more_likely` criterion
unstable.
@xavierleroy xavierleroy merged commit 8ce7997 into master Aug 22, 2024
2 of 7 checks passed
@xavierleroy xavierleroy deleted the size_stmt_heuristic branch August 22, 2024 08:20
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.

1 participant