diff --git a/src/coreclr/jit/lclmorph.cpp b/src/coreclr/jit/lclmorph.cpp index b4e48deeac9b9c..cd464797e79890 100644 --- a/src/coreclr/jit/lclmorph.cpp +++ b/src/coreclr/jit/lclmorph.cpp @@ -1241,10 +1241,13 @@ class LocalAddressVisitor final : public GenTreeVisitor break; case GT_CAST: + { assert(TopValue(1).Node() == node); assert(TopValue(0).Node() == node->AsCast()->CastOp()); - if (!node->TypeIs(TYP_I_IMPL, TYP_BYREF) || node->gtOverflow() || !TopValue(0).IsAddress() || + var_types castToType = node->CastToType(); + bool isPtrCast = (castToType == TYP_I_IMPL) || (castToType == TYP_U_IMPL) || (castToType == TYP_BYREF); + if (!isPtrCast || node->gtOverflow() || !TopValue(0).IsAddress() || !TopValue(1).AddOffset(TopValue(0), 0)) { EscapeValue(TopValue(0), node); @@ -1252,7 +1255,7 @@ class LocalAddressVisitor final : public GenTreeVisitor PopValue(); break; - + } case GT_CALL: while (TopValue(0).Node() != node) {