Skip to content

8324720: Instruction selection does not respect -XX:-UseBMI2Instructions flag #25415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sarannat
Copy link
Contributor

@sarannat sarannat commented May 23, 2025

Issue:

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 , the initial idea was to make VM_Version::supports_bmi2() respectUseBMI2Instructionsflag 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 in commit 85c1aea .


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8324720: Instruction selection does not respect -XX:-UseBMI2Instructions flag (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25415/head:pull/25415
$ git checkout pull/25415

Update a local copy of the PR:
$ git checkout pull/25415
$ git pull https://git.openjdk.org/jdk.git pull/25415/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25415

View PR using the GUI difftool:
$ git pr show -t 25415

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25415.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 23, 2025

👋 Welcome back sarannat! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 23, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8324720: Instruction selection does not respect -XX:-UseBMI2Instructions flag 8324720: Instruction selection does not respect -XX:-UseBMI2Instructions flag May 23, 2025
@openjdk
Copy link

openjdk bot commented May 23, 2025

@sarannat The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@sarannat sarannat marked this pull request as ready for review May 23, 2025 22:13
@openjdk openjdk bot added the rfr Pull request is ready for review label May 23, 2025
@mlbridge
Copy link

mlbridge bot commented May 23, 2025

Webrevs

@robcasloz
Copy link
Contributor

/cc hotspot-compiler

@openjdk
Copy link

openjdk bot commented May 26, 2025

@robcasloz
The hotspot-compiler label was successfully added.

Copy link
Contributor

@robcasloz robcasloz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change affects the final value of UseBMI2Instructions when the JVM is run with its default configuration on machines without AVX-512 (i.e. UseAVX <= 2), I guess that is unexpected?

My CPU flags:

$ cat /proc/cpuinfo | grep flags
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities

Before this change:

$ java -XX:+PrintFlagsFinal | grep UseBMI
     bool UseBMI1Instructions                      = true                                 {ARCH product} {default}
     bool UseBMI2Instructions                      = true                                 {ARCH product} {default}

With this change:

$ java -XX:+PrintFlagsFinal --version | grep BMI
     bool UseBMI1Instructions                      = true                                 {ARCH product} {default}
     bool UseBMI2Instructions                      = false                                {ARCH product} {default}

@merykitty
Copy link
Member

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.

This seems unreasonable, you are sacrificing correctness for performance. UseBMI2Instructions has the default value being true, and if UseBMI2Instruction is explicitly set to false, the VM should respect that.

@sarannat
Copy link
Contributor Author

sarannat commented May 28, 2025

Thank you for the review. My first approach to the fix was inline with your comments. I will go back and implement the changes based on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants