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.
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.
- relates to
-
JDK-8248445 Use of AbsI / AbsL nodes should be limited to supported platforms
-
- Resolved
-
-
JDK-8247695 PPC/S390: compiler/intrinsics/math/TestFpMinMaxIntrinsics.java fails
-
- Resolved
-
-
JDK-8244927 Absolute value check for float/double doesn't work
-
- Closed
-