Skip to content

[RISC-V] Replace addi, addiw with mov, sext.w when immediate is zero #117932

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 2 commits into from
Aug 6, 2025

Conversation

credo-quia-absurdum
Copy link
Contributor

Replace addi, addiw with mov, sext.w when immediate is zero

@clamp03 @tomeksowi @SkyShield, @namu-lee
part of #84834, cc @dotnet/samsung

@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 14:27
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 optimizes RISC-V assembly code generation by replacing addi/addiw instructions with more appropriate mov/sext.w instructions when the immediate value is zero. This change improves code clarity and potentially performance by using semantically correct instructions for register moves and sign extension operations.

Key changes:

  • Replace addi rd, rs, 0 with mov rd, rs for 64-bit register moves
  • Replace addiw rd, rs, 0 with sext.w rd, rs for 32-bit sign extension operations
  • Update conditional logic to use appropriate instruction based on attribute size

@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 Jul 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 22, 2025
Copy link
Contributor

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

@sirntar
Copy link
Member

sirntar commented Jul 25, 2025

@risc-vv /run

@risc-vv
Copy link

risc-vv commented Jul 25, 2025

RISC-V Release-CLR-QEMU: 9092 / 9122 (99.67%)
=======================
      passed: 9092
      failed: 2
     skipped: 596
      killed: 28
------------------------
 TOTAL tests: 9718
VIRTUAL time: 37h 32min 19s 65ms
   REAL time: 38min 17s 563ms
=======================

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

RISC-V Release-FX-QEMU: 284268 / 285403 (99.60%)
=======================
      passed: 284268
      failed: 1127
     skipped: 39
      killed: 8
------------------------
 TOTAL tests: 285442
VIRTUAL time: 33h 16min 25s 178ms
   REAL time: 1h 12min 37s 570ms
=======================

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

RISC-V Release-CLR-VF2: 9093 / 9123 (99.67%)
=======================
      passed: 9093
      failed: 2
     skipped: 596
      killed: 28
------------------------
 TOTAL tests: 9719
VIRTUAL time: 11h 56min 43s 238ms
   REAL time: 48min 15s 33ms
=======================

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

RISC-V Release-FX-VF2: 307796 / 309263 (99.53%)
=======================
      passed: 307796
      failed: 1459
     skipped: 39
      killed: 8
------------------------
 TOTAL tests: 309302
VIRTUAL time: 21h 41min 2s 301ms
   REAL time: 2h 19min 50s 28ms
=======================

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

Build information and commands

GIT: 3d45d1687dda1fe42a7e2d79403c8de986144dda
CI: 785da59dadeb491bca87651db4b40a68883f8a00
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@clamp03 clamp03 requested a review from jakobbotsch July 28, 2025 04:52
@clamp03
Copy link
Member

clamp03 commented Jul 31, 2025

@jakobbotsch Could you review this PR and #117967 as well? Thank you.

@clamp03
Copy link
Member

clamp03 commented Aug 5, 2025

@jakobbotsch Could you review this PR too? Thank you.

@jakobbotsch
Copy link
Member

/ba-g Unknown failure was #117961

1 similar comment
@jakobbotsch
Copy link
Member

/ba-g Unknown failure was #117961

@jakobbotsch jakobbotsch merged commit 82f0bd1 into dotnet:main Aug 6, 2025
108 of 111 checks passed
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.

7 participants