diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index dfc29a621d4652..e25bc6d59cced7 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -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. diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index b510ce4a558dc5..76728786c826e6 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -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); diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index c4a839fbb4044d..72f7ee98ee0f5f 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -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; } diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 79c66577176945..a76205c6f03e43 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -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 @@ -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); } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/lsraarm.cpp b/src/coreclr/jit/lsraarm.cpp index 47cdbaa7539077..09d5bbf46d1a36 100644 --- a/src/coreclr/jit/lsraarm.cpp +++ b/src/coreclr/jit/lsraarm.cpp @@ -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; diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 3908f1998792a9..0d7cfed2e98716 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -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(); } @@ -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); } diff --git a/src/coreclr/jit/lsraxarch.cpp b/src/coreclr/jit/lsraxarch.cpp index c0fd6030c28804..875fb45aee55b8 100644 --- a/src/coreclr/jit/lsraxarch.cpp +++ b/src/coreclr/jit/lsraxarch.cpp @@ -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;