-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue
Milestone
Description
Functions using stackalloc will fail to inline with reason unknown opcode
Discovered this as part of this PR davidfowl/Channels#145 (should have probably raised it then)
Example function that will fail to inline even with aggressive inlinining
public unsafe bool TrySliceTo(byte b1, byte b2, out ReadableBuffer slice, out ReadCursor cursor)
{
byte* twoBytes = stackalloc byte[2];
twoBytes[0] = b1;
twoBytes[1] = b2;
return TrySliceTo(new Span<byte>(twoBytes, 2), out slice, out cursor);
}Changed function that will inline successfully without aggressive inlinining
public unsafe bool TrySliceTo(byte b1, byte b2, out ReadableBuffer slice, out ReadCursor cursor)
{
// use address of ushort rather than stackalloc as the inliner won't inline functions with stackalloc
ushort twoBytes;
byte* byteArray = (byte*)&twoBytes;
byteArray[0] = b1;
byteArray[1] = b2;
return TrySliceTo(new Span<byte>(byteArray, 2), out slice, out cursor);
}/cc @AndyAyersMS @JosephTremoulet
category:cq
theme:inlining
skill-level:expert
cost:medium
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue