Skip to content

[RISC-V] Substituting INS_ori and INS_addi with INS_mov for zero immediate values #116956

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

namu-lee
Copy link
Contributor

@namu-lee namu-lee commented Jun 24, 2025

Substituting INS_ori and INS_addi with INS_mov for zero immediate values.

@clamp03 @tomeksowi @SkyShield, @credo-quia-absurdum
part of #84834, cc @dotnet/samsung

@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 10:30
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 24, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR substitutes 32-bit addi/ori instructions with the 16-bit compressed mv (INS_mov) for zero immediates in RISC-V codegen, reducing native code size.

  • genSimpleReturn now emits INS_mov instead of INS_addi when the immediate is zero.
  • Several local-heap, cast, and LEA emitters replace emitIns_R_R_I(..., 0) with emitIns_R_R(INS_mov, ...).
Comments suppressed due to low confidence (1)

src/coreclr/jit/codegenriscv64.cpp:1429

  • There are no unit tests verifying that INS_mov is emitted for zero immediates; consider adding codegen tests to ensure mv is generated instead of addi/ori and that code size benefits are validated.
                emit->emitIns_R_R(INS_mov, easz, regCnt, targetReg);

Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@risc-vv
Copy link

risc-vv commented Jun 24, 2025

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 8min 38s 406ms
   REAL time: 36min 0s 243ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9717
VIRTUAL time: 11h 21min 24s 799ms
   REAL time: 46min 2s 681ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-QEMU: 283841 / 284911 (99.62%)
=======================
      passed: 283841
      failed: 1065
     skipped: 39
      killed: 5
------------------------
 TOTAL tests: 284950
VIRTUAL time: 30h 6min 12s 171ms
   REAL time: 1h 11min 50s 776ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-VF2: 510321 / 512066 (99.66%)
=======================
      passed: 510321
      failed: 1736
     skipped: 39
      killed: 9
------------------------
 TOTAL tests: 512105
VIRTUAL time: 24h 39min 53s 929ms
   REAL time: 2h 12min 1s 730ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 735cdcdbab5e439c25eb9b462770cf6b2c4cc28f
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Jun 25, 2025
@clamp03
Copy link
Member

clamp03 commented Jun 25, 2025

cc @tomeksowi

@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 19min 1s 392ms
   REAL time: 36min 11s 28ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9717
VIRTUAL time: 11h 41min 58s 804ms
   REAL time: 47min 12s 22ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-QEMU: 275972 / 277043 (99.61%)
=======================
      passed: 275972
      failed: 1065
     skipped: 39
      killed: 6
------------------------
 TOTAL tests: 277082
VIRTUAL time: 30h 14min 46s 188ms
   REAL time: 1h 11min 9s 687ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-VF2: 498288 / 500030 (99.65%)
=======================
      passed: 498288
      failed: 1733
     skipped: 39
      killed: 9
------------------------
 TOTAL tests: 500069
VIRTUAL time: 22h 54min 33s 821ms
   REAL time: 2h 17min 32s 80ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 0ac9ad8c7316303a6eba621cbdf48a6deca7d398
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@namu-lee namu-lee force-pushed the instruction-compression branch from 0ac9ad8 to 10a76f3 Compare June 25, 2025 10:18
@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9717
VIRTUAL time: 11h 28min 58s 156ms
   REAL time: 46min 30s 246ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 10a76f3964bf8ed73db3edc7fa0e426afc5c8293
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-FX-QEMU: 283642 / 284660 (99.64%)
=======================
      passed: 283642
      failed: 1011
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 284699
VIRTUAL time: 29h 31min 29s 467ms
   REAL time: 1h 10min 50s 64ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 10a76f3964bf8ed73db3edc7fa0e426afc5c8293
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 16min 2s 426ms
   REAL time: 36min 7s 55ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 10a76f3964bf8ed73db3edc7fa0e426afc5c8293
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-FX-QEMU: 283846 / 284916 (99.62%)
=======================
      passed: 283846
      failed: 1063
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 284955
VIRTUAL time: 31h 17min 41s 328ms
   REAL time: 1h 11min 1s 293ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 26min 51s 814ms
   REAL time: 36min 17s 724ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-VF2: 305373 / 307123 (99.43%)
=======================
      passed: 305373
      failed: 1740
     skipped: 39
      killed: 10
------------------------
 TOTAL tests: 307162
VIRTUAL time: 21h 36min 28s 964ms
   REAL time: 2h 15min 27s 693ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 10a76f3964bf8ed73db3edc7fa0e426afc5c8293
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Jun 25, 2025

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9717
VIRTUAL time: 10h 26min 20s 249ms
   REAL time: 42min 30s 116ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-QEMU: 281186 / 282272 (99.62%)
=======================
      passed: 281186
      failed: 1080
     skipped: 39
      killed: 6
------------------------
 TOTAL tests: 282311
VIRTUAL time: 30h 47min 53s 45ms
   REAL time: 1h 11min 52s 374ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 30min 18s 785ms
   REAL time: 36min 22s 203ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 10a76f3964bf8ed73db3edc7fa0e426afc5c8293
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@clamp03
Copy link
Member

clamp03 commented Jun 26, 2025

@jakobbotsch @jkotas Could you review and merge this PR? This is substituting instructions with RISC-V pseudo instructions for better code readability. Thank you.

@risc-vv
Copy link

risc-vv commented Jun 26, 2025

RISC-V Release-CLR-QEMU: 9086 / 9116 (99.67%)
=======================
      passed: 9086
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9716
VIRTUAL time: 35h 13min 6s 612ms
   REAL time: 36min 3s 115ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 600
      killed: 28
------------------------
 TOTAL tests: 9717
VIRTUAL time: 10h 46min 20s 897ms
   REAL time: 43min 44s 198ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-QEMU: 283473 / 284549 (99.62%)
=======================
      passed: 283473
      failed: 1069
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 284588
VIRTUAL time: 31h 6min 52s 670ms
   REAL time: 1h 11min 43s 192ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

RISC-V Release-FX-VF2: 308390 / 310083 (99.45%)
=======================
      passed: 308390
      failed: 1682
     skipped: 39
      killed: 11
------------------------
 TOTAL tests: 310122
VIRTUAL time: 21h 37min 34s 550ms
   REAL time: 2h 9min 31s 659ms
=======================

report.xml, report.md, failures.xml, testclr_details.tar.zst

Build information and commands

GIT: 92cc1f551a0169497ae0a7da9b9f29189caad99d
CI: 01a69d638efe9b8b18c2888449be98b4a6cde211
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@clamp03
Copy link
Member

clamp03 commented Jun 30, 2025

@jakobbotsch Could you merge if there is no problem in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv Related to the RISC-V architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants