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

Fix GT_XCHG for byte on x86 #97593

Merged
merged 5 commits into from
Jan 29, 2024
Merged
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
24 changes: 18 additions & 6 deletions src/coreclr/jit/lsraxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,17 @@ int LinearScan::BuildNode(GenTree* tree)
srcCount = 3;
assert(dstCount == 1);

GenTree* addr = tree->AsCmpXchg()->Addr();
GenTree* data = tree->AsCmpXchg()->Data();
GenTree* comparand = tree->AsCmpXchg()->Comparand();

// Comparand is preferenced to RAX.
// The remaining two operands can be in any reg other than RAX.
BuildUse(tree->AsCmpXchg()->Addr(), availableIntRegs & ~RBM_RAX);
BuildUse(tree->AsCmpXchg()->Data(), availableIntRegs & ~RBM_RAX);
BuildUse(tree->AsCmpXchg()->Comparand(), RBM_RAX);

const unsigned nonRaxCandidates = availableIntRegs & ~RBM_RAX;
BuildUse(addr, nonRaxCandidates);
BuildUse(data, varTypeIsByte(tree) ? (nonRaxCandidates & RBM_BYTE_REGS) : nonRaxCandidates);
BuildUse(comparand, RBM_RAX);
BuildDef(tree, RBM_RAX);
}
break;
Expand All @@ -438,10 +444,16 @@ int LinearScan::BuildNode(GenTree* tree)
case GT_XAND:
if (!tree->IsUnusedValue())
{
GenTree* addr = tree->gtGetOp1();
GenTree* data = tree->gtGetOp2();

// These don't support byte operands.
assert(!varTypeIsByte(data));

// if tree's value is used, we'll emit a cmpxchg-loop idiom (requires RAX)
buildInternalIntRegisterDefForNode(tree, availableIntRegs & ~RBM_RAX);
BuildUse(tree->gtGetOp1(), availableIntRegs & ~RBM_RAX);
BuildUse(tree->gtGetOp2(), availableIntRegs & ~RBM_RAX);
BuildUse(addr, availableIntRegs & ~RBM_RAX);
BuildUse(data, availableIntRegs & ~RBM_RAX);
BuildDef(tree, RBM_RAX);
buildInternalRegisterUses();
srcCount = 2;
Expand All @@ -463,7 +475,7 @@ int LinearScan::BuildNode(GenTree* tree)
setDelayFree(addrUse);
tgtPrefUse = addrUse;
assert(!data->isContained());
BuildUse(data);
BuildUse(data, varTypeIsByte(tree) ? RBM_BYTE_REGS : RBM_NONE);
srcCount = 2;
assert(dstCount == 1);
BuildDef(tree);
Expand Down
Loading