Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324720

Instruction selection does not respect -XX:-UseBMI2Instructions flag

XMLWordPrintable

      (Noticed by Joel Rudsberg during manual code inspection.)

      Run the following test with:
      $ java -Xcomp -XX:-UseBMI2Instructions -XX:CompileCommand=print,BMI.shift -XX:CompileCommand=dontinline,BMI.shift BMI.java

      class BMI {
          static int shift(int a, int b) {
              return a >> b;
          }

          public static void main(String[] args) {
              shift(42, 23);
          }
      }

      Expected: no BMI2 instructions in the generated code

      Actual: the generated code contains the BMI2 instruction sarx eax,esi,edx

      I believe the reason is that the definition of sarx and other BMI2 instructions in hotspot/cpu/x86/x86_64.ad is guarded by:

        predicate(VM_Version::supports_bmi2());

      which only checks the host CPU's flags. In contrast, BMI1 instructions in the same file are guarded by:

        predicate(UseBMI1Instructions);

      I believe the fix is to replace the predicates for BMI2 instructions with the corresponding

        predicate(UseBMI2Instructions);

      I can put together a PR if someone can confirm that this would be the correct fix.

            dlunden Daniel Lunden
            gbarany Gergö Barany
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: