RFR: 8309502: RISC-V: String.indexOf intrinsic may produce misaligned memory loads
Vladimir Kempik
vkempik at openjdk.org
Wed Jun 7 07:57:01 UTC 2023
On Mon, 5 Jun 2023 20:52:01 GMT, Vladimir Kempik <vkempik at openjdk.org> wrote:
> Please review this attempt to remove misaligned loads in String.indexOf intrinsic on RISC-V
>
> Initialy found these misaligned loads when profiling finagle-http test from renaissance suite.
> The majority of trp_lam events (about 66k per finagle-http round) came at line 706 (https://github.com/openjdk/jdk/pull/14320/files#diff-35eb1d2f1e2f0514dd46bd7fbad49ff2c87703d5a3041a6433956df00a3fe6e6L706)
> The other two produced about 100 events combined.
> Later I've found this can partially be reproduced with StringIndexOf.advancedWithMediumSub.
> Numbers on hifive before and after applying the patch:
>
>
> Benchmark Mode Cnt Score Error Units
> StringIndexOf.advancedWithMediumSub avgt 25 47031.406 ± 144.005 ns/op
>
>
> After:
>
> Benchmark Mode Cnt Score Error Units
> StringIndexOf.advancedWithMediumSub avgt 25 4256.830 ± 23.075 ns/op
>
>
> Testing: tier1/tier2 is clean on hifive.
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.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14320#issuecomment-1580138574
More information about the hotspot-compiler-dev
mailing list