Skip to content
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

[X64] [MichalPetryka] Remove invalid Unsafe.As from array helpers #332

Open
MihuBot opened this issue Mar 17, 2024 · 3 comments
Open

[X64] [MichalPetryka] Remove invalid Unsafe.As from array helpers #332

MihuBot opened this issue Mar 17, 2024 · 3 comments

Comments

@MihuBot
Copy link
Owner

MihuBot commented Mar 17, 2024

Build completed in 30 minutes.
dotnet/runtime#99778

Diffs

Found 309 files with textual diffs.

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 38726719
Total bytes of diff: 38726783
Total bytes of delta: 64 (0.00 % of base)
Total relative delta: -0.13
    diff is a regression.
    relative diff is an improvement.


Total byte diff includes 58 bytes from reconciling methods
	Base had    3 unique methods,      180 unique bytes
	Diff had    4 unique methods,      238 unique bytes

Top file regressions (bytes):
          64 : System.Private.CoreLib.dasm (0.00 % of base)

1 total files with Code Size differences (0 improved, 1 regressed), 255 unchanged.

Top method regressions (bytes):
          98 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Object[],long,System.Object) (FullOpts) (0 base, 1 diff methods)
          54 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Object[],long,ulong):byref (FullOpts) (0 base, 1 diff methods)
          43 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException() (FullOpts) (0 base, 1 diff methods)
          43 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowIndexOutOfRangeException() (FullOpts) (0 base, 1 diff methods)
          35 (19.77 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object) (FullOpts)

Top method improvements (bytes):
         -91 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Array,long,System.Object) (FullOpts) (1 base, 0 diff methods)
         -46 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Array,long,ulong):byref (FullOpts) (1 base, 0 diff methods)
         -43 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException():byref (FullOpts) (1 base, 0 diff methods)
         -29 (-32.58 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object) (FullOpts)

Top method regressions (percentages):
          54 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Object[],long,ulong):byref (FullOpts) (0 base, 1 diff methods)
          98 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Object[],long,System.Object) (FullOpts) (0 base, 1 diff methods)
          43 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException() (FullOpts) (0 base, 1 diff methods)
          43 (Infinity of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowIndexOutOfRangeException() (FullOpts) (0 base, 1 diff methods)
          35 (19.77 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object) (FullOpts)

Top method improvements (percentages):
         -46 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Array,long,ulong):byref (FullOpts) (1 base, 0 diff methods)
         -91 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Array,long,System.Object) (FullOpts) (1 base, 0 diff methods)
         -43 (-100.00 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException():byref (FullOpts) (1 base, 0 diff methods)
         -29 (-32.58 % of base) : System.Private.CoreLib.dasm - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object) (FullOpts)

9 total methods with Code Size differences (4 improved, 5 regressed), 239700 unchanged.

--------------------------------------------------------------------------------

Artifacts:

@MihuBot
Copy link
Owner Author

MihuBot commented Mar 17, 2024

Top method regressions

35 (19.77 % of base) - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object)
 ; Assembly listing for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object) (FullOpts)
 ; Emitting BLENDED_CODE for X64 with AVX - Unix
 ; FullOpts code
 ; optimized code
 ; rbp based frame
 ; fully interruptible
 ; No PGO data
-; 0 inlinees with PGO data; 7 single block inlinees; 1 inlinees without PGO data
+; 0 inlinees with PGO data; 7 single block inlinees; 2 inlinees without PGO data
 ; Final local variable assignments
 ;
-;  V00 arg0         [V00,T09] (  4,  3   )   byref  ->  rdi         single-def
+;  V00 arg0         [V00,T09] (  4,  3   )   byref  ->  rbx         single-def
 ;  V01 arg1         [V01,T07] (  5,  5.50)    long  ->  rsi         single-def
-;  V02 arg2         [V02,T08] (  5,  4   )     ref  ->  rdx         class-hnd single-def <System.Object>
+;  V02 arg2         [V02,T08] (  5,  4   )     ref  ->  rax         class-hnd single-def <System.Object>
 ;* V03 loc0         [V03    ] (  0,  0   )     int  ->  zero-ref   
 ;# V04 OutArgs      [V04    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
-;  V05 tmp1         [V05,T11] (  2,  4   )     ref  ->  rax         class-hnd single-def "impAppendStmt" <int[]>
-;  V06 tmp2         [V06,T12] (  2,  1   )     int  ->  rbx         "Inline return value spill temp"
-;  V07 tmp3         [V07,T05] (  4, 10   )   byref  ->  rax         single-def "Inline stloc first use temp"
+;  V05 tmp1         [V05,T11] (  2,  4   )     ref  ->  rdi         class-hnd single-def "impAppendStmt" <int[]>
+;  V06 tmp2         [V06,T13] (  2,  1   )     int  ->  r11         "Inline return value spill temp"
+;  V07 tmp3         [V07,T05] (  4, 10   )   byref  ->  rdi         single-def "Inline stloc first use temp"
 ;  V08 tmp4         [V08,T04] (  3, 12   )    long  ->  rcx         "Inlining Arg"
-;  V09 tmp5         [V09,T03] (  4, 13   )     int  ->   r8         "Inline stloc first use temp"
-;  V10 tmp6         [V10,T00] (  5, 17   )     int  ->   r9         "Inline stloc first use temp"
-;  V11 tmp7         [V11,T02] (  5, 14.50)   byref  ->  r10         "Inline stloc first use temp"
-;  V12 tmp8         [V12,T01] (  5, 16.50)     int  ->  r11         "Inline stloc first use temp"
-;  V13 tmp9         [V13,T06] (  2,  8   )    long  ->  rbx         "Inline stloc first use temp"
-;  V14 tmp10        [V14,T10] (  3,  4.50)    long  ->  rbx         "Inline stloc first use temp"
+;  V09 tmp5         [V09,T03] (  4, 13   )     int  ->  rdx         "Inline stloc first use temp"
+;  V10 tmp6         [V10,T00] (  5, 17   )     int  ->   r8         "Inline stloc first use temp"
+;  V11 tmp7         [V11,T02] (  5, 14.50)   byref  ->   r9         "Inline stloc first use temp"
+;  V12 tmp8         [V12,T01] (  5, 16.50)     int  ->  r10         "Inline stloc first use temp"
+;  V13 tmp9         [V13,T06] (  2,  8   )    long  ->  r11         "Inline stloc first use temp"
+;  V14 tmp10        [V14,T10] (  3,  4.50)    long  ->  r11         "Inline stloc first use temp"
 ;* V15 tmp11        [V15    ] (  0,  0   )     int  ->  zero-ref    "Inline stloc first use temp"
 ;* V16 tmp12        [V16    ] (  0,  0   )    long  ->  zero-ref    "Inline stloc first use temp"
+;  V17 tmp13        [V17,T12] (  3,  3   )     ref  ->  rax         class-hnd single-def "Inlining Arg" <System.Object>
 ;
 ; Lcl frame size = 8
 
 G_M34926_IG01:
        push     rbp
        push     rbx
        push     rax
        lea      rbp, [rsp+0x10]
-						;; size=8 bbWeight=1 PerfScore 3.50
+       mov      rbx, rdi
+       mov      rax, rdx
+						;; size=14 bbWeight=1 PerfScore 4.00
 G_M34926_IG02:
-       mov      rax, 0xD1FFAB1E      ; data for System.Runtime.CompilerServices.CastHelpers:s_table
-       mov      rax, gword ptr [rax]
-       mov      rcx, qword ptr [rdx]
-       add      rax, 16
-       rorx     r8, rcx, 32
-       xor      r8, rsi
-       mov      r9, 0xD1FFAB1E
-       imul     r8, r9
-       mov      r9d, dword ptr [rax]
-       shrx     r8, r8, r9
-       xor      r9d, r9d
-       align    [2 bytes for IG03]
-						;; size=56 bbWeight=1 PerfScore 10.50
+       mov      rdi, 0xD1FFAB1E      ; data for System.Runtime.CompilerServices.CastHelpers:s_table
+       mov      rdi, gword ptr [rdi]
+       mov      rcx, qword ptr [rax]
+       add      rdi, 16
+       rorx     rdx, rcx, 32
+       xor      rdx, rsi
+       mov      r8, 0xD1FFAB1E
+       imul     rdx, r8
+       mov      r8d, dword ptr [rdi]
+       shrx     rdx, rdx, r8
+       xor      r8d, r8d
+       align    [0 bytes for IG03]
+						;; size=54 bbWeight=1 PerfScore 10.25
 G_M34926_IG03:
-       lea      r10d, [r8+0x01]
-       movsxd   r10, r10d
-       lea      r10, [r10+2*r10]
-       lea      r10, bword ptr [rax+8*r10]
-       mov      r11d, dword ptr [r10]
-       mov      rbx, qword ptr [r10+0x08]
-       and      r11d, -2
-       cmp      rbx, rcx
+       lea      r9d, [rdx+0x01]
+       movsxd   r9, r9d
+       lea      r9, [r9+2*r9]
+       lea      r9, bword ptr [rdi+8*r9]
+       mov      r10d, dword ptr [r9]
+       mov      r11, qword ptr [r9+0x08]
+       and      r10d, -2
+       cmp      r11, rcx
        jne      SHORT G_M34926_IG05
 						;; size=31 bbWeight=4 PerfScore 29.00
 G_M34926_IG04:
-       mov      rbx, rsi
-       xor      rbx, qword ptr [r10+0x10]
-       cmp      rbx, 1
+       mov      r11, rsi
+       xor      r11, qword ptr [r9+0x10]
+       cmp      r11, 1
        jbe      SHORT G_M34926_IG06
 						;; size=13 bbWeight=2 PerfScore 9.00
 G_M34926_IG05:
-       test     r11d, r11d
+       test     r10d, r10d
        je       SHORT G_M34926_IG08
-       inc      r9d
-       add      r8d, r9d
-       and      r8d, dword ptr [rax+0x04]
-       cmp      r9d, 8
+       inc      r8d
+       add      edx, r8d
+       and      edx, dword ptr [rdi+0x04]
+       cmp      r8d, 8
        jl       SHORT G_M34926_IG03
        jmp      SHORT G_M34926_IG08
-						;; size=23 bbWeight=4 PerfScore 32.00
+						;; size=22 bbWeight=4 PerfScore 32.00
 G_M34926_IG06:
-       cmp      r11d, dword ptr [r10]
+       cmp      r10d, dword ptr [r9]
        jne      SHORT G_M34926_IG08
-       cmp      ebx, 1
+       cmp      r11d, 1
        jne      SHORT G_M34926_IG08
-       mov      rsi, rdx
+       mov      rdi, rbx
+       mov      rsi, rax
        call     System.Runtime.CompilerServices.CastHelpers:WriteBarrier(byref,System.Object)
        nop      
-						;; size=19 bbWeight=0.50 PerfScore 3.38
+						;; size=23 bbWeight=0.50 PerfScore 3.50
 G_M34926_IG07:
        add      rsp, 8
        pop      rbx
        pop      rbp
        ret      
 						;; size=7 bbWeight=0.50 PerfScore 1.12
 G_M34926_IG08:
-       mov      rax, 0xD1FFAB1E      ; code for System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object)
-       call     [rax]System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object)
+       mov      rdi, rsi
+       mov      rsi, rax
+       call     System.Runtime.CompilerServices.CastHelpers:IsInstanceOfAny_NoCacheLookup(ulong,System.Object):System.Object
+       test     rax, rax
+       je       SHORT G_M34926_IG10
+       mov      rdi, rbx
+       mov      rsi, rax
+       call     System.Runtime.CompilerServices.CastHelpers:WriteBarrier(byref,System.Object)
        nop      
-						;; size=13 bbWeight=0.50 PerfScore 1.75
+						;; size=28 bbWeight=0.50 PerfScore 2.25
 G_M34926_IG09:
        add      rsp, 8
        pop      rbx
        pop      rbp
        ret      
 						;; size=7 bbWeight=0.50 PerfScore 1.12
+G_M34926_IG10:
+       mov      rax, 0xD1FFAB1E      ; code for System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException()
+       call     [rax]System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException()
+       int3     
+						;; size=13 bbWeight=0 PerfScore 0.00
 
-; Total bytes of code 177, prolog size 8, PerfScore 91.38, instruction count 55, allocated bytes for code 177 (MethodHash=f2f07791) for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object) (FullOpts)
+; Total bytes of code 212, prolog size 14, PerfScore 92.25, instruction count 67, allocated bytes for code 212 (MethodHash=f2f07791) for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper(byref,ulong,System.Object) (FullOpts)

@MihuBot
Copy link
Owner Author

MihuBot commented Mar 17, 2024

Top method improvements

-29 (-32.58 % of base) - System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object)
 ; Assembly listing for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object) (FullOpts)
 ; Emitting BLENDED_CODE for X64 with AVX - Unix
 ; FullOpts code
 ; optimized code
 ; rbp based frame
 ; fully interruptible
 ; No PGO data
 ; Final local variable assignments
 ;
 ;  V00 arg0         [V00,T01] (  3,  3   )   byref  ->  rbx         single-def
 ;  V01 arg1         [V01,T02] (  3,  3   )    long  ->  rsi         single-def
 ;  V02 arg2         [V02,T00] (  6,  6   )     ref  ->  rax         class-hnd <System.Object>
 ;# V03 OutArgs      [V03    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
-;  V04 tmp1         [V04,T03] (  3,  0   )     ref  ->  rbx         class-hnd exact single-def "NewObj constructor temp" <System.ArrayTypeMismatchException>
 ;
 ; Lcl frame size = 8
 
 G_M14814_IG01:
        push     rbp
        push     rbx
        push     rax
        lea      rbp, [rsp+0x10]
        mov      rbx, rdi
        mov      rax, rdx
 						;; size=14 bbWeight=1 PerfScore 4.00
 G_M14814_IG02:
        mov      rdi, rsi
        mov      rsi, rax
        call     System.Runtime.CompilerServices.CastHelpers:IsInstanceOfAny_NoCacheLookup(ulong,System.Object):System.Object
        test     rax, rax
        je       SHORT G_M14814_IG04
        mov      rdi, rbx
        mov      rsi, rax
 						;; size=22 bbWeight=1 PerfScore 3.25
 G_M14814_IG03:
        add      rsp, 8
        pop      rbx
        pop      rbp
        jmp      System.Runtime.CompilerServices.CastHelpers:WriteBarrier(byref,System.Object)
 						;; size=11 bbWeight=1 PerfScore 3.25
 G_M14814_IG04:
-       mov      rdi, 0xD1FFAB1E      ; System.ArrayTypeMismatchException
-       call     CORINFO_HELP_NEWSFAST
-       mov      rbx, rax
-       mov      rdi, rbx
-       mov      rax, 0xD1FFAB1E      ; code for System.ArrayTypeMismatchException:.ctor():this
-       call     [rax]System.ArrayTypeMismatchException:.ctor():this
-       mov      rdi, rbx
-       call     CORINFO_HELP_THROW
+       mov      rax, 0xD1FFAB1E      ; code for System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException()
+       call     [rax]System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException()
        int3     
-						;; size=42 bbWeight=0 PerfScore 0.00
+						;; size=13 bbWeight=0 PerfScore 0.00
 
-; Total bytes of code 89, prolog size 14, PerfScore 10.50, instruction count 26, allocated bytes for code 89 (MethodHash=29c6c621) for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object) (FullOpts)
+; Total bytes of code 60, prolog size 14, PerfScore 10.50, instruction count 20, allocated bytes for code 60 (MethodHash=29c6c621) for method System.Runtime.CompilerServices.CastHelpers:StelemRef_Helper_NoCacheLookup(byref,ulong,System.Object) (FullOpts)

@MihuBot
Copy link
Owner Author

MihuBot commented Mar 17, 2024

@MichalPetryka

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

No branches or pull requests

1 participant