Skip to content

Commit

Permalink
Optimize MethodTable on both sides of == (#87238)
Browse files Browse the repository at this point in the history
Optimizes `typeof(Foo) == typeof(Bar)` for both sides. This is necessary to get `System.Double` MethodTable from hello world again.

I tried to write a test for this but I wasn't able to come up with something in 10 minutes so I gave up. It seems to require interactions of several things to actually trigger the size bloat without this extra optimization. But this does fix the `Double` case.
  • Loading branch information
MichalStrehovsky authored Jun 8, 2023
1 parent 157996f commit 7c00b17
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,32 @@ private void ImportLdToken(int token)
nextBasicBlock = _basicBlocks[_currentOffset + 5];
if (nextBasicBlock == null)
{
// We expect pattern:
//
// ldtoken Foo
// call GetTypeFromHandle
// ldtoken Bar
// call GetTypeFromHandle
// call Equals
//
// We check for both ldtoken cases
if ((ILOpcode)_ilBytes[_currentOffset + 5] == ILOpcode.call)
{
methodToken = ReadILTokenAt(_currentOffset + 6);
method = (MethodDesc)_methodIL.GetObject(methodToken);
isTypeEquals = IsTypeEquals(method);
}
else if ((ILOpcode)_ilBytes[_currentOffset + 5] == ILOpcode.ldtoken
&& _basicBlocks[_currentOffset + 10] == null
&& (ILOpcode)_ilBytes[_currentOffset + 10] == ILOpcode.call
&& methodToken == ReadILTokenAt(_currentOffset + 11)
&& _basicBlocks[_currentOffset + 15] == null
&& (ILOpcode)_ilBytes[_currentOffset + 15] == ILOpcode.call)
{
methodToken = ReadILTokenAt(_currentOffset + 16);
method = (MethodDesc)_methodIL.GetObject(methodToken);
isTypeEquals = IsTypeEquals(method);
}
}
}
}
Expand Down

0 comments on commit 7c00b17

Please sign in to comment.