Ashay Rane a666f9e2a0
8256951: C2: Reuse cmp condition codes in adjacent basic blocks
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.
2026-03-27 09:29:19 +00:00
2016-05-30 16:17:11 +02:00
2024-09-25 16:25:23 +00:00

Welcome to the JDK!

For build instructions please see the online documentation, or either of these files:

See https://openjdk.org/ for more information about the OpenJDK Community and the JDK and see https://bugs.openjdk.org for JDK issue tracking.

Languages
Java 73.9%
C++ 14.1%
C 7.9%
Assembly 2.7%
Objective-C 0.4%
Other 0.8%