Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree)
return;
}

if (tree->OperIs(GT_AND) && op2->isContainedAndNotIntOrIImmed())
if (tree->isContainedCompareChainSegment(op2))
{
GenCondition cond;
bool chain = false;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,10 @@ struct GenTree
return isContained() && IsCnsIntOrI() && !isUsedFromSpillTemp();
}

// Node is contained, but it isn't contained due to being a containable int.
bool isContainedAndNotIntOrIImmed() const
// Node and its child in isolation form a contained compare chain.
bool isContainedCompareChainSegment(GenTree* child) const
{
return isContained() && !isContainedIntOrIImmed();
return (OperIs(GT_AND) && child->isContained() && (child->OperIs(GT_AND) || child->OperIsCmpCompare()));
}

bool isContainedFltOrDblImmed() const
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
#ifdef TARGET_ARM64
// Do not optimise further if op1 has a contained chain.
if (op1->OperIs(GT_AND) &&
(op1->gtGetOp1()->isContainedAndNotIntOrIImmed() || op1->gtGetOp2()->isContainedAndNotIntOrIImmed()))
(op1->isContainedCompareChainSegment(op1->gtGetOp1()) || op1->isContainedCompareChainSegment(op1->gtGetOp2())))
{
return cmp;
}
Expand Down
33 changes: 14 additions & 19 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,26 +2255,21 @@ bool Lowering::IsValidCompareChain(GenTree* child, GenTree* parent)
{
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));

if (child->isContainedAndNotIntOrIImmed())
if (parent->isContainedCompareChainSegment(child))
{
// Already have a chain.
assert(child->OperIs(GT_AND) || child->OperIsCmpCompare());
return true;
}
else
else if (child->OperIs(GT_AND))
{
if (child->OperIs(GT_AND))
{
// Count both sides.
return IsValidCompareChain(child->AsOp()->gtGetOp2(), child) &&
IsValidCompareChain(child->AsOp()->gtGetOp1(), child);
}
else if (child->OperIsCmpCompare() && varTypeIsIntegral(child->gtGetOp1()) &&
varTypeIsIntegral(child->gtGetOp2()))
{
// Can the child compare be contained.
return IsSafeToContainMem(parent, child);
}
// Count both sides.
return IsValidCompareChain(child->AsOp()->gtGetOp2(), child) &&
IsValidCompareChain(child->AsOp()->gtGetOp1(), child);
}
else if (child->OperIsCmpCompare() && varTypeIsIntegral(child->gtGetOp1()) && varTypeIsIntegral(child->gtGetOp2()))
{
// Can the child compare be contained.
return IsSafeToContainMem(parent, child);
}

return false;
Expand All @@ -2299,9 +2294,9 @@ bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));
*startOfChain = nullptr; // Nothing found yet.

if (child->isContainedAndNotIntOrIImmed())
if (parent->isContainedCompareChainSegment(child))
{
// Already have a chain.
// Already have a contained chain.
return true;
}
// Can the child be contained.
Expand All @@ -2310,7 +2305,7 @@ bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree
if (child->OperIs(GT_AND))
{
// If Op2 is not contained, then try to contain it.
if (!child->AsOp()->gtGetOp2()->isContainedAndNotIntOrIImmed())
if (!child->isContainedCompareChainSegment(child->AsOp()->gtGetOp2()))
{
if (!ContainCheckCompareChain(child->gtGetOp2(), child, startOfChain))
{
Expand All @@ -2320,7 +2315,7 @@ bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree
}

// If Op1 is not contained, then try to contain it.
if (!child->AsOp()->gtGetOp1()->isContainedAndNotIntOrIImmed())
if (!child->isContainedCompareChainSegment(child->AsOp()->gtGetOp1()))
{
if (!ContainCheckCompareChain(child->gtGetOp1(), child, startOfChain))
{
Expand Down