Skip to content

PR for llvm/llvm-project#66868 #705

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 2 commits into from
Sep 27, 2023
Merged

PR for llvm/llvm-project#66868 #705

merged 2 commits into from
Sep 27, 2023

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Sep 21, 2023

The in-loop successor is only on the left after a potential condition
inversion. As we re-use the old condition as-is, we should also
reuse the old successors as-is.

Fixes llvm/llvm-project#63962.

(cherry picked from commit afd7db48c55cb87566758e961f1ebac8af16b8bc)
When unswitching via invariant condition injection, we currently
mark the condition in the old loop, so that it does not get
unswitched again. However, if there are multiple branches for
which conditions can be injected, then we can do that for both
the old and new loop. This means that the number of unswitches
increases exponentially.

Change the handling to be more similar to partial unswitching,
where we instead mark the whole loop, rather than a single
condition. This means that we will only generate a linear number
of loops.

TBH I think even that is still highly undesirable, and we should
probably be unswitching all candidates at the same time, so that
we end up with only two loops. But at least this mitigates the
worst case.

The test case is a reduced variant that generates 1700 lines of IR
without this patch and 290 with it.

Fixes llvm/llvm-project#66868.

(cherry picked from commit 8362cae71b80bc43c8c680cdfb13c495705a622f)
@tru
Copy link
Contributor

tru commented Sep 25, 2023

@nikic good to merge into 17.0.1?

@nikic
Copy link
Contributor

nikic commented Sep 26, 2023

Yeah, this fixes some compiler hangs we've encountered in the wild.

@tru tru merged commit 2839aa9 into release/17.x Sep 27, 2023
@tru tru deleted the llvm-issue66868 branch September 27, 2023 15:53
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.

Infinite/exponential loop unswitch due to invariant condition injection
3 participants