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

JIT: refactor how opaque VNs are represented #55853

Merged
merged 2 commits into from
Jul 19, 2021

Conversation

AndyAyersMS
Copy link
Member

Use a unary function to capture opaque VN loop dependence, rather than factoring
that out as part of the owning chunk. As a result the VN chunk data no longer
has a per-loop component (no dependence on MAX_LOOP_NUM).

This gives us the flexibility to address #54118 by doing something similar for
MapUpdate VNs.

Use a unary function to capture opaque VN loop dependence, rather than factoring
that out as part of the owning chunk. As a result the VN chunk data no longer
has a per-loop component (no dependence on MAX_LOOP_NUM).

This gives us the flexibility to address dotnet#54118 by doing something similar for
`MapUpdate` VNs.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 16, 2021
@AndyAyersMS
Copy link
Member Author

@briansull PTAL
cc @dotnet/jit-contrib

No diffs (per SPMI).

I can add a second commit with the remainder of the fix for #54118 here, but would prefer to merge this as a preparatory no-diff change.

@@ -6582,21 +6587,6 @@ bool Compiler::optVNIsLoopInvariant(ValueNum vn, unsigned lnum, VNToBoolMap* loo
}
}
}
else
Copy link
Contributor

@briansull briansull Jul 16, 2021

Choose a reason for hiding this comment

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

You are removing this block of code.

How was this used prior to your changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

The then clause now handles that bit of logic (via the VNF_MemOpaque addition).

@@ -454,7 +454,7 @@ ValueNumStore::ValueNumStore(Compiler* comp, CompAllocator alloc)
// We have no current allocation chunks.
for (unsigned i = 0; i < TYP_COUNT; i++)
{
for (unsigned j = CEA_None; j <= CEA_Count + BasicBlock::MAX_LOOP_NUM; j++)
for (unsigned j = CEA_Const; j <= CEA_Count; j++)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change a bug-fix, as we weren't fully initializing things?

Copy link
Contributor

@briansull briansull Jul 16, 2021

Choose a reason for hiding this comment

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

I see now that you are just removing the MAX_LOOP_NUM stuff.
Your change deletes CEA_None as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, we no longer need the CEA_None chunks.

Chunk* c = GetAllocChunk(typ, CEA_Func1);
unsigned offsetWithinChunk = c->AllocVN();
ValueNum resultVN = c->m_baseVN + offsetWithinChunk;
reinterpret_cast<VNDefFunc1Arg*>(c->m_defs)[offsetWithinChunk] = fstruct;
Copy link
Contributor

Choose a reason for hiding this comment

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

This assignment looks odd and is hard to parse.
If it can't be written as a typical assignment, then add a comment with an explanation.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean the last line there? That is what all of the VNForFunc overloads do -- I just "inlined" the unary case here since for these opaque VNs we don't memoize.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see it written here using two lines:

ValueNum ValueNumStore::VnForConst(T cnsVal, NumMap* numMap, var_types varType)

        T* chunkDefs                 = reinterpret_cast<T*>(chunk->m_defs);
        chunkDefs[offsetWithinChunk] = cnsVal;

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok... might as well change this everywhere it appears.

Comment on lines 4360 to 4342
if (vn == NoVN)
if (IsVNFunc(vn))
{
return BasicBlock::MAX_LOOP_NUM;
VNFuncApp funcApp;
GetVNFunc(vn, &funcApp);
Copy link
Member

Choose a reason for hiding this comment

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

I can't add a suggestion since there's a deleted line in the diff, but GetVNFunc returns a bool so you can combine it with the check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Will update.

Copy link
Contributor

@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

@AndyAyersMS AndyAyersMS merged commit d05950b into dotnet:main Jul 19, 2021
@AndyAyersMS AndyAyersMS deleted the RefactorVnChunks branch July 19, 2021 15:39
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants