RFR: 8328480: C2: SubTypeCheckNode in checkcast should use the klass constant of a unique concrete sub class

Roland Westrelin roland at openjdk.org
Thu Mar 28 13:55:32 UTC 2024


On Thu, 28 Mar 2024 13:45:56 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

>> I'm confused by this. Looking at `TypeInstKlassPtr::try_improve()` returns a constant only if it finds a unique subklass and that subklass is final. So it should not be uncommon to have an `improved_klass_ptr_type` that's not constant.
>
> That's true. I've missed that we could also improve non-constants like `LoadKlass`, for example. I'm not sure if we could also have other improved types here apart from constants or `LoadKlass` (from `array_store_check()`). The only other non-constant `superklass` is passed by `LibraryCallKit::inline_Class_cast()`. From there, we either get a constant or a `CastPPNode` from which I'm not sure if it can really be improved.
> 
> Either way, I think we could improve the code like that to get an improved type regardless of the node, what do you think?
> 
> 
>     if (improved_klass_ptr_type != klass_ptr_type) {
>       if (improved_klass_ptr_type->singleton()) {
>         improved_superklass = makecon(improved_klass_ptr_type);
>       } else {
>         superklass->raise_bottom_type(improved_klass_ptr_type);
>         _gvn.set_type(superklass, improved_klass_ptr_type);
>       }
>     }

That's what I was wondering too. Wouldn't casting `superklass` to `improved_klass_ptr_type` do all of this in a cleaner way? gvn would constant fold the result if it can.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18515#discussion_r1543022425


More information about the hotspot-compiler-dev mailing list