C2: Reuse cmp condition codes in adjacent basic blocks#45
Draft
raneashay wants to merge 2 commits intomicrosoft:mainfrom
Draft
C2: Reuse cmp condition codes in adjacent basic blocks#45raneashay wants to merge 2 commits intomicrosoft:mainfrom
raneashay wants to merge 2 commits intomicrosoft:mainfrom
Conversation
C2 always emits instructions for evaluating the condition prior to the branch that uses it, but when the code contains a chain of if-else statements whose predicates compare the same two values or if the code contains a switch-case statement, the generated assembly often includes repeated instructions that compare the same two values prior to each branch, even if the condition codes between the comparison instructions have not changed. This patch adds a peephole optimization to the X64 backend to recognize such redundant instructions and to remove the instruction in the successor block when the condition codes can be reused. C2 applies this optimization after conservative checks (single predecessor block, no intermediate instructions that modify condition codes, and identical instructions). This patch enables the peephole opimization for signed and unsigned, and integer and long comparsion instructions. This optimization should also be applicable to float and double comparison instructions on X64, but this patch does not enable the optimization for those instructions, since writing tests for those cases is made difficult by a different optimization that rewrites one of the two comparison instruction with swapped operands, causing this patch's conservative equivalence checks between instructions to fail, thus skipping the optimization.
This patch rehouses the peephole optimization from the previous patch so
that it can be enabled on both X64 and AArch64 targets. Specifically,
this patch introduces a new class (`WindowOpt`) that contains the logic
for the peephole optimization, so that the target-specific `Peephole`
class implementation can call into the newly-introduced `WindowOpt`'s
method.
Since Peephole optimizations were blanket disabled on the AArch64 target
prior to this patch, this patch makes a few cursory to changes to enable
them. First, this patch updates c2_globals_aarch64.hpp to enable
`OptoPeephole` and `OptoScheduling` by default. Second,
peephole_aarch64.{cpp,hpp} introduces a `Peephole` class that is
compiled only on the AArch64 target. Finally, this newly introduced
`Peephole` class calls into the method in `WindowOpt` that works for
both X64 and AArch64 targets.
As a final change, this patch updates the IR tests introduced in the
previous patch to now run on both X64 and AArch64 targets. Local test
runs show that all Tier 1, Tier 2, and Tier 3 HotSpot tests pass in both
Release and FastDebug build configurations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR contains two commits:
and