Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Check for non-valid compare chains (#76566)
  • Loading branch information
a74nh committed Oct 5, 2022
commit b0bf905c32f61c6e9a4eb0d43f061db300263d05
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->OperIs(GT_AND) && op2->isContainedCompareChainSegment())
{
GenCondition cond;
bool chain = false;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ struct GenTree
}

// Node is contained, but it isn't contained due to being a containable int.
bool isContainedAndNotIntOrIImmed() const
bool isContainedCompareChainSegment() const
{
return isContained() && !isContainedIntOrIImmed();
}
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->gtGetOp1()->isContainedCompareChainSegment() || op1->gtGetOp2()->isContainedCompareChainSegment()))
{
return cmp;
}
Expand Down
21 changes: 10 additions & 11 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,15 +2255,14 @@ bool Lowering::IsValidCompareChain(GenTree* child, GenTree* parent)
{
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));

if (child->isContainedAndNotIntOrIImmed())
if (child->OperIs(GT_AND) || child->OperIsCmpCompare())
{
// Already have a chain.
assert(child->OperIs(GT_AND) || child->OperIsCmpCompare());
return true;
}
else
{
if (child->OperIs(GT_AND))
if (child->isContainedCompareChainSegment())
{
// Already have a chain.
return true;
}
else if (child->OperIs(GT_AND))
{
// Count both sides.
return IsValidCompareChain(child->AsOp()->gtGetOp2(), child) &&
Expand Down Expand Up @@ -2299,7 +2298,7 @@ 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 (child->isContainedCompareChainSegment())
{
// Already have a chain.
return true;
Expand All @@ -2310,7 +2309,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->AsOp()->gtGetOp2()->isContainedCompareChainSegment())
{
if (!ContainCheckCompareChain(child->gtGetOp2(), child, startOfChain))
{
Expand All @@ -2320,7 +2319,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->AsOp()->gtGetOp1()->isContainedCompareChainSegment())
{
if (!ContainCheckCompareChain(child->gtGetOp1(), child, startOfChain))
{
Expand Down