JDK-8312213 : Remove unnecessary TEST instructions on x86 when flags reg will already be set
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-07-11
  • Updated: 2023-09-07
  • Resolved: 2023-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b14Fixed
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
HotSpot C2 currently sometimes emits TEST instrutions that operate on the result and of a AND, XOR or OR instruction and are their immediate successor.
This pattern can emerge if the result of the and is compared against two values where one of the values is zero. The matcher does not have the capability to know that the instruction mentioned above also set the flag register to the correct value.
According to https://www.felixcloutier.com/x86/and, https://www.felixcloutier.com/x86/xor, https://www.felixcloutier.com/x86/or and https://www.felixcloutier.com/x86/test the flags are set to same values for TEST, AND, XOR and OR, so this should be safe.
By adding peephole rules to remove the TEST instructions, the resulting assembly code can be shortend and a small speedup can be observed.
I've already created a PR for this: https://github.com/openjdk/jdk/pull/14172



Comments
Changeset: aba89f20 Author: Tobias Hotz <tobias.hotz@hotmail.de> Committer: Jorn Vernee <jvernee@openjdk.org> Date: 2023-09-05 22:08:20 +0000 URL: https://git.openjdk.org/jdk/commit/aba89f20bfce4de5ef034fed30b3b461fc715ba5
05-09-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14172 Date: 2023-05-26 10:32:00 +0000
24-07-2023

This is an enhancement request, moving it to Dev team for analysis: https://github.com/openjdk/jdk/pull/14172
18-07-2023