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

Hannes Greule hgreule at openjdk.org
Tue Sep 23 21:07:00 UTC 2025


On Tue, 23 Sep 2025 14:12:40 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:

>> 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.

The comment comes from the original code before my change in #25254, where that path also returned `POS` but that wasn't monotonic with my changes anymore.

> So, if a divisor becomes 0, it means the node is effectively dead and can go away.

I think this check mostly comes down to CCP. We need to return *something* for a zero divisor, and that something has to be monotonic with subsequent wider inputs.

If you agree with that observation, I can change the comment to better reflect what's going on, e.g., `Mod by zero can be observed in PhaseCCP, return TOP to ensure monotonic results` (I'm open for other suggestions).

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

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


More information about the hotspot-compiler-dev mailing list