Skip to content
Closed
1 change: 1 addition & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
#ifdef TARGET_ARM64
case GT_TEST_EQ:
case GT_TEST_NE:
assert(!treeNode->isContained());
// On ARM64 genCodeForCompare does not consume its own operands because
// genCodeForBinary also has this behavior and it can end up calling
// genCodeForCompare when generating compare chains for GT_AND.
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,9 @@ void CodeGen::genCodeForJumpTrue(GenTreeOp* jtrue)
{
assert(compiler->compCurBB->bbJumpKind == BBJ_COND);
assert(jtrue->OperIs(GT_JTRUE));
assert(jtrue->gtGetOp1()->isContained());
assert(jtrue->gtGetOp1()->OperIsCompare());
assert(jtrue->gtGetOp1()->GetRegNum() == REG_NA);

GenTreeOp* relop = jtrue->gtGetOp1()->AsOp();
GenCondition condition = GenCondition::FromRelop(relop);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)

// contained nodes are part of their parents for codegen purposes
// ex : immediates, most LEAs
if (treeNode->isContained())
if (treeNode->isContained() && !treeNode->OperIsCompare())
{
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3345,6 +3345,8 @@ GenTreeCC* Lowering::LowerNodeCC(GenTree* node, GenCondition condition)
{
if (next->OperIs(GT_JTRUE))
{
assert(!relop->isContained());

// If the instruction immediately following 'relop', i.e. 'next' is a conditional branch,
// it should always have 'relop' as its 'op1'. If it doesn't, then we have improperly
// constructed IL (the setting of a condition code should always immediately precede its
Expand Down Expand Up @@ -7166,8 +7168,12 @@ void Lowering::ContainCheckJTrue(GenTreeOp* node)
{
// The compare does not need to be generated into a register.
GenTree* cmp = node->gtGetOp1();
cmp->gtType = TYP_VOID;
cmp->gtFlags |= GTF_SET_FLAGS;

assert(cmp->OperIsCompare());

cmp->gtFlags &= ~GTF_SET_FLAGS;

MakeSrcContained(node, cmp);
}

//------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions src/coreclr/jit/lsraarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,14 @@ int LinearScan::BuildNode(GenTree* tree)
break;

case GT_JTRUE:
srcCount = 0;
{
assert(dstCount == 0);
break;
GenTree* cmp = tree->gtGetOp1();
assert(cmp->isContained());
assert(cmp->OperIsCompare());
srcCount = BuildCmp(cmp);
}
break;

case GT_JMP:
srcCount = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4085,7 +4085,7 @@ int LinearScan::BuildCmp(GenTree* tree)
#ifdef TARGET_X86
// If the compare is used by a jump, we just need to set the condition codes. If not, then we need
// to store the result into the low byte of a register, which requires the dst be a byteable register.
if (tree->TypeGet() != TYP_VOID)
if (tree->TypeGet() != TYP_VOID && !tree->isContained())
{
dstCandidates = allByteRegs();
}
Expand Down Expand Up @@ -4135,7 +4135,7 @@ int LinearScan::BuildCmp(GenTree* tree)

int srcCount = BuildOperandUses(op1, op1Candidates);
srcCount += BuildOperandUses(op2, op2Candidates);
if (tree->TypeGet() != TYP_VOID)
if (tree->TypeGet() != TYP_VOID && !tree->isContained())
{
BuildDef(tree, dstCandidates);
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/lsraxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_JTRUE:
{
srcCount = 0;
assert(dstCount == 0);
GenTree* cmp = tree->gtGetOp1();
assert(!cmp->IsValue());
assert(cmp->isContained());
assert(cmp->OperIsCompare());
srcCount = BuildCmp(cmp);
}
break;

Expand Down