Skip to content

Weird inlining of methods optimized by JIT #47434

@Tearth

Description

@Tearth

Description

I've spotted some weird behavior in code generated by JIT. The image below is self-explaining but a short description from me: we have two similar methods, optimized to the same form (which is just a simple asm instruction, like blsr here). In theory, both should be inlined just looking at their size, but apparently, JIT does it only for the first method as shown below.

Data

image

Here is the link to this snippet: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABABgAJiBGAOgCUBXAOwwEt8YaBhCfAB1YAbGFADKIgG6swMXAG4AsAChlTbB1x9sM8gAUIfADK5gAFVkZlAb2Xk7lAEyUqAdlv2bS+9+dJyDQQgmAHNyBEUvHztqP2IUcgBZbFYmAAoASncozyiohHIAXj0DY2AqVKpSUnSI3J98ov0jEwcKqpqsnwBfTu9e+xj/QJDi5rLUgKDQiWxBBhhMyOz+qOIXZ3pmNg4aAEkWKBTcaVwaAA0ADiQaACF8Vloz1HpZGAxDCAB3C3EMG9YMKkZnMFrVcj0lj4Vr4hlNRqVWpMRsD5os6jk6vZWAAzcipaibFjsTj7DCHJjHMCnS7XO4PPa4UQMPh8aAYGAAEzRmLsGJ53jWG0YRJ2pPJlOpV1u90ezzor3eXx+b3+gJRoOh3gh/PIMEEuBgmo8RtW63V5AAZHjzXByFQOpC6trwZ0IV0gA==

Analysis

We can force the second method to be inlined by [MethodImpl(MethodImplOptions.AggressiveInlining)], in this case, it behaves exactly the same as the first one.

category:cq
theme:inlining
skill-level:expert
cost:large

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions