diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index c1f01983993f2..05ec46c51d199 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2046,9 +2046,7 @@ void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* s // call - The call // // Remarks: -// This makes use of the fact that TYP_I_IMPL <-> TYP_BYREF casts are -// implicit in JIT IR, allowing us to change the types directly without -// inserting a cast node. +// Make the "casting away" of GC explicit here instead of retyping. // void Compiler::impRetypeUnmanagedCallArgs(GenTreeCall* call) { @@ -2059,7 +2057,7 @@ void Compiler::impRetypeUnmanagedCallArgs(GenTreeCall* call) // We should not be passing gc typed args to an unmanaged call. if (varTypeIsGC(argNode->TypeGet())) { - // Tolerate byrefs by retyping to native int. + // Tolerate byrefs by casting to native int. // // This is needed or we'll generate inconsistent GC info // for this arg at the call site (gc info says byref, @@ -2067,7 +2065,8 @@ void Compiler::impRetypeUnmanagedCallArgs(GenTreeCall* call) // if (argNode->TypeGet() == TYP_BYREF) { - argNode->ChangeType(TYP_I_IMPL); + GenTree* cast = gtNewCastNode(TYP_I_IMPL, argNode, false, TYP_I_IMPL); + arg.SetEarlyNode(cast); } else {