Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e8f9ae6
Add lowering support for conditional nodes
a74nh Mar 22, 2022
e9c0474
Contain conditionals
a74nh Jul 8, 2022
97386b3
Fix formatting
a74nh Jul 11, 2022
1bcd61a
Use AND and CMP nodes
a74nh Jul 12, 2022
7884eca
Fix formatting
a74nh Jul 18, 2022
6d36f9d
Remove LowerNodeCC changes
a74nh Jul 18, 2022
1138fae
Remove asserts & fix variable names
a74nh Jul 19, 2022
d98f9d0
Better contain checks for conditional compares
a74nh Jul 19, 2022
8ef9994
Simpler contained conditions codegen
a74nh Jul 20, 2022
6202894
Remove Conditional Compare nodes
a74nh Jul 18, 2022
c0aba37
Minor cleanups
a74nh Jul 20, 2022
9995881
Generate AND compare chains
a74nh Jul 26, 2022
165060b
Fix unsigned compares && reduce chain check recursion
a74nh Aug 3, 2022
6117333
Add compare chain tests
a74nh Aug 3, 2022
574742f
Review fixes
a74nh Aug 3, 2022
eae824a
Use GenCondition
a74nh Aug 4, 2022
8b282f9
Change CompareChainSize to IsValidCompareChain
a74nh Aug 4, 2022
ce5882d
Move lowering functions to lowerarmarch
a74nh Aug 4, 2022
c548f9f
Formatting fixes
a74nh Aug 4, 2022
df67d67
Fix SELECT issues
a74nh Aug 5, 2022
d1854f8
Fix test output messages.
a74nh Aug 5, 2022
8310017
Better explanations for AND chains
a74nh Aug 5, 2022
e2c8f5d
Compare chains should not contain tst compares
a74nh Aug 8, 2022
25696f1
Don't allow tst compares in codegeneration of compare chains
a74nh Aug 9, 2022
a3d5d0c
Add tests for chains with tst compares
a74nh Aug 9, 2022
cac2740
Don't allow tst compares in lsrabuild of compare chains
a74nh Aug 9, 2022
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
Prev Previous commit
Next Next commit
Fix unsigned compares && reduce chain check recursion
  • Loading branch information
a74nh committed Aug 3, 2022
commit 165060b97fa2dc2d374995031a72fe002bccce31
43 changes: 38 additions & 5 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree)

// Move the result from flags into a register.
genTreeOps opCond = GT_EQ;
bool isUnsigned = false;
switch (cond)
{
case INS_COND_EQ:
Expand All @@ -2599,10 +2600,26 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree)
case INS_COND_LE:
opCond = GT_LE;
break;
case INS_COND_HS:
isUnsigned = true;
opCond = GT_GE;
break;
case INS_COND_HI:
isUnsigned = true;
opCond = GT_GT;
break;
case INS_COND_LO:
isUnsigned = true;
opCond = GT_LT;
break;
case INS_COND_LS:
isUnsigned = true;
opCond = GT_LE;
break;
default:
assert(!"Unexpected cond");
}
inst_SETCC(GenCondition::FromIntegralRelop(opCond, false), tree->TypeGet(), targetReg);
inst_SETCC(GenCondition::FromIntegralRelop(opCond, isUnsigned), tree->TypeGet(), targetReg);
genProduceReg(tree);
return;
}
Expand Down Expand Up @@ -10603,13 +10620,13 @@ insCond CodeGen::InsCondForCompareOp(GenTree* tree)
case GT_TEST_NE:
return INS_COND_NE;
case GT_GE:
return INS_COND_GE;
return tree->IsUnsigned() ? INS_COND_HS : INS_COND_GE;
case GT_GT:
return INS_COND_GT;
return tree->IsUnsigned() ? INS_COND_HI : INS_COND_GT;
case GT_LT:
return INS_COND_LT;
return tree->IsUnsigned() ? INS_COND_LO : INS_COND_LT;
case GT_LE:
return INS_COND_LE;
return tree->IsUnsigned() ? INS_COND_LS : INS_COND_LE;
default:
assert(false && "Invalid condition");
return INS_COND_EQ;
Expand Down Expand Up @@ -10638,6 +10655,14 @@ insCond CodeGen::InvertInsCond(insCond cond)
return INS_COND_GE;
case INS_COND_LE:
return INS_COND_GT;
case INS_COND_HS:
return INS_COND_LO;
case INS_COND_HI:
return INS_COND_LS;
case INS_COND_LO:
return INS_COND_HS;
case INS_COND_LS:
return INS_COND_HI;
default:
assert(false && "Invalid condition");
return INS_COND_EQ;
Expand Down Expand Up @@ -10673,6 +10698,14 @@ insCflags CodeGen::InsCflagsForCcmp(insCond cond)
return INS_FLAGS_NC;
case INS_COND_LE:
return INS_FLAGS_NZC;
case INS_COND_HS:
return INS_FLAGS_C;
case INS_COND_HI:
return INS_FLAGS_C;
case INS_COND_LO:
return INS_FLAGS_NONE;
case INS_COND_LS:
return INS_FLAGS_Z;
default:
assert(false && "Invalid condition");
return INS_FLAGS_NONE;
Expand Down
35 changes: 20 additions & 15 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7080,21 +7080,27 @@ int Lowering::CompareChainSize(GenTree* child, GenTree* parent, bool* inChain)
// Arguments:
// child - pointer to the node being checked.
// parent - parent node of the child.
// earliestValid - If found, returns the earliest valid op in the chain.
// startOfChain - If found, returns the earliest valid op in the chain.
//
bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree** earliestValid)
bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree** startOfChain)
{
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));

