There is absolute value check for float/double.
http://hg.openjdk.java.net/jdk/jdk/file/dd652a1b2a39/src/hotspot/share/opto/cfgnode.cpp#l1519
But it doesn't work both on AArch64 and x86.
Test case:
public static float absf(float a) {
return ((a <= 0.0f) ? 0.0f - a : a);
}
Assembly generated by c2 on AArch64:
0x0000ffff8cb3c054: fmov s17, wzr
0x0000ffff8cb3c058: fcmp s17, s0
0x0000ffff8cb3c05c: b.lt 0x0000ffff8cb3c078
0x0000ffff8cb3c060: fsub s0, s17, s0
0x0000ffff8cb3c078: fcmp s17, s0
0x0000ffff8cb3c07c: csetm w10, ne // ne = any
0x0000ffff8cb3c080: cneg w10, w10, ge // ge = tcont
In this code snippet, pattern CmpF3 is matched. But it isn't expected.
We expect that pattern AbsF can be matched.
For example, Math.abs(float) is used.
public static float absfm(float a) {
return Math.abs(a);
}
Assembly generated by c2 on AArch64:
0x0000ffff80b3c0d4: fabs s0, s0
http://hg.openjdk.java.net/jdk/jdk/file/dd652a1b2a39/src/hotspot/share/opto/cfgnode.cpp#l1519
But it doesn't work both on AArch64 and x86.
Test case:
public static float absf(float a) {
return ((a <= 0.0f) ? 0.0f - a : a);
}
Assembly generated by c2 on AArch64:
0x0000ffff8cb3c054: fmov s17, wzr
0x0000ffff8cb3c058: fcmp s17, s0
0x0000ffff8cb3c05c: b.lt 0x0000ffff8cb3c078
0x0000ffff8cb3c060: fsub s0, s17, s0
0x0000ffff8cb3c078: fcmp s17, s0
0x0000ffff8cb3c07c: csetm w10, ne // ne = any
0x0000ffff8cb3c080: cneg w10, w10, ge // ge = tcont
In this code snippet, pattern CmpF3 is matched. But it isn't expected.
We expect that pattern AbsF can be matched.
For example, Math.abs(float) is used.
public static float absfm(float a) {
return Math.abs(a);
}
Assembly generated by c2 on AArch64:
0x0000ffff80b3c0d4: fabs s0, s0
- relates to
-
JDK-8244926 Add absolute check for int/long to generate Abs nodes
-
- Resolved
-