Skip to content

[RISC-V] Print load immediate value in disassembly #114470

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
Apr 12, 2025

Conversation

fuad1502
Copy link
Contributor

Changes in this PR:

  • Grouped load immediate instructions into a single instrDesc (by introducing INS_OPTS_I & instrDescLoadImm)
  • Print immediate value on the last load immediate instruction.

See first note from @BruceForstall #113250 (comment) in the merged PR (although I decided to put the comment on the last instruction, is it better to put it at the first one as requested?)

C# source code:

[MethodImpl(MethodImplOptions.NoInlining)]
public ulong Fun13()
{
		return 0x07ffffc112312345;
}

Disassembly output:

G_M25971_IG02:  ;; offset=0x0010
            lui            a0, -515514
            addiw          a0, a0, 583
            slli           a0, a0, 12
            addi           a0, a0, -1888
            srli           a0, a0, 5            ;; load imm: hex=0x07FFFFC112312345 dec=576460482025694021
                                                ;; size=20 bbWeight=1 PerfScore 2.50

Part of #84834, cc @dotnet/samsung

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 10, 2025
Copy link
Contributor

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

@fuad1502
Copy link
Contributor Author

Diffs are based on 12,502 contexts (10,177 MinOpts, 2,325 FullOpts).

Overall (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
test.mch 6,214,876 +0 -0.00%
MinOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
test.mch 4,839,896 +0 0.00%
FullOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
test.mch 1,374,980 +0 -0.00%
Example diffs
test.mch
+0 (0.00%) : 1.dasm - System.Runtime.CompilerServices.GenericsHelpers:ClassWithSlotAndModule(long,ulong):long (Instrumented Tier1)
@@ -119,7 +119,7 @@ RWD08  	dq	000074CB4BAB17D2h
 RWD16  	dq	000074CB4BEA4BECh
 
 
-; Total bytes of code 328, prolog size 60, PerfScore 163.50, instruction count 68, allocated bytes for code 328 (MethodHash=b5296683) for method System.Runtime.CompilerServices.GenericsHelpers:ClassWithSlotAndModule(long,ulong):long (Instrumented Tier1)
+; Total bytes of code 328, prolog size 60, PerfScore 163.50, instruction count 64, allocated bytes for code 328 (MethodHash=b5296683) for method System.Runtime.CompilerServices.GenericsHelpers:ClassWithSlotAndModule(long,ulong):long (Instrumented Tier1)
 ; ============================================================
 
 Unwind Info:
+0 (0.00%) : 17.dasm - __GeneratedMainWrapper:Main():int (Tier0)
@@ -104,7 +104,7 @@ G_M2004_IG09:        ; bbWeight=1, funclet epilog, nogc, extend
             addi           sp, sp, 32
             ret						;; size=16 bbWeight=1 PerfScore 7.50
 
-; Total bytes of code 260, prolog size 32, PerfScore 115.00, instruction count 61, allocated bytes for code 260 (MethodHash=2a2bf82b) for method __GeneratedMainWrapper:Main():int (Tier0)
+; Total bytes of code 260, prolog size 32, PerfScore 115.00, instruction count 49, allocated bytes for code 260 (MethodHash=2a2bf82b) for method __GeneratedMainWrapper:Main():int (Tier0)
 ; ============================================================
 
 Unwind Info:
+0 (0.00%) : 65.dasm - System.String:Ctor(ulong):System.String (Instrumented Tier1)
@@ -132,7 +132,7 @@ RWD00  	dq	00007323F4AD42ECh
 RWD08  	dq	00007323F4AD42E8h
 
 
-; Total bytes of code 340, prolog size 24, PerfScore 64.09, instruction count 83, allocated bytes for code 340 (MethodHash=0f67cbd1) for method System.String:Ctor(ulong):System.String (Instrumented Tier1)
+; Total bytes of code 340, prolog size 24, PerfScore 64.09, instruction count 52, allocated bytes for code 340 (MethodHash=0f67cbd1) for method System.String:Ctor(ulong):System.String (Instrumented Tier1)
 ; ============================================================
 
 Unwind Info:
+0 (0.00%) : 12496.dasm - Microsoft.CodeAnalysis.CSharp.Symbols.SourceMethodSymbolWithAttributes:get_DeclaringSyntaxReferences():System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.SyntaxReference]:this (Instrumented Tier0)
@@ -25,11 +25,11 @@ G_M22631_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
             ld             a0, 0xD1FFAB1E(a0)
             beqz           a0, G_M22631_IG04
             lui            a0, 0xD1FFAB1E
