Skip to content

Commit 7c00b17

Browse files
Optimize MethodTable on both sides of == (#87238)
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.
1 parent 157996f commit 7c00b17

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs

+20
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,32 @@ private void ImportLdToken(int token)
929929
nextBasicBlock = _basicBlocks[_currentOffset + 5];
930930
if (nextBasicBlock == null)
931931
{
932+
// We expect pattern:
933+
//
934+
// ldtoken Foo
935+
// call GetTypeFromHandle
936+
// ldtoken Bar
937+
// call GetTypeFromHandle
938+
// call Equals
939+
//
940+
// We check for both ldtoken cases
932941
if ((ILOpcode)_ilBytes[_currentOffset + 5] == ILOpcode.call)
933942
{
934943
methodToken = ReadILTokenAt(_currentOffset + 6);
935944
method = (MethodDesc)_methodIL.GetObject(methodToken);
936945
isTypeEquals = IsTypeEquals(method);
937946
}
947+
else if ((ILOpcode)_ilBytes[_currentOffset + 5] == ILOpcode.ldtoken
948+
&& _basicBlocks[_currentOffset + 10] == null
949+
&& (ILOpcode)_ilBytes[_currentOffset + 10] == ILOpcode.call
950+
&& methodToken == ReadILTokenAt(_currentOffset + 11)
951+
&& _basicBlocks[_currentOffset + 15] == null
952+
&& (ILOpcode)_ilBytes[_currentOffset + 15] == ILOpcode.call)
953+
{
954+
methodToken = ReadILTokenAt(_currentOffset + 16);
955+
method = (MethodDesc)_methodIL.GetObject(methodToken);
956+
isTypeEquals = IsTypeEquals(method);
957+
}
938958
}
939959
}
940960
}

0 commit comments

Comments
 (0)