Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

Adds a test that compiles with CFG enabled and then re-runs itself to crash in various ways.

Adds a test that compiles with CFG enabled and then re-runs itself to crash in various ways.
@MichalStrehovsky
Copy link
Member Author

@jakobbotsch looks like the Debug leg is failing with a RyuJIT assert Assertion failed '!op1->OperIs(GT_LCL_VAR_ADDR) && "missed an opt opportunity"' in 'Internal.Runtime.CompilerServices.OpenMethodResolver:get_GVMMethodHandle():System.RuntimeMethodHandle:this' during 'Forward Substitution' (IL size 23). Does it look related to CFG? It's possible it's just an artifact of forcing RyuJIT optimizations on unoptimized IL (CoreLib in this test is not optimized, but I'm enabling optimizations in RyuJIT. Maybe I shouldn't do that.)

Also apparently in the CI the exit code of a process that was shut down by CFG is 57005 (0xDEAD) and not 0xC0000409 that I'm seeing locally ¯_(ツ)_/¯.

@jakobbotsch
Copy link
Member

@jakobbotsch looks like the Debug leg is failing with a RyuJIT assert Assertion failed '!op1->OperIs(GT_LCL_VAR_ADDR) && "missed an opt opportunity"' in 'Internal.Runtime.CompilerServices.OpenMethodResolver:get_GVMMethodHandle():System.RuntimeMethodHandle:this' during 'Forward Substitution' (IL size 23). Does it look related to CFG? It's possible it's just an artifact of forcing RyuJIT optimizations on unoptimized IL (CoreLib in this test is not optimized, but I'm enabling optimizations in RyuJIT. Maybe I shouldn't do that.)

Forward sub is quite new and runs before any CFG related transformation, so I don't think it is related. Cc @AndyAyersMS

Also apparently in the CI the exit code of a process that was shut down by CFG is 57005 (0xDEAD) and not 0xC0000409 that I'm seeing locally ¯_(ツ)_/¯.

😄

@AndyAyersMS
Copy link
Member

Forward sub is quite new and runs before any CFG

Forward Sub is calling a morph utility before morph has run, so presumably some precondition isn't satisfied. I'm not sure what that assert is trying to tell us but it looks like we can just remove it.

@sandreenko if you get a chance -- can you explain the assert added to fgMorphTryFoldObjAsLclVar in 6cccee5 ?

@sandreenko
Copy link
Contributor

Forward sub is quite new and runs before any CFG

Forward Sub is calling a morph utility before morph has run, so presumably some precondition isn't satisfied. I'm not sure what that assert is trying to tell us but it looks like we can just remove it.

@sandreenko if you get a chance -- can you explain the assert added to fgMorphTryFoldObjAsLclVar in 6cccee5 ?

Hi Andy, the idea was the following: I wanted fgMorphTryFoldObjAsLclVar to be called from different places and phases, one example is in the header: call(obj struct(add(lcl_var)), but it required more work. So I left this function working only with copy block sources and the function did not support trees that we did not expect to see there, for example, GT_LCL_VAR_ADDR.
The firing assert says that now we see GT_LCL_VAR_ADDR there and we need to support it in order for this optimization to work. The code after handles (GT_ADDR(GT_LCL_VAR)), you should just add another condition for GT_LCL_VAR_ADDR with the same logic that compares class layouts and replaces OBJ(LCL_VAR_ADDR) with (LCL_VAR) when they match.

@AndyAyersMS
Copy link
Member

@sandreenko thanks.
@MichalStrehovsky I will work up a fix in the jit for this.

@AndyAyersMS
Copy link
Member

@MichalStrehovsky see if AndyAyersMS@5658ec9 fixes your issue, if so you can fold it in here or I can PR separately.

@MichalStrehovsky
Copy link
Member Author

@MichalStrehovsky see if AndyAyersMS@5658ec9 fixes your issue, if so you can fold it in here or I can PR separately.

Thank you! I folded it in.

@MichalStrehovsky
Copy link
Member Author

Now it's D:\a\_work\1\s\src\coreclr\jit\compiler.h:1063 Assertion failed 'varTypeIsStruct(lvType)' in 'Internal.Runtime.CompilerServices.OpenMethodResolver:get_GVMMethodHandle():System.RuntimeMethodHandle:this' during 'Forward Substitution' (IL size 23).

@MichalStrehovsky
Copy link
Member Author

I don't really need the mode where we compile debug-compiled CoreLib with RyuJIT optimizations so this is not a blocker (it's what I meant with "Maybe I shouldn't do that." above).

Unless the failure looks interesting for the general "make sure this works for IL patterns generated by compilers other than Roslyn". It's not high pri from my side.

@AndyAyersMS
Copy link
Member

Seems like this could come up more generally. The call to fgMorphTryFoldObjAsLclVar is optional so I'll just bypass it in this case. Updated my branch with 2 commits (revert, rework).

@MichalStrehovsky
Copy link
Member Author

The NativeAOT legs now look good! Thanks Andy!

@jakobbotsch Could you review the JIT change too? While I 100% trust Andy's code, I don't want to merge something that didn't go through code review and I'm not qualified.

@MichalStrehovsky MichalStrehovsky merged commit 3494d72 into dotnet:main Feb 15, 2022
@MichalStrehovsky MichalStrehovsky deleted the cfgTest branch February 15, 2022 08:18
@ghost ghost locked as resolved and limited conversation to collaborators Mar 17, 2022
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.

4 participants