Integrated: 8350577: Fix missing Assertion Predicates when splitting loops
Christian Hagedorn
chagedorn at openjdk.org
Mon Mar 31 07:41:12 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 pull request has now been integrated.
Changeset: 25925138
Author: Christian Hagedorn <chagedorn at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/25925138b0a7d781d9293e52a8c9520329a85219
Stats: 1821 lines in 5 files changed: 1711 ins; 39 del; 71 mod
8350577: Fix missing Assertion Predicates when splitting loops
Reviewed-by: epeter, kvn
-------------
PR: https://git.openjdk.org/jdk/pull/24246
More information about the hotspot-compiler-dev
mailing list