JDK-8352093 : Vectorize ConvHF2F when using Float.float16ToFloat with byte or int array element
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-03-14
  • Updated: 2025-03-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
The following cases are not vectorized after the bug fix for JDK-8350835:
Case 1) byte array
    public static byte[] aB = new byte[10000];
   ...
    for (int i = 0; i < aF.length; i++) {
        aF[i] = Float.float16ToFloat(aB[i]);
    }
Case 2) int array
   public static int[] aI = new int[10000];
   ...
    for (int i = 0; i < aF.length; i++) {
        aF[i] = Float.float16ToFloat((short)aI[i]);
    }
 
Prior to JDK-8350835 fix these were resulting in wrong vectorization/code gen in the product build. The JDK-8350835 fix disabled auto vectorization for these cases.

Let us take Case 1) with byte array:
    Scalar code for loop body: LoadB,  ConvHF2F, StoreF
    Vectorized code: LoadVector, VectorCastHF2F , StoreVector

     LoadB loads a byte with sign extension and the input to ConvHF2F is a signed short.
     LoadVector loads byte elements into vector register and the input to VectorCastHF2F is a byte vector
    But the VectorCastHF2F expects short vector as input always and so this results in wrong code generation.

    This could be fixed in two ways:
     Either the vectorizer should add vector byte to short conversion before VectorCastHF2F
     Or the VectorCastHF2F code gen should handle Byte vector as input in addition to Short vector.

For Case 2) with int array:
    Scalar code for loop body: LoadI,  LShiftI by 16, RShiftI by 16, ConvHF2F, StoreF
    Vectorized code: LoadVector, LShiftVI, RShiftVI, VectorCastHF2F, StoreVector

    Here LoadI,  LShiftI by 16, RShiftI by 16 are doing the int to short conversion and sign extension.
     LoadVector is loading int elements into vector register and the input to VectorCastHF2F is an int vector

    But as above the VectorCastHF2F expects short vector as input always and so this results in wrong code generation.

    This could be fixed in two ways:
     Either the vectorizer should add vector int to short conversion before VectorCastHF2F
     Or the VectorCastHF2F code gen should handle int vector as input in addition to Short vector.