Skip to content

[WIP] Optimize CastHelpers method for performance#2

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/optimize-casthelpers-method
Closed

[WIP] Optimize CastHelpers method for performance#2
Copilot wants to merge 1 commit intomainfrom
copilot/optimize-casthelpers-method

Conversation

Copy link

Copilot AI commented Mar 10, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

; Assembly listing for method System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Array,long,System.Object) (Tier1)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Tier1 code
; optimized code
; rsp based frame
; fully interruptible
; No PGO data
; 0 inlinees with PGO data; 2 single block inlinees; 0 inlinees without PGO data

G_M000_IG01: ;; offset=0x0000
sub rsp, 40

G_M000_IG02: ;; offset=0x0004
mov eax, dword ptr [rcx+0x08]
cmp rdx, rax
jae SHORT G_M000_IG10
lea rax, bword ptr [rcx+8*rdx+0x10]
mov rdx, qword ptr [rcx]
mov rdx, qword ptr [rdx+0x30]
test r8, r8
je SHORT G_M000_IG06

G_M000_IG03: ;; offset=0x001D
cmp rdx, qword ptr [r8]
jne SHORT G_M000_IG08

G_M000_IG04: ;; offset=0x0022
mov rcx, rax
mov rdx, r8

G_M000_IG05: ;; offset=0x0028
add rsp, 40
jmp System.Runtime.CompilerServices.CastHelpers:WriteBarrier(byref,System.Object)

G_M000_IG06: ;; offset=0x0031
xor rcx, rcx
mov gword ptr [rax], rcx

G_M000_IG07: ;; offset=0x0036
add rsp, 40
ret

G_M000_IG08: ;; offset=0x003B
mov r10, 0x7FFC7D01C4D8
cmp qword ptr [rcx], r10
je SHORT G_M000_IG04
mov rcx, rax

G_M000_IG09: ;; offset=0x004D
add rsp, 40
tail.jmp [System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object)]

G_M000_IG10: ;; offset=0x0057
call CORINFO_HELP_RNGCHKFAIL
int3

; Total bytes of code 93

; Assembly listing for method System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Array,long,ulong):byref (Tier1)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Tier1 code
; optimized code
; rsp based frame
; partially interruptible
; No PGO data
; 0 inlinees with PGO data; 1 single block inlinees; 0 inlinees without PGO data

G_M000_IG01: ;; offset=0x0000
sub rsp, 40

G_M000_IG02: ;; offset=0x0004
mov eax, dword ptr [rcx+0x08]
cmp rdx, rax
jae SHORT G_M000_IG05
lea rax, bword ptr [rcx+8*rdx+0x10]
mov rcx, qword ptr [rcx]
cmp qword ptr [rcx+0x30], r8
jne SHORT G_M000_IG04

G_M000_IG03: ;; offset=0x001A
add rsp, 40
ret

G_M000_IG04: ;; offset=0x001F
call [System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException():byref]
int3

G_M000_IG05: ;; offset=0x0026
call CORINFO_HELP_RNGCHKFAIL
int3

; Total bytes of code 44

; Assembly listing for method ConsoleApp1.DemoService:Main() (MinOpts)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; MinOpts code
; debuggable code
; rbp based frame
; fully interruptible
; No PGO data

G_M000_IG01: ;; offset=0x0000
push rbp
push rdi
sub rsp, 40
lea rbp, [rsp+0x30]

G_M000_IG02: ;; offset=0x000B
cmp dword ptr [(reloc 0x7ffc7d16e328)], 0
je SHORT G_M000_IG04

G_M000_IG03: ;; offset=0x0014
call CORINFO_HELP_DBG_IS_JUST_MY_CODE

G_M000_IG04: ;; offset=0x0019
mov rcx, 0x150001004A0
mov rdx, 0x15000100008
call [MyInterceptorNamespace.<CallerFullNameInterceptors_g>F8A1E273C8BFA75940BE2801949B9CC6C8A69D09F0A9863E82EB3B1D02C61D464__CallerFullNameInterceptors:Intercept_ConsoleApp1_LogHelper_Log_10_19(System.String,System.String)]
nop

G_M000_IG05: ;; offset=0x0034
add rsp, 40
pop rdi
pop rbp
ret

; Total bytes of code 59

; Assembly listing for method MyInterceptorNamespace.<CallerFullNameInterceptors_g>F8A1E273C8BFA75940BE2801949B9CC6C8A69D09F0A9863E82EB3B1D02C61D464__CallerFullNameInterceptors:Intercept_ConsoleApp1_LogHelper_Log_10_19(System.String,System.String) (MinOpts)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; MinOpts code
; debuggable code
; rbp based frame
; fully interruptible
; No PGO data

G_M000_IG01: ;; offset=0x0000
push rbp
push rdi
sub rsp, 40
lea rbp, [rsp+0x30]
mov gword ptr [rbp+0x10], rcx
mov gword ptr [rbp+0x18], rdx

G_M000_IG02: ;; offset=0x0013
cmp dword ptr [(reloc 0x7ffc7d16e328)], 0
je SHORT G_M000_IG04

G_M000_IG03: ;; offset=0x001C
call CORINFO_HELP_DBG_IS_JUST_MY_CODE

G_M000_IG04: ;; offset=0x0021
mov rcx, gword ptr [rbp+0x10]
mov rdx, 0x150001004D0
call [ConsoleApp1.LogHelper:Log(System.String,System.String)]
nop

G_M000_IG05: ;; offset=0x0036
add rsp, 40
pop rdi
pop rbp
ret

; Total bytes of code 61

; Assembly listing for method ConsoleApp1.LogHelper:Log(System.String,System.String) (MinOpts)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; MinOpts code
; debuggable code
; rbp based frame
; fully interruptible
; No PGO data

G_M000_IG01: ;; offset=0x0000
push rbp
push rdi
sub rsp, 40
lea rbp, [rsp+0x30]
xor eax, eax
mov qword ptr [rbp-0x10], rax
mov gword ptr [rbp+0x10], rcx
mov gword ptr [rbp+0x18], rdx

G_M000_IG02: ;; offset=0x0019
cmp dword ptr [(reloc 0x7ffc7d16e328)], 0
je SHORT G_M000_IG04

G_M000_IG03: ;; offset=0x0022
call CORINFO_HELP_DBG_IS_JUST_MY_CODE

G_M000_IG04: ;; offset=0x0027
mov rcx, gword ptr [rbp+0x18]
mov r8, gword ptr [rbp+0x10]
mov rdx, 0x15000100210
call [System.String:Concat(System.String,System.String,System.String):System.String]
mov gword ptr [rbp-0x10], rax
mov rcx, gword ptr [rbp-0x10]
call [System.Console:WriteLine(System.String)]
nop

G_M000_IG05: ;; offset=0x004E
add rsp, 40
pop rdi
pop rbp
ret

; Total bytes of code 85

检查这个JIT输出, 告诉我为何它没有成功内联


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@Flithor Flithor closed this Mar 10, 2026
@Flithor Flithor deleted the copilot/optimize-casthelpers-method branch March 10, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants