RFR: 8324720: Instruction selection does not respect -XX:-UseBMI2Instructions flag
Saranya Natarajan
duke at openjdk.org
Fri May 23 22:17:03 UTC 2025
While executing a function performing `a >> b` operation with `–XX:-UseBMI2Instructions` flag, the generated code contains BMI2 instruction `sarx eax,esi,edx`. The expected output should not contain any BMI2 instruction.
### Analysis and solution
As suggested by @merykitty in [JDK-8324720](https://bugs.openjdk.org/browse/JDK-8324720) , the initial idea was to make `VM_Version::supports_bmi2()` respect` UseBMI2Instructions `flag by disabling BMI2 feature when `UseBMI2Instructions` runtime flag is explicitly set to false. This fix is similar to how other runtime flags such as, `UseAPX` and `UseAVX`, enable or disable specific code and register set. However, some test failures were encountered while running tests on this fix.
The first set of failures were caused by assertion check on `VM_Version::supports_bmi2()` statement while generating some BMI2 specific instructions. This was caused by the stub generator generating AVX-512 specific code that uses these BMI2 instructions. It should be noted that the `UseAVX` flag is set by default to the highest supported version available in x86 machine). This in turn allows AVX-512 specific code generation whenever possible. In order to not comprise the performance benefits of using AVX-512, the proposed fix only disables BMI2 feature if AVX-512 features are also disabled (or not available in the machine) along with the UseBMI2Instructions flag.
The second failure occured in `compiler/intrinsics/sha/cli/TestUseSHA512IntrinsicsOptionOnSupportedCPU.java` where a warning "_Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU_." was returned on a AMD64 machine that had support for SHA512. Looking into `compiler/testlibrary/sha/predicate/IntrinsicPredicates.java` it was found that the predicate for AMD64 was not in line with the changes introduced by [JDK-8341052](https://bugs.openjdk.org/browse/JDK-8341052) in commit [85c1aea](https://github.com/openjdk/jdk/pull/20633/commits/85c1aea90b10014aa34dfc902dff2bfd31bd70c0) .
-------------
Commit messages:
- fix
Changes: https://git.openjdk.org/jdk/pull/25415/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=25415&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8324720
Stats: 11 lines in 2 files changed: 8 ins; 1 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/25415.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25415/head:pull/25415
PR: https://git.openjdk.org/jdk/pull/25415
More information about the hotspot-dev
mailing list