RFR: 8350577: Fix missing Assertion Predicates when splitting loops

Vladimir Kozlov kvn at openjdk.org
Wed Mar 26 18:48:13 UTC 2025


On Wed, 26 Mar 2025 09:21:50 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

> _Note: The actual fix is only ~80 changed lines - everything else is about tests._
> 
> After integrating many preparatory sub-tasks, I'm finally fixing the last outstanding Assertion Predicate issues with this patch.
> 
> For more background about Assertion Predicates, have a look at the following [blog post](https://chhagedorn.github.io/jdk/2023/05/05/assertion-predicates.html).
> 
> ### Maintain Assertion Predicates when Splitting a Loop
> When performing Loop Predication on a counted loop, we create two Template Assertion Predicates for each hoisted range check. Whenever we split this loop as part of loop opts, we need to establish the Template Assertion Predicates at the new sub loops with the new loop init and stride and create Initialized Assertion Predicates from them. This ensures that a sub loop is folded when it becomes dead due to an impossible condition (e.g. always having a negative index for the hoisted range check in all loop iterations).
> 
> #### Current State
> Today, we are already covering most of the cases where Assertion Predicates are required - but we are still missing some. The following table describes the current state for the different loop splitting optimizations:
> 
> | Loop Optimization | Template Assertion Predicate | Initialized Assertion Predicate |
> | ------------------------ | --------------------------------------- | --------------------------------------- |
> | Create Main Loop | ✅                |  ✅  |
> | Create Post Loop  | ❌                |   ✅  |
> | Loop Unswitching  | ✅                | _not required, same init, stride and, limit_  |
> | Loop Unrolling       | ✅                |  ✅ | 
> | Range Check Elimination | ✅     | ✅ |
> | Loop Peeling         | ❌                                            |  ✅ |
> | Splitting Main Loop | ❌                                        | ❌ |
> 
> Whenever we apply a loop optimization that does not establish Template Assertion Predicates, then all subsequent loop splitting optimizations on that loop cannot establish Template Assertion Predicates, either,  and we fail to emit Initialized Assertion Predicates which can lead to a broken graph.
> 
> #### Fixing Unsupported Cases
> This patch provides fixes for the remaining unsupported cases as shown in the table above. With all the work done in previous PRs, the fix is quite straight forward: 
> - Remove the restriction that we don't clone Template Assertion Predicate in Loop Peeling and post loop creation.
> - Remove the restriction that we only clone Template Assertion Predicate ...

This simplifies the code. Good.

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

Marked as reviewed by kvn (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/24246#pullrequestreview-2718305992


More information about the hotspot-compiler-dev mailing list