Loading... (original) (raw)

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