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
Move lowering functions to lowerarmarch
  • Loading branch information
a74nh committed Aug 4, 2022
commit ce5882d9020c4853155341cf47bcb802bc3200c4
179 changes: 4 additions & 175 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ GenTree* Lowering::LowerNode(GenTree* node)
return LowerJTrue(node->AsOp());

case GT_SELECT:
#ifdef TARGET_ARM64
ContainCheckSelect(node->AsConditional());
#endif
break;

case GT_JMP:
Expand Down Expand Up @@ -6829,7 +6831,9 @@ void Lowering::ContainCheckNode(GenTree* node)
break;

case GT_SELECT:
#ifdef TARGET_ARM64
ContainCheckSelect(node->AsConditional());
#endif
break;

case GT_ADD:
Expand Down Expand Up @@ -7022,181 +7026,6 @@ void Lowering::ContainCheckJTrue(GenTreeOp* node)
cmp->gtFlags |= GTF_SET_FLAGS;
}

//------------------------------------------------------------------------
// IsValidCompareChain : Determine if the node contains a valid compare chain.
//
// Arguments:
// child - pointer to the node being checked.
// parent - parent node of the child.
//
// Return value:
// True if a valid chain is found.
//
bool Lowering::IsValidCompareChain(GenTree* child, GenTree* parent)
{
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));

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

return false;
}

//------------------------------------------------------------------------
// ContainCheckCompareChain : Determine if a chain of ANDs and CMPs can be contained.
//
// Arguments:
// child - pointer to the node being checked.
// parent - parent node of the child.
// startOfChain - If found, returns the earliest valid op in the chain.
//
bool Lowering::ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree** startOfChain)
{
assert(parent->OperIs(GT_AND) || parent->OperIs(GT_SELECT));

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, startOfChain))
{
// Op2 must be contained in order to contain Op1 or the AND.
return false;
}
}

// If Op1 is not contained, then try to contain it.
if (!child->AsOp()->gtGetOp1()->isContainedAndNotIntOrIImmed())
{
if (!ContainCheckCompareChain(child->gtGetOp1(), child, startOfChain))
{
return false;
}
}

// Contain the AND.
child->SetContained();
return true;
}
#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());
*startOfChain = child;
return true;
}
#endif
}

return false;
}

//------------------------------------------------------------------------
// ContainCheckAndCompareChain : Determine if an AND is a containable chain
//
// Arguments:
// node - pointer to the node
//
void Lowering::ContainCheckAndChain(GenTree* tree)
{
assert(tree->OperIs(GT_AND));

if (!comp->opts.OptimizationEnabled())
{
return;
}

// First check there is a valid chain.
if (IsValidCompareChain(tree->AsOp()->gtGetOp2(), tree) &&
IsValidCompareChain(tree->AsOp()->gtGetOp1(), tree))
{
GenTree* startOfChain = nullptr;

// To ensure ordering at code generation, Op1 and the parent can
// only be contained if Op2 is contained.
if (ContainCheckCompareChain(tree->AsOp()->gtGetOp2(), tree, &startOfChain))
{
if (ContainCheckCompareChain(tree->AsOp()->gtGetOp1(), tree, &startOfChain))
{
// If op1 is the start of a chain, then it'll be generated as a standard compare.
if (startOfChain != nullptr)
{
// The earliest node in the chain will be generated as a standard compare.
assert(startOfChain->OperIsCompare());
startOfChain->AsOp()->gtGetOp1()->ClearContained();
startOfChain->AsOp()->gtGetOp2()->ClearContained();
ContainCheckCompare(startOfChain->AsOp());
}
}
}

JITDUMP("Lowered And chain:\n");
DISPTREE(tree);
}
}

//------------------------------------------------------------------------
// ContainCheckSelect : determine whether the source of a select should be contained.
//
// Arguments:
// node - pointer to the node
//
void Lowering::ContainCheckSelect(GenTreeConditional* node)
{
if (!comp->opts.OptimizationEnabled())
{
return;
}

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

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

//------------------------------------------------------------------------
// ContainCheckBitCast: determine whether the source of a BITCAST should be contained.
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ class Lowering final : public Phase
void ContainCheckRet(GenTreeUnOp* ret);
void ContainCheckJTrue(GenTreeOp* node);
#ifdef TARGET_ARM64
void ContainCheckConditionalCompare(GenTreeOp* cmp);
#endif
bool IsValidCompareChain(GenTree* child, GenTree* parent);
bool ContainCheckCompareChain(GenTree* child, GenTree* parent, GenTree** earliestValid);
void ContainCheckAndChain(GenTree* tree);
void ContainCheckConditionalCompare(GenTreeOp* cmp);
void ContainCheckSelect(GenTreeConditional* node);
#endif
void ContainCheckBitCast(GenTree* node);
void ContainCheckCallOperands(GenTreeCall* call);
void ContainCheckIndir(GenTreeIndir* indirNode);
Expand Down
Loading