[jdk16] RFR: 8260585: AArch64: Wrong code generated for shifting right and accumulating four unsigned short integers [v3]

dongbo (E) dongbo4 at huawei.com
Tue Feb 2 14:05:34 UTC 2021


On 2021/2/2 18:53, Ningsheng Jian wrote:
> Hi,
>
> On 2/1/21 10:35 PM, dongbo (E) wrote:
>>
>> On 2021/2/1 20:32, Andrew Haley wrote:
>>> On 2/1/21 8:11 AM, dongbo (E) wrote:
>>>> The tests passed with the newest version and still can catch the typo.
>>>> Also tested a few of injected errors, the tests failed as expected.
>>> One oddity has come up.
>>>
>>> I'm running compiler/c2/TestShiftRightAndAccumulate
>>> and the generated code I see for 
>>> compiler.c2.TestShiftRightAndAccumulate::test_shorts
>>>
>>> No vector instructions here. As far as I can see vectors are never used
>>> for jshort, just for jchar. All very strange, and probably not your 
>>> fault,
>>> but since I'm looking I had to mention it.
>>>
>>> The other weird thing is that {u,s}sra is never generated with the 
>>> .8B form.
>>
>> I guess the `usra` is not generated for `byte` and `short` because:
>> ```
>> src/hotspot/share/opto/vectornode.cpp, line 182:
>>    case Op_URShiftI:
>>      switch (bt) {
>>      case T_BOOLEAN:return Op_URShiftVB;
>>      case T_CHAR:   return Op_URShiftVS;
>>      case T_BYTE:
>>      case T_SHORT:  return 0; // Vector logical right shift for 
>> signed short
>>                               // values produces incorrect Java 
>> result for
>>                               // negative data because java code 
>> should convert
>>                               // a short value into int value with sign
>>                               // extension before a shift.
>>      case T_INT:    return Op_URShiftVI;
>>      default:       ShouldNotReachHere(); return 0;
>>      }
>> ```
>>
>
> They can be used in vector api. E.g.
>
> var vba = ByteVector.fromArray(ByteVector.SPECIES_PREFERRED, ba, i);
> vba.add(vba.lanewise(VectorOperators.LSHR, 3)).intoArray(ba, i);
>
> Thanks,
> Ningsheng
>
I ran local tests with the code you mentioned, it does use the unsigned 
shift for byte and short.

Thank you.




More information about the hotspot-compiler-dev mailing list