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

Add absolute check for int/long to generate Abs nodes

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 16
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b02
    • CPU:
      generic
    • OS:
      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: