From 6e147d387d27728dbe1e053cc13a841687c84152 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Sun, 2 Oct 2022 14:28:08 -0700 Subject: [PATCH] Fixing where `ClearContained` is called for certain Arm64 cast ops --- src/coreclr/jit/lower.cpp | 7 +++---- src/coreclr/jit/lowerarmarch.cpp | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) 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 1eae6c6dbc0987..a6e2947f1681c2 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())) @@ -2010,13 +2007,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; }