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

Add absolute check for int/long to generate Abs nodes

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 15
    • 16
    • hotspot
    • b02
    • generic
    • generic

    Description

      For the following test case:
      public static int absi(int a) {
                return ((a < 0) ? -a : a);
        }

      The following 3 instructions are generated by C2 on AArch64.
      0x0000ffffa0b382d4: tbz w1, #31, 0x0000ffffa0b382f0
      0x0000ffffa0b382d8: neg w0, w1
      0x0000ffffa0b382f0: mov w0, w1

      But for the test case as follows:

      public static int absim(int a) {
                return (int)Math.abs(a);
        }

      Only two instructions are used on AArch64.
      0x0000ffffa0b385d4: cmp w1, wzr
      0x0000ffffa0b385d8: cneg w0, w1, lt

      There is absolute value check for float/double ((a <= 0.0f) ? (0.0f - a) : a);
      http://hg.openjdk.java.net/jdk/jdk/file/dd652a1b2a39/src/hotspot/share/opto/cfgnode.cpp#l1519

      Integer/long absolute value check can also be added. So that pattern " ((a < 0) ? -a : a)" or "((a > 0) ? a : -a)" can be optimized to AbsI/AbsL.

      Attachments

        Issue Links

          Activity

            People

              yzhang Yang Zhang
              yzhang Yang Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: