-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ILLink substitute BitConverter.IsLittleEndian as true constant #83169
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsThere is a method in 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 This doesn't let JIT to inline this small (in fact) method, because JIT doesn't resolve
|
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsThere is a method in 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 This doesn't let JIT to inline this small (in fact) method, because JIT doesn't resolve
|
Is linker keeping the |
Should the JIT start doing that in Tier1 or AOT modes to give the right treatment to initialized readonly fields? |
If it's the access to the substituted field (and not a propagated constant) I think it should be OK to remove the |
I'll take a look |
Correct, we didn't put any effort yet to teach linker how to trim static constructors bodies and for that reason we also keep anything that could static ctor even when applying the substitutions. |
It seems that even if I remove static constructor from |
Ah, the lambda in https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs#L672 still keeps it 😞 - presumably, can be replaced with string.FastAllocate |
There is a method in
Ascii.Utility.cs
(SPC.dll):After ILLink it looks like this:
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::IsLittleEndian
with justldc.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 specialIsLittleEndian
field that is always a constant) - it can be found in e.g.GetIndexOfFirstNonAsciiChar_Intrinsified
The text was updated successfully, but these errors were encountered: