RFR: 8367967: C2: "fatal error: Not monotonic" with Mod nodes [v3]

Vladimir Ivanov vlivanov at openjdk.org
Tue Sep 23 14:15:38 UTC 2025


On Tue, 23 Sep 2025 08:28:00 GMT, Hannes Greule <hgreule at openjdk.org> wrote:

>> Generally, we shouldn't return a wider type (ZERO) if there is a later case that would return a more narrow type (TOP) for the same input types. If the inputs are widened and the first case doesn't match anymore but the later one still does, the result is not monotonic with the previous result.
>> 
>> Please review :)
>
> Hannes Greule has updated the pull request incrementally with one additional commit since the last revision:
> 
>   move test

src/hotspot/share/opto/divnode.cpp line 1209:

> 1207:   if (t2 == Type::TOP) { return Type::TOP; }
> 1208: 
> 1209:   // Mod by zero?  Throw exception at runtime!

The comment is a bit confusing. It's not the node itself which produces the exception, but a dominating zero check (inserted during parsing). So, if a divisor becomes 0, it means the node is effectively dead and can go away.  

Also, the node should go away anyway as part of CFG pruning of dead branches when corresponding guard goes away. 

BTW if there are cases when control is not eliminated, it may irrevocably break the IR causing crashes down the road (take a look at JDK-8154831 as an example). So, maybe it's safer to just rely on dead control pruning to eliminate effectively dead ModI/ModL nodes and assert that there are no effectively dead ModI/ModL nodes present after GVN pass is over.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27408#discussion_r2372479648


More information about the hotspot-compiler-dev mailing list