JIT: fix phase status for some minimal instrumentation cases (#85411)
authorAndy Ayers <andya@microsoft.com>
Wed, 26 Apr 2023 23:48:46 +0000 (16:48 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 23:48:46 +0000 (16:48 -0700)
The instrumentation phase may modify the flow graph in anticipation of doing
some instrumentation, but then (because of minimal profiling) decide not to
instrument.

Make sure the phase status properly reflects that the phase made changes in
this case, and a few other cases where we exit early without actually doing
any instrumentation.

Fixes #85061.

src/coreclr/jit/fgprofile.cpp

index 3f6e02b..a856a72 100644 (file)
@@ -2455,6 +2455,12 @@ PhaseStatus Compiler::fgInstrumentMethod()
         }
     }
 
+    // Even though we haven't yet instrumented, we may have made changes in anticipation...
+    //
+    const bool madeAnticipatoryChanges = fgCountInstrumentor->ModifiedFlow() || fgHistogramInstrumentor->ModifiedFlow();
+    const PhaseStatus earlyExitPhaseStatus =
+        madeAnticipatoryChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
+
     // Optionally, when jitting, if there were no class probes and only one count probe,
     // suppress instrumentation.
     //
@@ -2478,13 +2484,14 @@ PhaseStatus Compiler::fgInstrumentMethod()
     {
         JITDUMP(
             "Not instrumenting method: minimal probing enabled, and method has only one counter and no class probes\n");
-        return PhaseStatus::MODIFIED_NOTHING;
+
+        return earlyExitPhaseStatus;
     }
 
     if (schema.size() == 0)
     {
         JITDUMP("Not instrumenting method: no schemas were created\n");
-        return PhaseStatus::MODIFIED_NOTHING;
+        return earlyExitPhaseStatus;
     }
 
     JITDUMP("Instrumenting method: %d count probes and %d class probes\n", fgCountInstrumentor->SchemaCount(),
@@ -2515,13 +2522,9 @@ PhaseStatus Compiler::fgInstrumentMethod()
         if (res != E_NOTIMPL)
         {
             noway_assert(!"Error: unexpected hresult from allocPgoInstrumentationBySchema");
-            return PhaseStatus::MODIFIED_NOTHING;
         }
 
-        // We may have modified control flow preparing for instrumentation.
-        //
-        const bool modifiedFlow = fgCountInstrumentor->ModifiedFlow() || fgHistogramInstrumentor->ModifiedFlow();
-        return modifiedFlow ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
+        return earlyExitPhaseStatus;
     }
 
     JITDUMP("Instrumentation data base address is %p\n", dspPtr(profileMemory));