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: Fold null checks for const strings #49930

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8138,12 +8138,22 @@ void Compiler::fgValueNumberTree(GenTree* tree)
if (tree->gtFlags & GTF_IND_INVARIANT)
{
assert(!isVolatile); // We don't expect both volatile and invariant
tree->gtVNPair =
ValueNumPair(vnStore->VNForMapSelect(VNK_Liberal, TYP_REF, ValueNumStore::VNForROH(),
addrNvnp.GetLiberal()),
vnStore->VNForMapSelect(VNK_Conservative, TYP_REF, ValueNumStore::VNForROH(),
addrNvnp.GetConservative()));
tree->gtVNPair = vnStore->VNPWithExc(tree->gtVNPair, addrXvnp);

// Is it a string literal? (it's always non-null)
if (addr->IsCnsIntOrI() && addr->IsIconHandle(GTF_ICON_STR_HDL))
{
tree->gtVNPair = vnStore->VNPairForFunc(tree->TypeGet(), VNF_StrCns, addrNvnp);
assert(addrXvnp.BothEqual() && (addrXvnp.GetLiberal() == ValueNumStore::VNForEmptyExcSet()));
}
else
{
tree->gtVNPair =
ValueNumPair(vnStore->VNForMapSelect(VNK_Liberal, TYP_REF, ValueNumStore::VNForROH(),
addrNvnp.GetLiberal()),
vnStore->VNForMapSelect(VNK_Conservative, TYP_REF, ValueNumStore::VNForROH(),
addrNvnp.GetConservative()));
tree->gtVNPair = vnStore->VNPWithExc(tree->gtVNPair, addrXvnp);
}
}
else if (isVolatile)
{
Expand Down Expand Up @@ -9598,7 +9608,7 @@ VNFunc Compiler::fgValueNumberJitHelperMethodVNFunc(CorInfoHelpFunc helpFunc)
break;

case CORINFO_HELP_STRCNS:
vnf = VNF_StrCns;
vnf = VNF_LazyStrCns;
break;

case CORINFO_HELP_CHKCASTCLASS:
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/valuenumfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ ValueNumFuncDef(JitReadyToRunNewArr, 3, false, true, false)
ValueNumFuncDef(Box, 3, false, false, false)
ValueNumFuncDef(BoxNullable, 3, false, false, false)

ValueNumFuncDef(StrCns, 2, false, true, false)
ValueNumFuncDef(LazyStrCns, 2, false, true, false) // lazy-initialized string literal (helper)
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
ValueNumFuncDef(StrCns, 1, false, true, false) // indirect for a string literal
ValueNumFuncDef(Unbox, 2, false, true, false)

ValueNumFuncDef(LT_UN, 2, false, false, false) // unsigned or unordered comparisons
Expand Down