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

Unnecessary sign extension for byte array access

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b64

      Backports

        Description

        C2 adds an unnecessary sign extension while compiling a byte array access.

          public static byte[] byteArr;
            
          public static byte accessByte(int index) {
            return byteArr[index];
          }

        The generated code contains:

          0x00007f76f4747208: movslq %esi,%r11
          0x00007f76f474720b: movsbl 0x10(%r10,%r11,1),%eax

        Where the 'movslq' instruction is not necessary because we emit range checks guaranteeing that index %esi is not negative.

        For a char array access no such sign extension is created:

          public static char[] charArr;
            
          public static char accessChar(int index) {
            return charArr[index];
          }

          0x00007fab3916b188: movzwl 0x10(%r10,%rsi,2),%eax

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                thartmann Tobias Hartmann
                Reporter:
                thartmann Tobias Hartmann
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: