RFR: 8350578: Refactor useless Parse and Template Assertion Predicate elimination code by using a PredicateVisitor

Christian Hagedorn chagedorn at openjdk.org
Fri Mar 14 10:08:04 UTC 2025


On Thu, 13 Mar 2025 18:12:00 GMT, Galder Zamarreño <galder at openjdk.org> wrote:

>> src/hotspot/share/opto/predicates.hpp line 331:
>> 
>>> 329:   // the ParsePredicateNode is not marked useless.
>>> 330:   bool is_valid() const {
>>> 331:     return _parse_predicate_node != nullptr && !_parse_predicate_node->is_useless();
>> 
>> Avoids visiting useless Parse Predicates during Predicate iteration.
>
> When can `_parse_predicate_node` be null?

When iterating through predicates, we use a `PredicateBlockIterator` for each Predicate Block, which consists of an optional Parse Predicate and a number of Regular Predicates (Runtime and Assertion Predicates). We could have either already removed the Parse Predicate before here:
https://github.com/openjdk/jdk/blob/e3c29c9e6cff7648952c0ba359b0763a0ea8da18/src/hotspot/share/opto/loopnode.cpp#L5055-L5066

or there is just no Parse Predicate for this loop. So, when initializing the `PredicateBlockIterator`, we could pass here a non-Parse-Predicate projection to the constructor of `ParsePredicate`:
https://github.com/openjdk/jdk/blob/e3c29c9e6cff7648952c0ba359b0763a0ea8da18/src/hotspot/share/opto/predicates.hpp#L747

We then set `_parse_predicate_node` to null here due to this mismatch:
https://github.com/openjdk/jdk/blob/e3c29c9e6cff7648952c0ba359b0763a0ea8da18/src/hotspot/share/opto/predicates.hpp#L293-L296

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24013#discussion_r1995275721


More information about the hotspot-compiler-dev mailing list