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

Optimize nullcheck for Interlocked.* operations #87297

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/coreclr/jit/earlyprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ GenTree* Compiler::optEarlyPropRewriteTree(GenTree* tree, LocalNumberToNullCheck
optPropKind propKind = optPropKind::OPK_INVALID;
bool folded = false;

if (tree->OperIsIndirOrArrMetaData())
if (tree->OperIsIndirOrArrMetaData() || tree->OperIsAtomicOp())
{
// optFoldNullCheck takes care of updating statement info if a null check is removed.
folded = optFoldNullCheck(tree, nullCheckMap);
Expand Down Expand Up @@ -503,15 +503,32 @@ bool Compiler::optFoldNullCheck(GenTree* tree, LocalNumberToNullCheckTreeMap* nu
// or
// indir(add(x, const2))
//
// (indir is any node for which OperIsIndirOrArrMetaData() is true.)
// (indir is any node for which OperIsIndirOrArrMetaData() or OperIsAtomicOp() is true.)
//
// 2. const1 + const2 if sufficiently small.

GenTree* Compiler::optFindNullCheckToFold(GenTree* tree, LocalNumberToNullCheckTreeMap* nullCheckMap)
{
assert(tree->OperIsIndirOrArrMetaData());
assert(tree->OperIsIndirOrArrMetaData() || tree->OperIsAtomicOp());

GenTree* addr = tree->GetIndirOrArrMetaDataAddr();
GenTree* addr;
if (tree->OperIsAtomicOp())
{
// For atomic operations, the address is always the first operand.
if (tree->OperIs(GT_CMPXCHG))
{
// Special case: GT_CMPXCHG is not a GenTreeOp
addr = tree->AsCmpXchg()->gtOpLocation->gtEffectiveVal();
}
else
{
addr = tree->gtGetOp1()->gtEffectiveVal(true);
}
}
else
{
addr = tree->GetIndirOrArrMetaDataAddr();
}

ssize_t offsetValue = 0;

Expand Down