There is a method in Ascii.Utility.cs (SPC.dll):
private static bool FirstCharInUInt32IsAscii(uint value)
{
return (BitConverter.IsLittleEndian && (value & 0xFF80u) == 0)
|| (!BitConverter.IsLittleEndian && (value & 0xFF800000u) == 0);
}
After ILLink it looks like this:
.method private hidebysig static bool
FirstCharInUInt32IsAscii(unsigned int32 'value') cil managed
{
.maxstack 8
IL_0000: ldsfld bool System.BitConverter::IsLittleEndian
IL_0005: pop
IL_0006: ldarg.0
IL_0007: ldc.i4 65408
IL_000c: and
IL_000d: brfalse.s IL_0018
IL_000f: ldsfld bool System.BitConverter::IsLittleEndian
IL_0014: brtrue.s IL_0016
IL_0016: ldc.i4.0
IL_0017: ret
IL_0018: ldc.i4.1
IL_0019: ret
}
which is roughly:
private static bool FirstCharInUInt32IsAscii(uint value)
{
int unused = BitConverter.IsLittleEndian;
if ((value & 65408) == 0)
goto RetTrue;
if (BitConverter.IsLittleEndian)
;
return false;
RetTrue:
return true;
}
So while it seems that ILLink did touch this method (thanks to #37615) it seems that it could do a better job here by replacing ldsfld bool System.BitConverter::IsLittleEndian with just ldc.i4.1, etc.
This doesn't let JIT to inline this small (in fact) method, because JIT doesn't resolve ldsfld tokens during IL prescan and it doesn't know that it's a special IsLittleEndian field that is always a constant) - it can be found in e.g. GetIndexOfFirstNonAsciiChar_Intrinsified
There is a method in
Ascii.Utility.cs(SPC.dll):After ILLink it looks like this:
.method private hidebysig static bool FirstCharInUInt32IsAscii(unsigned int32 'value') cil managed { .maxstack 8 IL_0000: ldsfld bool System.BitConverter::IsLittleEndian IL_0005: pop IL_0006: ldarg.0 IL_0007: ldc.i4 65408 IL_000c: and IL_000d: brfalse.s IL_0018 IL_000f: ldsfld bool System.BitConverter::IsLittleEndian IL_0014: brtrue.s IL_0016 IL_0016: ldc.i4.0 IL_0017: ret IL_0018: ldc.i4.1 IL_0019: ret }which is roughly:
So while it seems that ILLink did touch this method (thanks to #37615) it seems that it could do a better job here by replacing
ldsfld bool System.BitConverter::IsLittleEndianwith justldc.i4.1, etc.This doesn't let JIT to inline this small (in fact) method, because JIT doesn't resolve
ldsfldtokens during IL prescan and it doesn't know that it's a specialIsLittleEndianfield that is always a constant) - it can be found in e.g.GetIndexOfFirstNonAsciiChar_Intrinsified