diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index a1d649322252be..65ca9b1a2f7fd4 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -2816,6 +2816,8 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp) op2->gtType = castToType; #endif // If we have any contained memory ops on castOp, they must now not be contained. + castOp->ClearContained(); + if (castOp->OperIs(GT_OR, GT_XOR, GT_AND)) { GenTree* op1 = castOp->gtGetOp1(); @@ -2823,16 +2825,13 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp) { op1->ClearContained(); } + GenTree* op2 = castOp->gtGetOp2(); if ((op2 != nullptr) && !op2->IsCnsIntOrI()) { op2->ClearContained(); } } - else - { - castOp->ClearContained(); - } cmp->AsOp()->gtOp1 = castOp; diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index 12023a99d77c1b..36392913cbb2cb 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -288,9 +288,6 @@ bool Lowering::IsContainableBinaryOp(GenTree* parentNode, GenTree* childNode) co // Find "a op cast(b)" GenTree* castOp = childNode->AsCast()->CastOp(); - // We want to prefer the combined op here over containment of the cast op - castOp->ClearContained(); - bool isSupportedCast = false; if (varTypeIsSmall(childNode->CastToType())) @@ -2015,13 +2012,25 @@ void Lowering::ContainCheckBinary(GenTreeOp* node) { if (IsContainableBinaryOp(node, op2)) { + if (op2->OperIs(GT_CAST)) + { + // We want to prefer the combined op here over containment of the cast op + op2->AsCast()->CastOp()->ClearContained(); + } MakeSrcContained(node, op2); + return; } if (node->OperIsCommutative() && IsContainableBinaryOp(node, op1)) { + if (op1->OperIs(GT_CAST)) + { + // We want to prefer the combined op here over containment of the cast op + op1->AsCast()->CastOp()->ClearContained(); + } MakeSrcContained(node, op1); + std::swap(node->gtOp1, node->gtOp2); return; }