// Can the child compare be contained.
if (IsSafeToContainMem(parent, child))
if (child->isContainedAndNotIntOrIImmed())
{
// Already have a chain.
*startOfChain = nullptr;
return true;
}
// Can the child be contained.
else if (IsSafeToContainMem(parent, child))
{
if (child->OperIs(GT_AND))
{
// If Op2 is not contained, then try to contain it.
if (!child->AsOp()->gtGetOp2()->isContainedAndNotIntOrIImmed())
{
if (!ContainCheckCompareChain(child->gtGetOp2(), child, earliestValid))
if (!ContainCheckCompareChain(child->gtGetOp2(), child, startOfChain))
{
// Op2 must be contained in order to contain Op1 or the AND.
return false;
Expand All @@ -7104,7 +7110,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 (!ContainCheckCompareChain(child->gtGetOp1(), child, earliestValid))
if (!ContainCheckCompareChain(child->gtGetOp1(), child, startOfChain))
{
return false;
}
Expand All @@ -7117,14 +7123,13 @@ bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree
#ifdef TARGET_ARM64
else if (child->OperIsCompare())
{

child->AsOp()->SetContained();

// Ensure the children of the compare are contained correctly.
child->AsOp()->gtGetOp1()->ClearContained();
child->AsOp()->gtGetOp2()->ClearContained();
ContainCheckConditionalCompare(child->AsOp());
*earliestValid = child;
*startOfChain = child;
return true;
}
#endif
Expand Down Expand Up @@ -7203,16 +7208,16 @@ void Lowering::ContainCheckSelect(GenTreeConditional* node)
}

// Check if the compare does not need to be generated into a register.
GenTree* earliestValid = nullptr;
ContainCheckCompareChain(node->gtCond, node, &earliestValid);
GenTree* startOfChain = nullptr;
ContainCheckCompareChain(node->gtCond, node, &startOfChain);

if (earliestValid != nullptr)
if (startOfChain != nullptr)
{
// The earliest node in the chain will be generated as a standard compare.
assert(earliestValid->OperIsCompare());
earliestValid->AsOp()->gtGetOp1()->ClearContained();
earliestValid->AsOp()->gtGetOp2()->ClearContained();
ContainCheckCompare(earliestValid->AsOp());
assert(startOfChain->OperIsCompare());
startOfChain->AsOp()->gtGetOp1()->ClearContained();
startOfChain->AsOp()->gtGetOp2()->ClearContained();
ContainCheckCompare(startOfChain->AsOp());
}
}

Expand Down