From 1ee41c63d52583c9e7c233073465ec1e47cc78e8 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Wed, 22 May 2024 12:49:16 -0700 Subject: [PATCH] couple tweaks to optRemoveRedundantZeroInits (#102531) * couple tweaks to optRemoveRedundantZeroInits * Apply suggestions from code review Co-authored-by: Aman Khalid --------- Co-authored-by: Aman Khalid --- src/coreclr/jit/optimizer.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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