Skip to content

[RISCV] Update SpacemiT X60 scheduling latencies based on hardware measurements #144730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

mikhailramalho
Copy link
Member

This patch updates the RISC-V SpacemiT X60 scheduling model with latency values collected from the X60 hardware. The previous values were empirically derived but were slightly off.

Changes:

  • LoadLatency (baseline for load instructions): 5 --> 3 cycles
  • Memory operations: unified at 4 cycles
  • Atomic loads/stores: 5 --> 8 cycles
  • Atomic RMW operations: 5 --> 12 cycles

Hardware-measured values provide more accurate instruction scheduling for the in-order X60 core. Testing shows NFC across benchmarks except for 523.xalancbmk_r (known to be noisy).

https://lnt.lukelau.me/db_default/v4/nts/663?compare_to=657

Signed-off-by: Mikhail R. Gadelha <[email protected]>
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

This patch updates the RISC-V SpacemiT X60 scheduling model with latency values collected from the X60 hardware. The previous values were empirically derived but were slightly off.

Changes:

  • LoadLatency (baseline for load instructions): 5 --> 3 cycles
  • Memory operations: unified at 4 cycles
  • Atomic loads/stores: 5 --> 8 cycles
  • Atomic RMW operations: 5 --> 12 cycles

Hardware-measured values provide more accurate instruction scheduling for the in-order X60 core. Testing shows NFC across benchmarks except for 523.xalancbmk_r (known to be noisy).

https://lnt.lukelau.me/db_default/v4/nts/663?compare_to=657


Full diff: https://github.com/llvm/llvm-project/pull/144730.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVSchedSpacemitX60.td (+8-7)
diff --git a/llvm/lib/Target/RISCV/RISCVSchedSpacemitX60.td b/llvm/lib/Target/RISCV/RISCVSchedSpacemitX60.td
index 8948694c420a0..9059d5a4e497b 100644
--- a/llvm/lib/Target/RISCV/RISCVSchedSpacemitX60.td
+++ b/llvm/lib/Target/RISCV/RISCVSchedSpacemitX60.td
@@ -16,7 +16,7 @@
 def SpacemitX60Model : SchedMachineModel {
   let IssueWidth        = 2; // dual-issue
   let MicroOpBufferSize = 0; // in-order
-  let LoadLatency       = 5; // worse case: >= 3
+  let LoadLatency       = 3; // worse case: >= 3
   let MispredictPenalty = 9; // nine-stage
 
   let CompleteModel = 0;
@@ -114,7 +114,7 @@ def : WriteRes<WriteBEXT, [SMX60_IEU]>;
 def : WriteRes<WriteBEXTI, [SMX60_IEU]>;
 
 // Memory/Atomic memory
-let Latency = 3 in {
+let Latency = 4 in {
   def : WriteRes<WriteSTB, [SMX60_LS]>;
   def : WriteRes<WriteSTH, [SMX60_LS]>;
   def : WriteRes<WriteSTW, [SMX60_LS]>;
@@ -122,11 +122,7 @@ let Latency = 3 in {
   def : WriteRes<WriteFST16, [SMX60_LS]>;
   def : WriteRes<WriteFST32, [SMX60_LS]>;
   def : WriteRes<WriteFST64, [SMX60_LS]>;
-  def : WriteRes<WriteAtomicSTW, [SMX60_LS]>;
-  def : WriteRes<WriteAtomicSTD, [SMX60_LS]>;
-}
 
-let Latency = 5 in {
   def : WriteRes<WriteLDB, [SMX60_LS]>;
   def : WriteRes<WriteLDH, [SMX60_LS]>;
   def : WriteRes<WriteLDW, [SMX60_LS]>;
@@ -137,9 +133,14 @@ let Latency = 5 in {
 }
 
 // Atomics
-let Latency = 5 in {
+let Latency = 8 in {
+  def : WriteRes<WriteAtomicSTW, [SMX60_LS]>;
+  def : WriteRes<WriteAtomicSTD, [SMX60_LS]>;
   def : WriteRes<WriteAtomicLDW, [SMX60_LS]>;
   def : WriteRes<WriteAtomicLDD, [SMX60_LS]>;
+}
+
+let Latency = 12 in {
   def : WriteRes<WriteAtomicW, [SMX60_LS]>;
   def : WriteRes<WriteAtomicD, [SMX60_LS]>;
 }

@dtcxzyw dtcxzyw requested a review from zqb-all June 18, 2025 15:46
@zqb-all
Copy link
Contributor

zqb-all commented Jun 18, 2025

LGTM. Thanks.

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some MCA tests?

Signed-off-by: Mikhail R. Gadelha <[email protected]>
Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mikhailramalho mikhailramalho merged commit 3516ad0 into llvm:main Jun 19, 2025
7 checks passed
@mikhailramalho mikhailramalho deleted the update-ld-st-lat branch June 19, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants