RFR: 8344171: Clone and initialize Assertion Predicates in order instead of in reverse-order

Christian Hagedorn chagedorn at openjdk.org
Wed Nov 20 12:49:04 UTC 2024


(Note: This is a dependent PR on https://github.com/openjdk/jdk/pull/22136 which is not fully reviewed, yet, but I'd like to already send this PR out for review since I'm away for the rest of the week)

This patch changes the order in which we clone and initialize Assertion Predicates from "reverse-order" to "in-order".

#### Current State: Mostly "reverse-order" for Assertion Predicates
We are currently cloning and initializing Assertion Predicates in reverse-order out of convenience and simplicity for most of the loop splitting optimizations - except for Loop Unswitching (see next section). This means that we do the following:

                                     old target loop entry
                                               |
         x                         Cloned Template Assertion
         |                                Predicate 2
Template Assertion                             |
    Predicate 1                       Initialized Assertion
         |               ==>               Predicate 2
Template Assertion                             |
    Predicate 2                    Cloned Template Assertion
         |                                Predicate 1
    source loop                                |
                                      Initialized Assertion
                                           Predicate 1
                                               |
                                          target loop

I don't think this is wrong but still kinda unexpected when trying to reason about a graph. But now with the recent refactorings, I think it's easy to change this to an in-order processing:

                                     old target loop entry
                                               |
         x                          Cloned Template Assertion
         |                                Predicate 1
Template Assertion                             |
    Predicate 1                       Initialized Assertion
         |               ==>               Predicate 1
Template Assertion                             |
    Predicate 2                     Cloned Template Assertion
         |                                Predicate 2
    source loop                                |
                                      Initialized Assertion
                                           Predicate 2
                                               |
                                          target loop

 This will also align all cloning/initializing of Assertion Predicates to the same order which was not the case before: Loop Unswitching already had an in-order cloning.

#### Why Does Loop Unswitching Use In-Order?
The main reason was that we can reuse `create_new_if_for_predicate()` which allowed us to keep the UCT on the false path. Now that [JDK-8342047](https://bugs.openjdk.org/browse/JDK-8342047) is in, we no longer use this method because we are only using halt nodes on the false path and no UCTs anymore.

We could have flipped the order in Loop Unswitching to a reverse-order now. However, this is only possible for Assertion Predicates. Parse Predicates, which are also cloned during Loop Unswitching, still must keep their relative order. To do the cloning of Parse Predicates with the same predicate visitor and simplify the reasoning about a graph, I propose to switch to an in-order cloning/initialization for all the Assertion Predicates.

Thanks,
Christian

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

Depends on: https://git.openjdk.org/jdk/pull/22136

Commit messages:
 - Update comment
 - 8344171: Clone and initialize Assertion Predicates in order instead of in reverse-order

Changes: https://git.openjdk.org/jdk/pull/22275/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22275&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8344171
  Stats: 87 lines in 4 files changed: 41 ins; 33 del; 13 mod
  Patch: https://git.openjdk.org/jdk/pull/22275.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22275/head:pull/22275

PR: https://git.openjdk.org/jdk/pull/22275


More information about the hotspot-compiler-dev mailing list