Skip to content

Conversation

@SkyShield
Copy link

@SkyShield SkyShield commented Dec 12, 2025

RISC-V instructions were not printed during PHASE Generate code, which made debugging inconvenient.

This PR enables printing RISC-V instructions when JitDump is set:

Before (PHASE Generate code):

Generating: N085 (  1,  1) [000039] -----------                   t39 =    LCL_VAR   double V03 loc3         u:2 fs6 REG fs6 $2c1
                                                                        /--*  t39    double 
Generating: N087 (  2,  2) [000040] -----------                   t40 = *  NEG       double REG fa0 $182
                                                                        /--*  t40    double 
Generating: N089 (???,???) [000134] -----------                  t134 = *  PUTARG_REG double REG fa0
                                                                        /--*  t134   double arg0 fa0
Generating: N091 ( 16,  5) [000123] --C-G-----Z                  t123 = *  CALL      double System.Math:Exp(double):double REG fa0
Call: GCvars=0000000000000000 {}, gcrefRegs=C0000 {s2 s3}, byrefRegs=0000 {}

After (PHASE Generate code):

Generating: N085 (  1,  1) [000039] -----------                   t39 =    LCL_VAR   double V03 loc3         u:2 fs6 REG fs6 $2c1
                                                                        /--*  t39    double 
Generating: N087 (  2,  2) [000040] -----------                   t40 = *  NEG       double REG fa0 $182
            fneg.d         fa0, fs6
                                                                        /--*  t40    double 
Generating: N089 (???,???) [000134] -----------                  t134 = *  PUTARG_REG double REG fa0
                                                                        /--*  t134   double arg0 fa0
Generating: N091 ( 16,  5) [000123] --C-G-----Z                  t123 = *  CALL      double System.Math:Exp(double):double REG fa0
Call: GCvars=0000000000000000 {}, gcrefRegs=C0000 {s2 s3}, byrefRegs=0000 {}
            auipc          ra, ??
            jalr           ra, ??(ra)		// System.Math:Exp(double):double

Limitation

In the current RISC-V implementation, it's difficult to compute the actual jump offset during CodeGen. Thus, a placeholder "??" is printed instead.


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

@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 Dec 12, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 12, 2025
@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Dec 12, 2025
@clamp03 clamp03 requested a review from tomeksowi December 12, 2025 09:57
@SkyShield
Copy link
Author

@dotnet-policy-service agree

@SkyShield SkyShield changed the title [RISC-V] Enable instruction print for PHASE Generate code of JIT dump [RISC-V] Enable instruction printing for PHASE Generate code in JIT dump Dec 12, 2025
Copy link
Member

@tomeksowi tomeksowi left a comment

Choose a reason for hiding this comment

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

Can you run some asmdiffs to make sure these changes don't affect the actual codegen?

Comment on lines +4235 to +4243
if ((addr == nullptr) && (offset == 0))
{
// If address is not given, print placeholder instead.
printf("??");
}
else
{
emitDispImmediate(offset, false);
}
Copy link
Member

Choose a reason for hiding this comment

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

Branches without a label may need similar treatment.

Copy link
Author

@SkyShield SkyShield Dec 18, 2025

Choose a reason for hiding this comment

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

Handled non-labeled branch offsets in emitDispBranchOffset. Thanks.

@SkyShield
Copy link
Author

No differences were found when compared with feea419.


Diffs are based on 87,412 contexts (85,743 MinOpts, 1,669 FullOpts).

Overall (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 32,089,346 +0 0.00%
MinOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 31,407,428 +0 0.00%
FullOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 681,918 +0 0.00%
Example diffs
System.mch
+0 (0.00%) : 29.dasm - System.Diagnostics.Tracing.EventSource:InitializeDefaultEventSources() (FullOpts)

No diffs found?

+0 (0.00%) : 33.dasm - System.AppContext:TryGetSwitch(System.String,byref):bool (FullOpts)

No diffs found?

+0 (0.00%) : 109.dasm - System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1[System.__Canon]:Populate(System.String,int,int):System.__Canon[]:this (FullOpts)

No diffs found?

+0 (0.00%) : 87356.dasm - System.Net.Http.HPack.HPackEncoder:EncodeLiteralHeaderFieldWithoutIndexingNewNameToAllocatedArray(System.String):byte[] (MinOpts)

No diffs found?

+0 (0.00%) : 87352.dasm - System.Net.Http.HPack.HPackEncoder:EncodeValueStringPart(System.String,System.Span`1[byte]) (MinOpts)

No diffs found?

+0 (0.00%) : 87348.dasm - System.Net.Http.HPack.HPackEncoder:EncodeLiteralHeaderFieldWithoutIndexing(int,System.Span`1[byte],byref):bool (MinOpts)

No diffs found?

Details

Size improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same size Improvements (bytes) Regressions (bytes)
System.mch 2,713 0 0 2,713 -0 +0

PerfScore improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same PerfScore Improvements (PerfScore) Regressions (PerfScore) PerfScore Overall in FullOpts
System.mch 2,713 0 0 2,713 0.00% 0.00% 0.0000%

Context information

Collection Diffed contexts MinOpts FullOpts Missed, base Missed, diff
System.mch 87,412 85,743 1,669 0 (0.00%) 0 (0.00%)

jit-analyze output

@SkyShield
Copy link
Author

SkyShield commented Dec 18, 2025

After the change, asmdiffs showed no differences compared to 13ee790.


Diffs are based on 87,627 contexts (85,970 MinOpts, 1,657 FullOpts).

Overall (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 32,167,222 +0 0.00%
MinOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 31,487,584 +0 0.00%
FullOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
System.mch 679,638 +0 0.00%
Example diffs
System.mch
+0 (0.00%) : 1409.dasm - System.Diagnostics.Process:GetNextArgument(System.String,byref):System.String (MinOpts)

No diffs found?

+0 (0.00%) : 1985.dasm - System.ModuleHandle:ResolveTypeHandle(int,System.RuntimeTypeHandle[],System.RuntimeTypeHandle[]):System.RuntimeTypeHandle:this (FullOpts)

No diffs found?

+0 (0.00%) : 3841.dasm - System.Timers.Timer:.ctor():this (MinOpts)

No diffs found?

+0 (0.00%) : 79424.dasm - System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2+d__20[System.__Canon,long]:MoveNext():this (MinOpts)

No diffs found?

+0 (0.00%) : 78464.dasm - System.Net.Security.SslApplicationProtocol:.cctor() (MinOpts)

No diffs found?

+0 (0.00%) : 77568.dasm - System.Text.Encodings.Web.OptimizedInboxTextEncoder+AsciiPreescapedData:PopulatePreescapedData(byref,System.Text.Encodings.Web.ScalarEscaperBase):this (MinOpts)

No diffs found?

Details

Size improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same size Improvements (bytes) Regressions (bytes)
System.mch 2,720 0 0 2,720 -0 +0

PerfScore improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same PerfScore Improvements (PerfScore) Regressions (PerfScore) PerfScore Overall in FullOpts
System.mch 2,720 0 0 2,720 0.00% 0.00% 0.0000%

Context information

Collection Diffed contexts MinOpts FullOpts Missed, base Missed, diff
System.mch 87,627 85,970 1,657 0 (0.00%) 0 (0.00%)

jit-analyze output

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.

3 participants