RFR: 8352635: Improve inferencing of Float16 operations with constant inputs [v5]

Emanuel Peter epeter at openjdk.org
Wed Jun 11 14:18:40 UTC 2025


On Wed, 11 Jun 2025 14:05:34 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> import jdk.incubator.vector.*;
>> public class verify_rounding {
>>    public static void check() {
>>        for (int i = 0; i < 65550; i++) {
>>            short post_rounding = Float.floatToFloat16(Float.float16ToFloat(Float.floatToFloat16((float)i)) * 2049.0f);
>>            short pre_rounding = Float16.float16ToRawShortBits(Float16.multiply(Float16.valueOf((float)i), Float16.valueOf((float)2049.0f)));
>>            if (pre_rounding != post_rounding) {
>>               System.out.println("Mismatch at val = " + (float)i);
>>               System.out.println("post_rounding val = " + post_rounding);
>>               System.out.println("pre_rounding val = " + pre_rounding);
>>               break;
>>            }
>>        }
>>    }
>> 
>>    public static void main(String [] args) {
>>       check();
>>    }
>> }
>> 
>> 
>> CPROMPT>java --add-modules=jdk.incubator.vector -cp . verify_rounding
>> WARNING: Using incubator modules: jdk.incubator.vector
>> Mismatch at val = 3.0
>> post_rounding val = 28161
>> pre_rounding val = 28160
>> 
>> Since we intend to infer Float16 IR using patten match,  hence it may be incorrect to transform post-rounding pattern to pre-rounding.
>
> Right ok. The wording `enforce a pattern match` still does not make sense to me. You can `perform` a `pattern match`, but what does it mean to `enforce` it? Can you rephrase please?

Suggestion:
Suggestion:

      // 1. conF must lie within Float16 value range, otherwise we would have rounding issues:
      //    Doing the operation in float32 and then rounding is not the same as
      //    rounding first and doing the operation in float16.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24179#discussion_r2140303597


More information about the hotspot-compiler-dev mailing list