-            ; gcrRegs -[a0]
             addiw          a0, a0, 0xD1FFAB1E
             slli           a0, a0, 13
             addi           a0, a0, 0xD1FFAB1E
             slli           a0, a0, 3
+            ; gcrRegs -[a0]
             lui            a1, 0xD1FFAB1E
             addiw          a1, a1, 0xD1FFAB1E
             slli           a1, a1, 12
@@ -85,7 +85,7 @@ RWD00  	dq	00007CAB40B89C78h
 RWD08  	dq	00007CAB41E7390Ch
 
 
-; Total bytes of code 212, prolog size 16, PerfScore 71.00, instruction count 51, allocated bytes for code 212 (MethodHash=428ca798) for method Microsoft.CodeAnalysis.CSharp.Symbols.SourceMethodSymbolWithAttributes:get_DeclaringSyntaxReferences():System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.SyntaxReference]:this (Instrumented Tier0)
+; Total bytes of code 212, prolog size 16, PerfScore 71.00, instruction count 31, allocated bytes for code 212 (MethodHash=428ca798) for method Microsoft.CodeAnalysis.CSharp.Symbols.SourceMethodSymbolWithAttributes:get_DeclaringSyntaxReferences():System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.SyntaxReference]:this (Instrumented Tier0)
 ; ============================================================
 
 Unwind Info:
+0 (0.00%) : 12384.dasm - Microsoft.CodeAnalysis.CSharp.Symbols.SymbolExtensions:ShouldCheckRequiredMembers(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol):ubyte (Tier1)
@@ -218,7 +218,7 @@ G_M22420_IG19:        ; bbWeight=0.50, epilog, nogc, extend
 RWD00  	dq	00007CAB3FC1BDC8h
 
 
-; Total bytes of code 504, prolog size 28, PerfScore 103.30, instruction count 125, allocated bytes for code 504 (MethodHash=9bdfa86b) for method Microsoft.CodeAnalysis.CSharp.Symbols.SymbolExtensions:ShouldCheckRequiredMembers(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol):ubyte (Tier1)
+; Total bytes of code 504, prolog size 28, PerfScore 103.30, instruction count 97, allocated bytes for code 504 (MethodHash=9bdfa86b) for method Microsoft.CodeAnalysis.CSharp.Symbols.SymbolExtensions:ShouldCheckRequiredMembers(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol):ubyte (Tier1)
 ; ============================================================
 
 Unwind Info:
