Skip to content

[RISC-V] Always report call target in range#119304

Merged
jakobbotsch merged 1 commit intodotnet:mainfrom
tomeksowi:call-target-in-range
Oct 21, 2025
Merged

[RISC-V] Always report call target in range#119304
jakobbotsch merged 1 commit intodotnet:mainfrom
tomeksowi:call-target-in-range

Conversation

@tomeksowi
Copy link
Member

auipc + jalr instruction combo has 32-bit range. Further calls are kept absolute by the same condition as x64:

case IAT_VALUE:
// IsCallTargetInRange always return true on x64. It wants to use rip-based addressing
// for this call. Unfortunately, in case of already resolved pinvokes to external libs,
// which are identified via accessType: IAT_VALUE, the relative offset is unlikely to
// fit into int32 and we will have to turn fAllowRel32 off globally. To prevent that
// we'll create a wrapper node and force LSRA to allocate a register so RIP relative
// isn't used and we don't need to pessimize other callsites.
if (!comp->IsAot() || !IsCallTargetInRange(addr))
{
result = AddrGen(addr);
}

Part of #84834, cc @dotnet/samsung

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 3, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 3, 2025
@tomeksowi
Copy link
Member Author

No regressions, more cruft removed.

Diffs are based on 104,367 contexts (2,270 MinOpts, 102,097 FullOpts).

MISSED contexts: 2 (0.00%)

Overall (-3,163,368 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.3.mch 71,889,656 -3,163,368 -3.25%
MinOpts (-502,760 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.3.mch 16,685,964 -502,760 -2.34%
FullOpts (-2,660,608 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.3.mch 55,203,692 -2,660,608 -3.30%
Example diffs
linux.riscv64.Checked.3.mch
-32 (-32.00%) : 695.dasm - TestLibrary.HostPolicyMock:Mock_corehost_resolve_component_dependencies(int,System.String,System.String,System.String):TestLibrary.HostPolicyMock+MockValues_corehost_resolve_component_dependencies (FullOpts)
@@ -26,33 +26,25 @@ G_M6441_IG01:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
 						;; size=16 bbWeight=1 PerfScore 9.00
 G_M6441_IG02:        ; bbWeight=1, gcrefRegs=3800 {a1 a2 a3}, byrefRegs=0000 {}, byref
             ; gcrRegs +[a1-a3]
-            lui            a4, 0xD1FFAB1E
-            addiw          a4, a4, 0xD1FFAB1E
-            slli           a4, a4, 12
-            addi           a4, a4, 0xD1FFAB1E
-            slli           a4, a4, 3
-            jalr           ra, 0xD1FFAB1E(a4)		// <unknown method>
+            auipc          ra, 0xD1FFAB1E
+            jalr           ra		// <unknown method>
             ; gcrRegs -[a1-a3]
             lui            a0, 0xD1FFAB1E
             addiw          a0, a0, 0xD1FFAB1E
             slli           a0, a0, 12
             addi           a0, a0, 0xD1FFAB1E
             slli           a0, a0, 3
-            lui            a1, 0xD1FFAB1E
-            addiw          a1, a1, 0xD1FFAB1E
-            slli           a1, a1, 12
-            addi           a1, a1, 0xD1FFAB1E
-            slli           a1, a1, 3
-            jalr           ra, 0xD1FFAB1E(a1)		// CORINFO_HELP_NEWSFAST
+            auipc          ra, 0xD1FFAB1E
+            jalr           ra		// CORINFO_HELP_NEWSFAST
             ; gcrRegs +[a0]
-						;; size=68 bbWeight=1 PerfScore 21.00
+						;; size=36 bbWeight=1 PerfScore 13.00
 G_M6441_IG03:        ; bbWeight=1, epilog, nogc, extend
             ld             ra, 8(sp)
             ld             fp, 0(sp)
             addi           sp, sp, 16
             ret						;; size=16 bbWeight=1 PerfScore 7.50
 
-; Total bytes of code 100, prolog size 16, PerfScore 37.50, instruction count 13, allocated bytes for code 100 (MethodHash=7421e6d6) for method TestLibrary.HostPolicyMock:Mock_corehost_resolve_component_dependencies(int,System.String,System.String,System.String):TestLibrary.HostPolicyMock+MockValues_corehost_resolve_component_dependencies (FullOpts)
+; Total bytes of code 68, prolog size 16, PerfScore 29.50, instruction count 11, allocated bytes for code 68 (MethodHash=7421e6d6) for method TestLibrary.HostPolicyMock:Mock_corehost_resolve_component_dependencies(int,System.String,System.String,System.String):TestLibrary.HostPolicyMock+MockValues_corehost_resolve_component_dependencies (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -63,7 +55,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 50 (0x00032) Actual length = 100 (0x000064)
+  Function Length   : 34 (0x00022) Actual length = 68 (0x000044)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
-16 (-30.77%) : 52577.dasm - JIT.HardwareIntrinsics.Arm.Helpers:RoundToPositiveInfinity(double):double (FullOpts)
@@ -21,21 +21,15 @@ G_M38667_IG01:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
             sd             ra, 8(sp)
             mv             fp, sp
 						;; size=16 bbWeight=1 PerfScore 9.00
-G_M38667_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
-            lui            a0, 0xD1FFAB1E
-            addiw          a0, a0, 0xD1FFAB1E
-            slli           a0, a0, 12
-            addi           a0, a0, 0xD1FFAB1E
-            slli           a0, a0, 3
-						;; size=20 bbWeight=1 PerfScore 5.00
-G_M38667_IG03:        ; bbWeight=1, epilog, nogc, extend
+G_M38667_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref, epilog, nogc
             ld             ra, 8(sp)
             ld             fp, 0(sp)
             addi           sp, sp, 16
-            jr             a0		// <unknown method>
-						;; size=16 bbWeight=1 PerfScore 7.50
+            auipc          t2, 0xD1FFAB1E
+            jr             t2		// <unknown method>
+						;; size=20 bbWeight=1 PerfScore 8.50
 
-; Total bytes of code 52, prolog size 16, PerfScore 21.50, instruction count 9, allocated bytes for code 52 (MethodHash=70aa68f4) for method JIT.HardwareIntrinsics.Arm.Helpers:RoundToPositiveInfinity(double):double (FullOpts)
+; Total bytes of code 36, prolog size 16, PerfScore 17.50, instruction count 8, allocated bytes for code 36 (MethodHash=70aa68f4) for method JIT.HardwareIntrinsics.Arm.Helpers:RoundToPositiveInfinity(double):double (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -46,7 +40,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 26 (0x0001a) Actual length = 52 (0x000034)
+  Function Length   : 18 (0x00012) Actual length = 36 (0x000024)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
-16 (-30.77%) : 102261.dasm - ComWrappersTests.GlobalInstance.Program+<>c:b__11_0():System.Object:this (FullOpts)
@@ -19,21 +19,15 @@ G_M30715_IG01:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
             sd             ra, 8(sp)
             mv             fp, sp
 						;; size=16 bbWeight=1 PerfScore 9.00
-G_M30715_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
-            lui            a0, 0xD1FFAB1E
-            addiw          a0, a0, 0xD1FFAB1E
-            slli           a0, a0, 12
-            addi           a0, a0, 0xD1FFAB1E
-            slli           a0, a0, 3
-						;; size=20 bbWeight=1 PerfScore 5.00
-G_M30715_IG03:        ; bbWeight=1, epilog, nogc, extend
+G_M30715_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref, epilog, nogc
             ld             ra, 8(sp)
             ld             fp, 0(sp)
             addi           sp, sp, 16
-            jr             a0		// <unknown method>
-						;; size=16 bbWeight=1 PerfScore 7.50
+            auipc          t2, 0xD1FFAB1E
+            jr             t2		// <unknown method>
+						;; size=20 bbWeight=1 PerfScore 8.50
 
-; Total bytes of code 52, prolog size 16, PerfScore 21.50, instruction count 9, allocated bytes for code 52 (MethodHash=1a2f8804) for method ComWrappersTests.GlobalInstance.Program+<>c:<ValidatePInvokes>b__11_0():System.Object:this (FullOpts)
+; Total bytes of code 36, prolog size 16, PerfScore 17.50, instruction count 8, allocated bytes for code 36 (MethodHash=1a2f8804) for method ComWrappersTests.GlobalInstance.Program+<>c:<ValidatePInvokes>b__11_0():System.Object:this (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -44,7 +38,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 26 (0x0001a) Actual length = 52 (0x000034)
+  Function Length   : 18 (0x00012) Actual length = 36 (0x000024)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
+0 (0.00%) : 103392.dasm - Microsoft.Diagnostics.Symbols.SymbolReader:get_SourceCacheDirectory():System.String:this (FullOpts)

No diffs found?

+0 (0.00%) : 103360.dasm - Microsoft.Diagnostics.Symbols.SymbolPath:DefaultSymbolCache(bool):System.String:this (FullOpts)

No diffs found?

+0 (0.00%) : 102096.dasm - ILGEN_0x496bb0b:Main():int (FullOpts)

No diffs found?

Details

Size improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same size Improvements (bytes) Regressions (bytes)
linux.riscv64.Checked.3.mch 48,912 47,459 0 1,453 -3,163,368 +0

PerfScore improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same PerfScore Improvements (PerfScore) Regressions (PerfScore) PerfScore Overall in FullOpts
linux.riscv64.Checked.3.mch 48,912 38,001 0 10,911 -4.17% 0.00% -1.5206%

Context information

Collection Diffed contexts MinOpts FullOpts Missed, base Missed, diff
linux.riscv64.Checked.3.mch 104,367 2,270 102,097 2 (0.00%) 2 (0.00%)

jit-analyze output

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Sep 3, 2025
@tomeksowi
Copy link
Member Author

@risc-vv /run

@risc-vv
Copy link

risc-vv commented Sep 3, 2025

0bc7710 is being scheduled for building and testing

GIT: 0bc771099d5df4179d1e165b8355e8a3254f5eae
REPO: dotnet/runtime
BRANCH: main

@risc-vv
Copy link

risc-vv commented Sep 8, 2025

RISC-V pull_request-CLR-QEMU: 9109 / 9139 (99.67%)
=======================
      passed: 9109
      failed: 2
     skipped: 586
      killed: 28
------------------------
 TOTAL tests: 9725
VIRTUAL time: 80h 39min 22s 181ms
   REAL time: 1h 19min 4s 620ms
=======================

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

RISC-V pull_request-CLR-VF2: 9109 / 9139 (99.67%)
=======================
      passed: 9109
      failed: 2
     skipped: 586
      killed: 28
------------------------
 TOTAL tests: 9725
VIRTUAL time: 32h 7min 58s 459ms
   REAL time: 2h 7min 40s 139ms
=======================

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

RISC-V pull_request-FX-QEMU: 0 / 0 (100.00%)
=======================
      passed: 0
      failed: 0
     skipped: 14
      killed: 0
------------------------
 TOTAL tests: 14
VIRTUAL time: 0ms
   REAL time: 4h 30min 0s 551ms
=======================

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

RISC-V pull_request-FX-VF2: 0 / 71 (0.00%)
=======================
      passed: 0
      failed: 0
     skipped: 14
      killed: 71
------------------------
 TOTAL tests: 85
VIRTUAL time: 1min 26s 303ms
   REAL time: 12h 0min 12s 299ms
=======================

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

Build information and commands

GIT: 0bc771099d5df4179d1e165b8355e8a3254f5eae
CI: 0dd2da79b21e6d27378407c3af1305973fd300aa
REPO: tomeksowi/runtime
BRANCH: call-target-in-range
CONFIG: Checked
LIB_CONFIG: Release

@tomeksowi tomeksowi marked this pull request as ready for review September 8, 2025 12:53
@JulieLeeMSFT
Copy link
Member

We will review .NET 11 PRs when we are done with .NET 10 last minute works and less busy. Please give us a few more weeks.
CC @jakobbotsch.

@steveisok steveisok added this to the 11.0.0 milestone Oct 6, 2025
@jakobbotsch jakobbotsch merged commit f34b97a into dotnet:main Oct 21, 2025
115 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 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 community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants