[code-reflection] RFR: Implement shift ops
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Apr 18 17:13:15 UTC 2024
On Thu, 11 Apr 2024 22:07:23 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
> am uncomfortable with these binary operations have different operand integral types in some cases (long << int, or int << long). It may be better to more uniform for the compiler generated code models and insert conversion operations (which i believe should not change program meaning, and we can optimize for bytecode generation). @mcimadamore WDYT?
Sorry, I missed this comment. It would seem more in the spirit of what we're trying to do to use types that are close to the source types, and then introduce conversions as required. That is, if I have this:
void test(int x, long l) {
int i = x << l;
}
The generated bytecode is this:
stack=3, locals=5, args_size=3
0: iload_1
1: lload_2
2: l2i // conversion!
3: ishl // int shift!
4: istore 4
6: return
As you can see, the compiler assumes we want an int shift, and then narrows the long operand into an int. This is different from what happens for all the other binary ops (e.g. for `+` we would have widened the int operand to long, and then used a long add).
As you can see, the bytecode contains no
-------------
PR Comment: https://git.openjdk.org/babylon/pull/49#issuecomment-2064602436
More information about the babylon-dev
mailing list