]> Cypherpunks repositories - gostls13.git/commit
cmd/compile, runtime: avoid improper control transfer instruction hints on riscv64
authorwangboyao <wangboyao@bytedance.com>
Thu, 4 Dec 2025 11:06:20 +0000 (19:06 +0800)
committerJoel Sing <joel@sing.id.au>
Tue, 27 Jan 2026 11:43:00 +0000 (03:43 -0800)
commit2d1f571c6b420757b2a72b9e53d486840a1317f9
tree5a2ccd3ded657a3f7d0ebb8a35cb63a2b0322fc7
parentf532f87a9895afc60b6ab17969c67e33d1ed1564
cmd/compile, runtime: avoid improper control transfer instruction hints on riscv64

On RISC-V the JAL and JALR instructions provide Return Address
Stack(RAS) prediction hints based on the registers used (as per section
2.5.1 of the RISC-V ISA manual). When a JALR instruction uses X1 or X5
as the source register, it hints that a pop should occur.

When making a function call, avoid the use of X5 as a source register
since this results in the RAS performing a pop-then-push instead of a
push, breaking call/return pairing and significantly degrading front-end
branch prediction performance.

Based on test result of golang.org/x/benchmarks/json on SpacemiT K1, fix
version has a performance improvement of about 7%

Fixes #76654

Change-Id: I867c8d7cfb54f5decbe176f3ab3bb3d78af1cf64
Reviewed-on: https://go-review.googlesource.com/c/go/+/726760
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au>
src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go
src/cmd/compile/internal/ssa/opGen.go
src/runtime/asm_riscv64.s
src/runtime/race_riscv64.s
src/runtime/sys_openbsd_riscv64.s