RFR: 8370196: C2: Improve (U)MulHiLNode::MulHiValue [v5]

Hannes Greule hgreule at openjdk.org
Fri Nov 21 07:05:53 UTC 2025


On Thu, 20 Nov 2025 16:39:54 GMT, Zihao Lin <duke at openjdk.org> wrote:

>> src/hotspot/share/opto/mulnode.cpp line 641:
>> 
>>> 639:   // Both are constant, directly computed the result
>>> 640:   if (longType1->is_con() && longType2->is_con()) {
>>> 641:     jlong highResult = multiply_high_unsigned(longType1->get_con(), longType2->get_con());
>> 
>> We are going from an unsigned value to a signed here, I think this is implementation-defined? Maybe it's better to use julong and `TypeLong::make_or_top(TypeIntPrototype<jlong, julong>{{min_jlong, max_jlong}, {highResult, highResult}, {0, 0}})`?
>> 
>> (It might also make sense to have a helper function like `TypeLong::make_unsigned` for that, but I'll let others comment on whether that should be done separately)
>
> I think TypeLong::make is doing the work your mentioned, do we need another function to do it?
> 
> 
> const TypeLong* TypeLong::make(jlong con) {
>   julong ucon = con;
>   return (new TypeLong(TypeIntPrototype<jlong, julong>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
>                        WidenMin, false))->hashcons()->is_long();
> }

Sorry if it wasn't clear, but the problem is that `multiply_high_unsigned` returns an *unsigned* long which you currently convert into a *signed* long. But from my understanding this is implementation-defined and I *think* you need to avoid that (I might be wrong though, happy to be corrected by someone else here :) ). That would mean you need to make `highResult` a `julong` and then you can't use `TypeLong::make` anymore as this would result in the same problem again.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28097#discussion_r2548753897


More information about the hotspot-compiler-dev mailing list