Fix performance problem in LLVM JumpThreading #25630
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is https://reviews.llvm.org/D42262 upstream. When we emit
unboxed unions, we tend to emit
switch
instructions on a smallinteger which serves as a marker for which of types is currently active,
so we often emit things like:
In many situations the operation in the middle can get optimized away,
so we want to merge the two union split sections into one. LLVM's
jump threading pass can do this by keeping track of how control flow
behaves across a given basic block. Unfortunately, this optimization
wasn't taking effect. This is because InstCombine realized that the
range of possible values was rather small and turned the above into
something like:
which JumpThreading refused to look through (because of the i2 rather
than the i1). The included patch fixes this. On recent LLVM, we
additionally need https://reviews.llvm.org/D42260, for cases where
a union split branch happens to target a loop header. However,
LLVM 3.9.1 does not include the original commit that regressed that.
This fixes a number of the performance regressions seen in #25261.