Skip to content

Conversation

tomeksowi
Copy link
Member

Reuse and augment lowerings from mainstream platforms.

Base ISA only, bext(i) can be fitted easily in another PR once #115335 merges, it maps well to BITTEST_NE.

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 Jul 9, 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 9, 2025
Copy link
Contributor

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

@tomeksowi
Copy link
Member Author

Diffs are based on 297,254 contexts (102,759 MinOpts, 194,495 FullOpts).

Overall (-362,976 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.1.mch 281,376,692 -362,976 -0.29%
MinOpts (+0 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.1.mch 148,101,028 +0 0.00%
FullOpts (-362,976 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
linux.riscv64.Checked.1.mch 133,275,664 -362,976 -0.35%
Example diffs
linux.riscv64.Checked.1.mch
-24 (-30.00%) : 47851.dasm - Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE.PEMethodSymbol+PackedFlags:TryGetHasSetsRequiredMembers(byref):bool:this (FullOpts)
@@ -25,26 +25,19 @@ G_M17699_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0C00 {a0 a1}, b
             ; byrRegs +[a0-a1]
             lw             a0, 0xD1FFAB1E(a0)
             ; byrRegs -[a0]
-            lui            a2, 0xD1FFAB1E
-            and            a2, a0, a2
-            sext.w         a2, a2
-            sext.w         a2, a2
-            sltu           a2, zero, a2
+            slli           a2, a0, 49
+            srli           a2, a2, 63
             sb             a2, 0xD1FFAB1E(a1)
-            lui            a1, 0xD1FFAB1E
-            ; byrRegs -[a1]
-            and            a0, a0, a1
-            sext.w         a0, a0
-            sext.w         a0, a0
-            sltu           a0, zero, a0
-						;; size=48 bbWeight=1 PerfScore 12.00
+            slli           a0, a0, 48
+            srli           a0, a0, 63
+						;; size=24 bbWeight=1 PerfScore 8.00
 G_M17699_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 80, prolog size 16, PerfScore 28.50, instruction count 20, allocated bytes for code 80 (MethodHash=f9a2badc) for method Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE.PEMethodSymbol+PackedFlags:TryGetHasSetsRequiredMembers(byref):bool:this (FullOpts)
+; Total bytes of code 56, prolog size 16, PerfScore 24.50, instruction count 14, allocated bytes for code 56 (MethodHash=f9a2badc) for method Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE.PEMethodSymbol+PackedFlags:TryGetHasSetsRequiredMembers(byref):bool:this (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -55,7 +48,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 20 (0x00014) Actual length = 80 (0x000050)
+  Function Length   : 14 (0x0000e) Actual length = 56 (0x000038)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
-16 (-26.67%) : 26370.dasm - Microsoft.CodeAnalysis.VisualBasic.Symbols.SynthesizedDelegateMethodSymbol:get_IsOverridable():bool:this (FullOpts)
@@ -23,20 +23,16 @@ G_M2731_IG02:        ; bbWeight=1, gcrefRegs=0400 {a0}, byrefRegs=0000 {}, byref
             ; gcrRegs +[a0]
             lw             a0, 0xD1FFAB1E(a0)
             ; gcrRegs -[a0]
-            lui            a1, 0xD1FFAB1E
-            addiw          a1, a1, 0xD1FFAB1E
-            and            a0, a0, a1
-            sext.w         a0, a0
-            sext.w         a0, a0
-            sltu           a0, zero, a0
-						;; size=28 bbWeight=1 PerfScore 6.00
+            slli           a0, a0, 52
+            srli           a0, a0, 63
+						;; size=12 bbWeight=1 PerfScore 3.00
 G_M2731_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 60, prolog size 16, PerfScore 22.50, instruction count 14, allocated bytes for code 60 (MethodHash=da9bf554) for method Microsoft.CodeAnalysis.VisualBasic.Symbols.SynthesizedDelegateMethodSymbol:get_IsOverridable():bool:this (FullOpts)
+; Total bytes of code 44, prolog size 16, PerfScore 19.50, instruction count 11, allocated bytes for code 44 (MethodHash=da9bf554) for method Microsoft.CodeAnalysis.VisualBasic.Symbols.SynthesizedDelegateMethodSymbol:get_IsOverridable():bool:this (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -47,7 +43,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 15 (0x0000f) Actual length = 60 (0x00003c)
+  Function Length   : 11 (0x0000b) Actual length = 44 (0x00002c)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
-16 (-26.67%) : 249955.dasm - System.Text.RegularExpressions.Symbolic.MatchingState`1[byte]:IsNullableFor(uint):bool:this (FullOpts)
@@ -25,20 +25,16 @@ G_M21865_IG02:        ; bbWeight=1, gcrefRegs=0400 {a0}, byrefRegs=0000 {}, byre
             ; gcrRegs +[a0]
             lw             a0, 0xD1FFAB1E(a0)
             ; gcrRegs -[a0]
-            addi           a2, zero, 0xD1FFAB1E
-            sllw           a1, a2, a1
-            and            a0, a0, a1
-            sext.w         a0, a0
-            sext.w         a0, a0
-            sltu           a0, zero, a0
-						;; size=28 bbWeight=1 PerfScore 5.00
+            sraw           a0, a0, a1
+            andi           a0, a0, 1
+						;; size=12 bbWeight=1 PerfScore 3.00
 G_M21865_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 60, prolog size 16, PerfScore 21.50, instruction count 15, allocated bytes for code 60 (MethodHash=569daa96) for method System.Text.RegularExpressions.Symbolic.MatchingState`1[byte]:IsNullableFor(uint):bool:this (FullOpts)
+; Total bytes of code 44, prolog size 16, PerfScore 19.50, instruction count 11, allocated bytes for code 44 (MethodHash=569daa96) for method System.Text.RegularExpressions.Symbolic.MatchingState`1[byte]:IsNullableFor(uint):bool:this (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -49,7 +45,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 15 (0x0000f) Actual length = 60 (0x00003c)
+  Function Length   : 11 (0x0000b) Actual length = 44 (0x00002c)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
+4 (+9.09%) : 44466.dasm - Microsoft.CodeAnalysis.VisualBasic.Conversions:IsIdentityConversion(int):bool (FullOpts)
@@ -20,17 +20,18 @@ G_M16914_IG01:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
             mv             fp, sp
 						;; size=16 bbWeight=1 PerfScore 9.00
 G_M16914_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
+            not            a0, a0
             andi           a0, a0, 5
-            addiw          a0, a0, 0xD1FFAB1E
+            sext.w         a0, a0
             sltiu          a0, a0, 1
-						;; size=12 bbWeight=1 PerfScore 1.50
+						;; size=16 bbWeight=1 PerfScore 2.00
 G_M16914_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 44, prolog size 16, PerfScore 18.00, instruction count 11, allocated bytes for code 44 (MethodHash=e888bded) for method Microsoft.CodeAnalysis.VisualBasic.Conversions:IsIdentityConversion(int):bool (FullOpts)
+; Total bytes of code 48, prolog size 16, PerfScore 18.50, instruction count 12, allocated bytes for code 48 (MethodHash=e888bded) for method Microsoft.CodeAnalysis.VisualBasic.Conversions:IsIdentityConversion(int):bool (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -41,7 +42,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 11 (0x0000b) Actual length = 44 (0x00002c)
+  Function Length   : 12 (0x0000c) Actual length = 48 (0x000030)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
+4 (+8.33%) : 44364.dasm - Microsoft.CodeAnalysis.VisualBasic.Conversion:get_IsIdentity():bool:this (FullOpts)
@@ -25,17 +25,18 @@ G_M36159_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0400 {a0}, byre
             ; byrRegs +[a0]
             lw             a0, 0xD1FFAB1E(a0)
             ; byrRegs -[a0]
+            not            a0, a0
             andi           a0, a0, 5
-            addiw          a0, a0, 0xD1FFAB1E
+            sext.w         a0, a0
             sltiu          a0, a0, 1
-						;; size=16 bbWeight=1 PerfScore 3.50
+						;; size=20 bbWeight=1 PerfScore 4.00
 G_M36159_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 48, prolog size 16, PerfScore 20.00, instruction count 12, allocated bytes for code 48 (MethodHash=e6d072c0) for method Microsoft.CodeAnalysis.VisualBasic.Conversion:get_IsIdentity():bool:this (FullOpts)
+; Total bytes of code 52, prolog size 16, PerfScore 20.50, instruction count 13, allocated bytes for code 52 (MethodHash=e6d072c0) for method Microsoft.CodeAnalysis.VisualBasic.Conversion:get_IsIdentity():bool:this (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -46,7 +47,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 12 (0x0000c) Actual length = 48 (0x000030)
+  Function Length   : 13 (0x0000d) Actual length = 52 (0x000034)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
+4 (+7.14%) : 21967.dasm - Microsoft.CodeAnalysis.VisualBasic.LookupOptionExtensions:IsAttributeTypeLookup(int):bool (FullOpts)
@@ -20,20 +20,21 @@ G_M45402_IG01:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref,
             mv             fp, sp
 						;; size=16 bbWeight=1 PerfScore 9.00
 G_M45402_IG02:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
+            not            a0, a0
             lui            a1, 0xD1FFAB1E
             addiw          a1, a1, 0xD1FFAB1E
             and            a0, a0, a1
             sext.w         a0, a0
-            subw           a0, a0, a1
+            sext.w         a0, a0
             sltiu          a0, a0, 1
-						;; size=24 bbWeight=1 PerfScore 4.00
+						;; size=28 bbWeight=1 PerfScore 4.50
 G_M45402_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 56, prolog size 16, PerfScore 20.50, instruction count 13, allocated bytes for code 56 (MethodHash=e1cf4ea5) for method Microsoft.CodeAnalysis.VisualBasic.LookupOptionExtensions:IsAttributeTypeLookup(int):bool (FullOpts)
+; Total bytes of code 60, prolog size 16, PerfScore 21.00, instruction count 14, allocated bytes for code 60 (MethodHash=e1cf4ea5) for method Microsoft.CodeAnalysis.VisualBasic.LookupOptionExtensions:IsAttributeTypeLookup(int):bool (FullOpts)
 ; ============================================================
 
 Unwind Info:
@@ -44,7 +45,7 @@ Unwind Info:
   E bit             : 0
   X bit             : 0
   Vers              : 0
-  Function Length   : 14 (0x0000e) Actual length = 56 (0x000038)
+  Function Length   : 15 (0x0000f) Actual length = 60 (0x00003c)
   ---- Epilog scopes ----
   ---- Scope 0
   Epilog Start Offset        : 3523193630 (0xd1ffab1e) Actual offset = 3523193630 (0xd1ffab1e) Offset from main function begin = 3523193630 (0xd1ffab1e)
Details

Size improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same size Improvements (bytes) Regressions (bytes)
linux.riscv64.Checked.1.mch 63,277 42,670 6 20,601 -363,000 +24

PerfScore improvements/regressions per collection

Collection Contexts with diffs Improvements Regressions Same PerfScore Improvements (PerfScore) Regressions (PerfScore) PerfScore Overall in FullOpts
linux.riscv64.Checked.1.mch 63,277 41,285 663 21,329 -0.45% +0.37% -0.0949%

Context information

Collection Diffed contexts MinOpts FullOpts Missed, base Missed, diff
linux.riscv64.Checked.1.mch 297,254 102,759 194,495 0 (0.00%) 0 (0.00%)

jit-analyze output

The few +1 instruction regressions should disappear once we introduce some sign-extension elimination.

@risc-vv
Copy link

risc-vv commented Jul 9, 2025

RISC-V Release-FX-QEMU: 212796 / 214790 (99.07%)
=======================
      passed: 212796
      failed: 1987
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 214829
VIRTUAL time: 32h 30min 23s 166ms
   REAL time: 57min 25s 85ms
=======================

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

Build information and commands

GIT: 6686029c8a8780c5f8284fc641437b32f53053e3
CI: d6c9c1ab3a7411819463edc05ded301e89ba586a
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@risc-vv
Copy link

risc-vv commented Jul 9, 2025

RISC-V Release-CLR-QEMU: 9060 / 9112 (99.43%)
=======================
      passed: 9060
      failed: 24
     skipped: 597
      killed: 28
------------------------
 TOTAL tests: 9709
VIRTUAL time: 38h 47min 56s 982ms
   REAL time: 53min 9s 653ms
=======================

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

Build information and commands

GIT: 6686029c8a8780c5f8284fc641437b32f53053e3
CI: d6c9c1ab3a7411819463edc05ded301e89ba586a
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Jul 10, 2025
@risc-vv
Copy link

risc-vv commented Jul 10, 2025

RISC-V Release-CLR-QEMU: 9082 / 9112 (99.67%)
=======================
      passed: 9082
      failed: 2
     skipped: 597
      killed: 28
------------------------
 TOTAL tests: 9709
VIRTUAL time: 37h 25min 11s 36ms
   REAL time: 38min 8s 328ms
=======================

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

RISC-V Release-CLR-VF2: 9083 / 9113 (99.67%)
=======================
      passed: 9083
      failed: 2
     skipped: 597
      killed: 28
------------------------
 TOTAL tests: 9710
VIRTUAL time: 12h 4min 25s 774ms
   REAL time: 48min 47s 134ms
=======================

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

RISC-V Release-FX-QEMU: 281996 / 283078 (99.62%)
=======================
      passed: 281996
      failed: 1074
     skipped: 39
      killed: 8
------------------------
 TOTAL tests: 283117
VIRTUAL time: 32h 12min 55s 844ms
   REAL time: 1h 11min 58s 693ms
=======================

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

RISC-V Release-FX-VF2: 510734 / 512476 (99.66%)
=======================
      passed: 510734
      failed: 1735
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 512515
VIRTUAL time: 21h 42min 5s 376ms
   REAL time: 2h 17min 38s 325ms
=======================

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

Build information and commands

GIT: 514fa0e8a7a13f2a0c974f50959b21721e4b1646
CI: d6c9c1ab3a7411819463edc05ded301e89ba586a
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@tomeksowi tomeksowi marked this pull request as draft July 10, 2025 08:16
@tomeksowi tomeksowi marked this pull request as ready for review July 10, 2025 12:39
@sirntar
Copy link
Member

sirntar commented Jul 17, 2025

@risc-vv /run

@risc-vv
Copy link

risc-vv commented Jul 17, 2025

RISC-V Release-CLR-QEMU: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 597
      killed: 28
------------------------
 TOTAL tests: 9714
VIRTUAL time: 37h 22min 9s 676ms
   REAL time: 38min 11s 193ms
=======================

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

RISC-V Release-CLR-VF2: 9087 / 9117 (99.67%)
=======================
      passed: 9087
      failed: 2
     skipped: 597
      killed: 28
------------------------
 TOTAL tests: 9714
VIRTUAL time: 11h 46min 35s 674ms
   REAL time: 47min 39s 595ms
=======================

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

RISC-V Release-FX-QEMU: 279251 / 280326 (99.62%)
=======================
      passed: 279251
      failed: 1068
     skipped: 39
      killed: 7
------------------------
 TOTAL tests: 280365
VIRTUAL time: 30h 41min 52s 406ms
   REAL time: 1h 12min 13s 708ms
=======================

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

RISC-V Release-FX-VF2: 308242 / 309993 (99.44%)
=======================
      passed: 308242
      failed: 1743
     skipped: 39
      killed: 8
------------------------
 TOTAL tests: 310032
VIRTUAL time: 21h 19min 58s 889ms
   REAL time: 2h 14min 9s 329ms
=======================

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

Build information and commands

GIT: 514fa0e8a7a13f2a0c974f50959b21721e4b1646
CI: 785da59dadeb491bca87651db4b40a68883f8a00
REPO: dotnet/runtime
BRANCH: main
CONFIG: Release
LIB_CONFIG: Release

@JulieLeeMSFT JulieLeeMSFT requested a review from clamp03 August 11, 2025 15:42
@JulieLeeMSFT
Copy link
Member

cc @jakobbotsch.

@clamp03 clamp03 requested a review from jakobbotsch August 12, 2025 01:48
@jakobbotsch
Copy link
Member

Won't get to this until next week after .NET 10 snap.

@JulieLeeMSFT
Copy link
Member

.NET 10 RC2 snap is Sept 22nd. We will review this after that.

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.

6 participants