+0 (0.00%) : 12288.dasm - Microsoft.CodeAnalysis.Collections.OrderPreservingMultiDictionary`2[System.__Canon,System.__Canon]:Free():this (Instrumented Tier0)
@@ -342,10 +342,10 @@ G_M52571_IG25:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
             ld             a0, -88(fp)
             bnez           a0, G_M52571_IG27
             lui            a0, 0xD1FFAB1E
-            ; gcrRegs -[a0]
             addiw          a0, a0, 0xD1FFAB1E
             slli           a0, a0, 16
             addi           a0, a0, 0xD1FFAB1E
+            ; gcrRegs -[a0]
             lui            a1, 0xD1FFAB1E
             addiw          a1, a1, 0xD1FFAB1E
             slli           a1, a1, 12
@@ -461,7 +461,7 @@ RWD08  	dq	00007CAB41DCB3E8h
 RWD16  	dq	00007CABBA41EBC6h
 
 
-; Total bytes of code 1248, prolog size 60, PerfScore 453.26, instruction count 308, allocated bytes for code 1248 (MethodHash=8e8b32a4) for method Microsoft.CodeAnalysis.Collections.OrderPreservingMultiDictionary`2[System.__Canon,System.__Canon]:Free():this (Instrumented Tier0)
+; Total bytes of code 1248, prolog size 60, PerfScore 453.26, instruction count 217, allocated bytes for code 1248 (MethodHash=8e8b32a4) for method Microsoft.CodeAnalysis.Collections.OrderPreservingMultiDictionary`2[System.__Canon,System.__Canon]:Free():this (Instrumented Tier0)
 ; ============================================================
 
 Unwind Info:
Details

Size improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same size Improvements (bytes) Regressions (bytes)
test.mch 4,361 0 0 4,361 -0 +0

PerfScore improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same PerfScore Improvements (PerfScore) Regressions (PerfScore) PerfScore Overall in FullOpts
test.mch 4,361 0 0 4,361 0.00% 0.00% -0.0000%

Context information

Collection Diffed contexts MinOpts FullOpts Missed, base Missed, diff
test.mch 12,502 10,177 2,325 0 (0.00%) 0 (0.00%)

jit-analyze output

@risc-vv
Copy link

risc-vv commented Apr 10, 2025

RISC-V Release-CLR-VF2: 9532 / 9552 (99.79%)
=======================
      passed: 9532
      failed: 3
     skipped: 107
      killed: 17
------------------------
  TOTAL libs: 9659
 TOTAL tests: 9659
   REAL time: 2h 12min 43s 565ms
=======================

Release-CLR-VF2.md, Release-CLR-VF2.xml, testclr_output.tar.gz

Build information and commands

GIT: d2ced94133f4e10972ae1845734aa0a204e6d6ae
CI: 09909bfe3d23ad26455327811013bcbb48915255
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

RISC-V Release-CLR-QEMU: 9532 / 9552 (99.79%)
=======================
      passed: 9532
      failed: 3
     skipped: 107
      killed: 17
------------------------
  TOTAL libs: 9659
 TOTAL tests: 9659
   REAL time: 2h 47min 38s 229ms
=======================

Release-CLR-QEMU.md, Release-CLR-QEMU.xml, testclr_output.tar.gz

Build information and commands

GIT: d2ced94133f4e10972ae1845734aa0a204e6d6ae
CI: 09909bfe3d23ad26455327811013bcbb48915255
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Apr 10, 2025

5331560 is being scheduled for building and testing

GIT: 533156096ae6d63f280324ee8a81a0299beb2ca5
REPO: dotnet/runtime
BRANCH: main

{CONFIG}-CLR-tests FAILED

buildinfo.json
coreCLR tests failed for unknown reason. Check buildinfo.json or gocd for more details.

@risc-vv
Copy link

risc-vv commented Apr 11, 2025

RISC-V Release-CLR-QEMU: 9532 / 9552 (99.79%)
=======================
      passed: 9532
      failed: 3
     skipped: 107
      killed: 17
------------------------
  TOTAL libs: 9659
 TOTAL tests: 9659
   REAL time: 2h 47min 56s 343ms
=======================

Release-CLR-QEMU.md, Release-CLR-QEMU.xml, testclr_output.tar.gz

Build information and commands

GIT: 96b8a19dd6411ef3eb6643537218cd6164280f06
CI: 09909bfe3d23ad26455327811013bcbb48915255
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

RISC-V Release-FX-QEMU: 626054 / 651127 (96.15%)
=======================
      passed: 626054
      failed: 1534
     skipped: 1456
      killed: 23539
------------------------
  TOTAL libs: 259
 TOTAL tests: 652583
   REAL time: 2h 31min 55s 461ms
=======================

Release-FX-QEMU.md, Release-FX-QEMU.xml, testfx_output.tar.gz

Build information and commands

GIT: 96b8a19dd6411ef3eb6643537218cd6164280f06
CI: 09909bfe3d23ad26455327811013bcbb48915255
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@fuad1502
Copy link
Contributor Author

Somehow the "Format jit codebase" check failed after pushing 96b8a19. Looking at the logs, it looks like an issue with the CI:

Formatting jit directory.
Can't find compile_commands.json file. Running configure.
Running: /__w/runtime/runtime/runtime/src/coreclr/build-runtime.sh x64 Release configureonly -cmakeargs -DCMAKE_EXPORT_COMPILE_COMMANDS=1
There was an error running CMake to generate compile_commands.json. Please run build-runtime.sh configureonly

The attached patch file is also empty.

@am11
Copy link
Member

am11 commented Apr 11, 2025

This is a regression from #113899. I've opened #114538.

@BruceForstall
Copy link
Contributor

I'm going to re-run the CI to ensure the format jobs aren't broken.

Copy link
Contributor

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

LGTM. I'm worried there might be assumptions around the compiler than an instrDesc represents one instruction. I think there are already one or two exceptions (loop alignment and arm32 large branches come to mind) so maybe it's ok.

@BruceForstall BruceForstall merged commit b8f318d into dotnet:main Apr 12, 2025
112 of 114 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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