Skip to content

cmd/compile, cmd/asm: Incorrect Use of T0(X5) Register in Riscv64 Assembly Causes RAS Mismatch and Performance Issue #76654

@BoyaoWang430

Description

@BoyaoWang430

Based on The RISC-V Instruction Set Manual, not only X0 register but also X5 register can be used to be a link register. As described in Chapter 2.5.1, when two different link registers (x1 and x5) are given as rs1 and rd, the Return-address prediction stacks(RAS) will pop then push.

Image

The Go runtime’s handwritten assembly and the code generated by the Go compiler incorrectly emit JALR X1, X5 instruction. When a function call uses x5 as the source register for JALR, it causes unintended RAS behavior. Although functionally correct, these instructions make the RAS perform a pop-then-push instead of a normal push, breaking call/return pairing and significantly degrading front-end branch prediction performance.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.arch-riscvIssues solely affecting the riscv64 architecture.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions