Skip to content

Commit

Permalink
Allow inlining array methods (#88367)
Browse files Browse the repository at this point in the history
`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
```
  • Loading branch information
MichalStrehovsky authored Jul 4, 2023
1 parent 4d65a9a commit 483b98b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ public ScannedInliningPolicy(CompilationModuleGroup baseGroup, ImmutableArray<De
{
TypeDesc type = eetypeNode.Type;
_constructedTypes.Add(type);

// It's convenient to also see Array<T> as constructed for each T[]
DefType closestDefType = type.GetClosestDefType();
if (closestDefType != type)
_constructedTypes.Add(closestDefType);
}
}
}
Expand Down

0 comments on commit 483b98b

Please sign in to comment.