Allow inlining array methods (#88367)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Tue, 4 Jul 2023 05:48:39 +0000 (14:48 +0900)
committerGitHub <noreply@github.com>
Tue, 4 Jul 2023 05:48:39 +0000 (14:48 +0900)
commit483b98bf030065608171bffafcbc6126f6ace250
tree3e502a7745165ef832b7e40009e1f3342b3014ca
parent4d65a9af4168299f302951ae710f7d0c4f9b7647
Allow inlining array methods (#88367)

`CanInline` would return false to methods that implement generic interfaces on arrays because we didn't consider the magic `Array<T>` types constructed.

For:

```csharp
static int Main()
{
    IReadOnlyCollection<int> l = new int[] { 1, 2, 3 };
    return l.Count;
}
```

Before:

```
       sub      rsp, 40
                                                ;; size=4 bbWeight=1 PerfScore 0.25
G_M24375_IG02:  ;; offset=0004H
       lea      rcx, [(reloc 0x4000000000420a70)]      ; int[]
       mov      edx, 3
       call     CORINFO_HELP_NEWARR_1_VC
       lea      rcx, [(reloc 0x4000000000420aa8)]      ; const ptr
       mov      rdx, qword ptr [rcx]
       mov      qword ptr [rax+10H], rdx
       mov      rdx, qword ptr [rcx+04H]
       mov      qword ptr [rax+14H], rdx
       mov      rcx, rax
       call     System.Array`1[int]:get_Count():int:this
       nop
                                                ;; size=48 bbWeight=1 PerfScore 9.75
G_M24375_IG03:  ;; offset=0034H
       add      rsp, 40
       ret
```

After:

```
       sub      rsp, 40
                                                ;; size=4 bbWeight=1 PerfScore 0.25
G_M24375_IG02:  ;; offset=0004H
       lea      rcx, [(reloc 0x4000000000420a70)]      ; int[]
       mov      edx, 3
       call     CORINFO_HELP_NEWARR_1_VC
       lea      rcx, [(reloc 0x4000000000420aa8)]      ; const ptr
       mov      rdx, qword ptr [rcx]
       mov      qword ptr [rax+10H], rdx
       mov      rdx, qword ptr [rcx+04H]
       mov      qword ptr [rax+14H], rdx
       mov      eax, 3
                                                ;; size=44 bbWeight=1 PerfScore 8.50
G_M24375_IG03:  ;; offset=0030H
       add      rsp, 40
       ret
```
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs