RFR: 8309502: RISC-V: String.indexOf intrinsic may produce misaligned memory loads

Vladimir Kempik vkempik at openjdk.org
Wed Jun 7 15:56:28 UTC 2023


On Wed, 7 Jun 2023 08:27:53 GMT, Fei Yang <fyang at openjdk.org> wrote:

>> See, this part of algo is misaligned
>> 
>>  bind(CH1_LOOP);
>>     add(tmp3, haystack, hlen_neg);
>>     (this->*load_2chr)(ch2, Address(tmp3), noreg);
>>     beq(ch1, ch2, MATCH);
>>     add(hlen_neg, hlen_neg, haystack_chr_size);
>>     blez(hlen_neg, CH1_LOOP);
>> 
>> this becomes:
>> 
>> CH1_LOOP: add t4, a1, a2
>> lhu t1, 0(t4)
>> beg t0, t1, 0xMATCH
>> addi a2, a2, 1
>> blez a2, CH1_LOOP
>> 
>> 
>> so we load halfword on each iteration from address (a1+a2), and while a1 is constant, a2 is incrementing by 1 each step, so every other load is misaligned.
>
>> See, this part of algo is misaligned
>> 
>> ```
>>  bind(CH1_LOOP);
>>     add(tmp3, haystack, hlen_neg);
>>     (this->*load_2chr)(ch2, Address(tmp3), noreg);
>>     beq(ch1, ch2, MATCH);
>>     add(hlen_neg, hlen_neg, haystack_chr_size);
>>     blez(hlen_neg, CH1_LOOP);
>> ```
>> 
>> this becomes:
>> 
>> ```
>> CH1_LOOP: add t4, a1, a2
>> lhu t1, 0(t4)
>> beg t0, t1, 0xMATCH
>> addi a2, a2, 1
>> blez a2, CH1_LOOP
>> ```
>> 
>> so we load halfword on each iteration from address (a1+a2), and while a1 is constant, a2 is incrementing by 1 each step, so every other load is misaligned.
> 
> I see it now. Thanks. Then I am expecting that we could also have similar issue for the `if (needle_con_cnt == 4)` case in the same function where we do `load_4chr` incrementally with 1 byte step when `isLL` variable is true, right?

@RealFYang check last commit please, it improves DO2 by replacing one haystack_load_1chr() with one srli in expense one one load before the loop (CH1_LOOP)

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

PR Comment: https://git.openjdk.org/jdk/pull/14320#issuecomment-1581102536


More information about the hotspot-compiler-dev mailing list