RFR: 8350577: Fix missing Assertion Predicates when splitting loops [v2]

Emanuel Peter epeter at openjdk.org
Thu Mar 27 08:12:07 UTC 2025


On Thu, 27 Mar 2025 08:09:55 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 rest...
>
> Christian Hagedorn has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fixing test failure 8353019

@chhagedorn Amazing work! This really took a lot of patience and persistence, but you did it!

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

Marked as reviewed by epeter (Reviewer).

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


More information about the hotspot-compiler-dev mailing list