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

Christian Hagedorn chagedorn at openjdk.org
Fri Mar 28 10:25:44 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

During testing, I've noticed that one of my new tests failed with `-XX:-UseLoopPredicate -XX:-UseCompressedOops`. The reason was that we still have some `UseLoopPredicate` guards in place for Assertion Predicate handling. But this is not correct: We could also insert new Template Assertion Predicates with Range Check Elimination. When then turning such a main loop in a normal loop again with peeling (which happens in one of the test cases), we also need to update these Assertion Predicates - but we don't do that due to the `UseLoopPredicate` guards. We should remove these.

I've added another `-XX:-UseLoopPredicate` run that uses `-Xcomp` but did not add ` -XX:-UseCompressedOops`. This allows us to get more diverse coverage in the CI with different flag combos on top.

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

PR Comment: https://git.openjdk.org/jdk/pull/24246#issuecomment-2760843363


More information about the hotspot-compiler-dev mailing list