RFR: 8350329: C2: Div looses dependency on condition that guarantees divisor not zero in counted loop after peeling

Christian Hagedorn chagedorn at openjdk.org
Fri May 16 09:32:01 UTC 2025


On Fri, 16 May 2025 08:28:20 GMT, Roland Westrelin <roland at openjdk.org> wrote:

> This is an issue similar to 8349139: the type of the iv phi of a
> counted loop is narrowed down so a `Div` node doesn't need a control
> input. The loop is then peeled. The `Div` in the loop body is
> guaranteed to be non zero only if it is actually executed so the `Div`
> is implicitly dependent on the zero trip guard. Then the loop looses
> its backedge and the `Div` freely floats. The `Div` instruction is
> scheduled above the zero trip guard and faults. Had the `Div` been
> control dependent on the zero trip guard, it wouldn't have
> executed. The fix, similar to 8349139 is to add a `CastII` on peeling
> to make the dependency between what's in the loop body and relies on
> the narrowed down type of the iv phi and the zero trip guard explicit.

Looks good to me.

test/hotspot/jtreg/compiler/controldependency/TestPeeledLoopNoBackedgeFloatingDiv.java line 29:

> 27:  * @summary C2: Div looses dependency on condition that guarantees divisor not zero in counted loop after peeling
> 28:  * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseLoopPredicate -XX:+StressGCM -XX:StressSeed=31780379 TestPeeledLoopNoBackedgeFloatingDiv
> 29:  * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseLoopPredicate -XX:+StressGCM TestPeeledLoopNoBackedgeFloatingDiv

You should use `-XX:+UnlockDiagnosticVMOptions` for `StressGCM` and maybe also add `-XX:+IgnoreUnrecognizedVMOptions` when run without C2 since `UseLoopPredicate` is a C2 only flag.

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

Marked as reviewed by chagedorn (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/25262#pullrequestreview-2846080792
PR Review Comment: https://git.openjdk.org/jdk/pull/25262#discussion_r2092696865


More information about the hotspot-compiler-dev mailing list