diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 8e7e09efaba73..5c7b97b306bf4 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -5918,7 +5918,12 @@ void Compiler::optRemoveRedundantZeroInits() { if (((tree->gtFlags & GTF_CALL) != 0)) { - hasGCSafePoint = true; + // if this is not a No-GC helper + if (!tree->IsCall() || !emitter::emitNoGChelper(tree->AsCall()->GetHelperNum())) + { + // assume that we have a safe point. + hasGCSafePoint = true; + } } hasImplicitControlFlow |= hasEHSuccs && ((tree->gtFlags & GTF_EXCEPT) != 0); @@ -6071,9 +6076,10 @@ void Compiler::optRemoveRedundantZeroInits() (!hasImplicitControlFlow || (lclDsc->lvTracked && !lclDsc->lvLiveInOutOfHndlr))) { // If compMethodRequiresPInvokeFrame() returns true, lower may later - // insert a call to CORINFO_HELP_INIT_PINVOKE_FRAME which is a gc-safe point. - if (!lclDsc->HasGCPtr() || - (!GetInterruptible() && !hasGCSafePoint && !compMethodRequiresPInvokeFrame())) + // insert a call to CORINFO_HELP_INIT_PINVOKE_FRAME but that is not a gc-safe point. + assert(emitter::emitNoGChelper(CORINFO_HELP_INIT_PINVOKE_FRAME)); + + if (!lclDsc->HasGCPtr() || (!GetInterruptible() && !hasGCSafePoint)) { // The local hasn't been used and won't be reported to the gc between // the prolog and this explicit initialization. Therefore, it doesn't