Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Workaround for compiler.hpp (1848) - Assertion failed 'lvRefCnt' #18292

Merged
merged 4 commits into from
Jun 8, 2018

Conversation

sandreenko
Copy link

@sandreenko sandreenko commented Jun 4, 2018

The description is in #18291.

The fix is to replace JTRUE relop before morph the list of its side effects. In this case when we have fgRemoveRestOfBlock and call fgRemoveStmt it removes updated JTRUE and this part works correct.

The problem that optVNConstantPropCurStmt could receive a statement that was already removed still exists.

@sandreenko sandreenko added the bug Product bug (most likely) label Jun 4, 2018
@sandreenko sandreenko changed the title add repro for 18291 add repro for compiler.hpp (1848) - Assertion failed 'lvRefCnt' Jun 4, 2018
@sandreenko
Copy link
Author

@sandreenko sandreenko changed the title add repro for compiler.hpp (1848) - Assertion failed 'lvRefCnt' Workaround for compiler.hpp (1848) - Assertion failed 'lvRefCnt' Jun 5, 2018
@sandreenko
Copy link
Author

PTAL @dotnet/jit-contrib

@sandreenko
Copy link
Author

@dotnet-bot test Windows_NT x64 Checked jitstress2
@dotnet-bot test Windows_NT x86 Checked jitstress2

@AndyAyersMS
Copy link
Member

Our ambition is to remove all incremental ref count maintenance -- in part because of issues like this -- in the not too distant future.

So if this is some kind of artificial bug case, perhaps we can just hold off fixing it for now?

@AndyAyersMS
Copy link
Member

Going to re-trigger the formatting tests to make sure my recent jitutils update is OK.

@dotnet-bot test Windows_NT x64 Formatting

@AndyAyersMS
Copy link
Member

Yep, looks to be ok:

08:16:01   Restore completed in 41.58 ms for D:\j\workspace\x64_windows_n---616f30f2\jitutils\src\pmi\PMI.csproj.
08:16:02   PMI -> D:\j\workspace\x64_windows_n---616f30f2\jitutils\src\pmi\bin\win81-x64\Release\netcoreapp2.1\PMI.dll
08:16:02   PMI -> D:\j\workspace\x64_windows_n---616f30f2\jitutils\bin\
08:16:02         1 file(s) copied.

@sandreenko
Copy link
Author

So if this is some kind of artificial bug case

Yes, it is an artificial bug case, however, I think it can be recreated with C# code.

Our ambition is to remove all incremental ref count maintenance -- in part because of issues like this -- in the not too distant future.

Do we have an issue to track that ambition?
The problem is not only that we decrease counters twice, but also that we remove other trees twice. The PR makes things better, we replace JTRUE relop with a new created tree and then start extracting and morphing side effects, it means we do not have a moment when IR has duplicates, as it was before (JTRUE has old relop tree and part of it was already extracted and inserted before JTRUE). So we need this change even after removing all incremental ref count maintenance.

perhaps we can just hold off fixing it for now?

I do not see why we should hold it.

@sandreenko
Copy link
Author

Could somebody pls take a look, @dotnet/jit-contrib ?

@AndyAyersMS
Copy link
Member

Issue for incremental ref count removal is #13280.

The change you made looks ok but it rreallly needs a comment saying why things must be done in this particular order as it's not obvious.

I wonder how many other places we may have similar ordering issues and haven't hit the right test case yet?

I'm also surprised we don't hit other asserts when trying to remove trees twice. Seems like we should be calling DEBUG_DESTROY_NODE in fgRemoveStmt. Though I recall being confused as to what the expected behavior of this method was in the past (#8059)-- it seemingly can't destroy everything in the statement. But perhaps it can destroy the statement expression?

@sandreenko
Copy link
Author

sandreenko commented Jun 7, 2018

I'm also surprised we don't hit other asserts when trying to remove trees twice. Seems like we should be calling DEBUG_DESTROY_NODE in fgRemoveStmt. Though I recall being confused as to what the expected behavior of this method was in the past (#8059)-- it seemingly can't destroy everything in the statement. But perhaps it can destroy the statement expression?

It was my first idea :-), but it appeared that you can't do it, because we usefgRemoveStmt to move statements, like fgRemoveStmt from here and fgInsertStmt there. I thought about adding a debug flag removed and check it there, but I think it should be a separate change.

Yes, I think it would be a good idea to separate remove for move and remove as delete and destroy.

@sandreenko
Copy link
Author

The change you made looks ok but it rreallly needs a comment saying why things must be done in this particular order as it's not obvious.

Sounds reasonable, I will think how to describe it better.

Copy link

@briansull briansull left a comment

Choose a reason for hiding this comment

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

Looks Good

@sandreenko
Copy link
Author

I have added 2 comments to explain it better.

I think we should add a separate issue to better check and assert flowGraph transformations.

For example in the existing code when JTRUE has two side effects, THROW and something else, and THROW goes first, that code

    while (sideEffList != nullptr) <- sideEffList = {THROW, smth else}
    {
        GenTree* newStmt;
        if (sideEffList->OperGet() == GT_COMMA)
        {
            newStmt     = fgInsertStmtNearEnd(block, sideEffList->gtGetOp1());
            sideEffList = sideEffList->gtGetOp2();
        }
        else
        {
            newStmt     = fgInsertStmtNearEnd(block, sideEffList); <-- will delete stmts after THROW, including JTRUE on the first iteration.
            sideEffList = nullptr;
        }
        // fgMorphBlockStmt could potentially affect stmts after the current one,
        // for example when it decides to fgRemoveRestOfBlock.
        fgMorphBlockStmt(block, newStmt->AsStmt() DEBUGARG(__FUNCTION__));
    }

on the second iteration something else will call fgInsertStmtNearEnd and the statement will be inserted after THROW without any need.

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.

Thanks for the comment. Looks good.

@sandreenko sandreenko merged commit 16169a8 into dotnet:master Jun 8, 2018
@sandreenko sandreenko deleted the Fix18291 branch June 29, 2018 20:40
AndyAyersMS added a commit that referenced this pull request Jul 4, 2018
The issue the test was hitting was worked around in #18292.

Fixes #17967.

Also add GitHub_18522_8 to the arm/arm64 lists (from #18708).
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…net/coreclr#18292)

* add test

* clean fgRemoveStmt a bit

* fix the issue (more like a workaround).


Commit migrated from dotnet/coreclr@16169a8
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Product bug (most likely)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants