RFR: 8366815: C2: Delay Mod/Div by constant transformation
Manuel Hässig
mhaessig at openjdk.org
Wed Oct 22 15:21:12 UTC 2025
On Sun, 19 Oct 2025 15:46:06 GMT, Hannes Greule <hgreule at openjdk.org> wrote:
> The test cases show examples of code where `Value()` previously wasn't run because idealization took place before, resulting in less precise type analysis.
>
> Please let me know what you think.
Thinking about it a bit more, I think your fix is too superficial. If the discovery of the constant is slightly delayed, nothing is folded again. Consider the followig program for an example:
class Test {
static boolean test(int x, boolean flag) {
Integer a;
if (flag) {
a = 171384;
} else {
a = 2902;
}
return x % a >= a;
}
public static void main(String[] args) {
for (int i = 0; i < 20000; i++) {
if (test(i, false)) {
throw new RuntimeException("wrong result");
}
}
}
}
In my opinion, the benefits do not outweigh the drawbacks for this PR. A better solution would probably be to delay the expansion of the Mod and Div nodes to post-loop optimizations and extend Superword to expand Div/Mod nodes to shifts. However, this is quite a bit of complexity, which raises if this complexity is worth it (@eme64 probably has opinions and/or guidance on this).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27886#issuecomment-3432972151
More information about the hotspot-compiler-dev
mailing list