Skip to content
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

Fix for Crossgen2 compilation of System.ServiceModel.Syndication #35728

Merged
merged 3 commits into from
Jun 4, 2020

Conversation

trylek
Copy link
Member

@trylek trylek commented May 1, 2020

I originally tried to use the flag CORINFO_FLG_CUSTOMLAYOUT
as suggested by JanK but that doesn't work - apparently the code at

if (StructHasCustomLayout(typeFlags) && compiler->IsHfa(typeHnd))

the CUSTOMLAYOUT flag is only honored for HFA fields.

Thanks

Tomas

/cc @dotnet/crossgen-contrib

@jkotas
Copy link
Member

jkotas commented May 1, 2020

Is there a way to run asm-diff on this to see what it does to the generated code?

@jkotas
Copy link
Member

jkotas commented May 1, 2020

Or at least have some high-level stats like code-sizes before/after.

@trylek
Copy link
Member Author

trylek commented May 1, 2020

@jkotas - my apologies, I completely forgot about that. I'll produce a pair of R2RDump outputs for comparison in a bit.

@trylek
Copy link
Member Author

trylek commented May 1, 2020

OK, here are the two dumps:

https://gist.github.com/trylek/4e5194e71fd824b28b1bfb6c0a89cc26
https://gist.github.com/trylek/bb5e35c3ce7f2d96bc8b05dc8f3097c5

I used to have a tool called SDVDiff using which I could publish a structured diff of the two dumps but I no longer have it and the codebox link is dead. From what I saw, there are some extra null checks in form of

cmp dword ptr [rcx], ecx

and some scattered bits of code changes. With the field checks commented out, the size difference for the SSS assembly is 402944 B without the change and 404480 with the change.

@jkotas
Copy link
Member

jkotas commented May 1, 2020

This change should be introducing extra null checks. I think there may be something else going on that needs to be understood.

trylek added 2 commits June 2, 2020 18:12
I originally tried to use the flag CORINFO_FLG_CUSTOMLAYOUT
as suggested by JanK but that doesn't work - apparently the code at

https://github.com/dotnet/runtime/blob/57a931b11e9ecff42bf75d2e451370af904c0992/src/coreclr/src/jit/lclvars.cpp#L1696

the CUSTOMLAYOUT flag is only honored for HFA fields.

Thanks

Tomas
I have added a new flag to suppress field promotion for types
outside of the compilation version bubble. I have also fixed two
other small inconsistencies I noticed in the investigation:

1) I have changed getClassName to use TypeString as the output
matches Crossgen1 and makes NGenDump outputs easier to compare.

2) When I was comparing the NGen dumps, I noticed a check in
Crossgen1 missing in Crossgen2 - only setting
CORINFO_FLG_BEFOREFIELDINIT for types in the same version bubble;
so I made it conditional in Crossgen2 too:

https://github.com/dotnet/runtime/blob/f9d3e6f2151d090f3fc3eae1965b2339f7a5428e/src/coreclr/src/vm/jitinterface.cpp#L3925

Thanks

Tomas
Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jit changes LGTM.

Normally we would update the jit guid for jit flag changes. but I think it's ok to skip that for this change.

@@ -1357,6 +1366,14 @@ private uint getClassAttribsInternal(TypeDesc type)
result |= CorInfoFlag.CORINFO_FLG_ABSTRACT;
}

#if READYTORUN
if (!_compilation.NodeFactory.CompilationModuleGroup.VersionsWithType(type))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be _compilation.CompilationModuleGroup like above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed in 3rd commit (including one other place in the file).

result |= CorInfoFlag.CORINFO_FLG_BEFOREFIELDINIT;
{
#if READYTORUN
if (_compilation.CompilationModuleGroup.VersionsWithType(metadataType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to clear the flag CORINFO_FLG_BEFOREFIELDINIT at the end instead. One less #if READYTORUN ifdef and one less call to VersionsWithType.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the suggestion, fixed in 3rd commit.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to check the impact on codegen.

@trylek trylek merged commit 8d02f6a into dotnet:master Jun 4, 2020
@trylek trylek deleted the CustomLayout branch June 4, 2020 09:08
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants