mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-28 16:50:10 +00:00
C2 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.
Welcome to the JDK!
For build instructions please see the online documentation, or either of these files:
- doc/building.html (html version)
- doc/building.md (markdown version)
See https://openjdk.org/ for more information about the OpenJDK Community and the JDK and see https://bugs.openjdk.org for JDK issue tracking.
Description
Languages
Java
73.9%
C++
14.1%
C
7.9%
Assembly
2.7%
Objective-C
0.4%
Other
0.8%