diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 3613e9a6274b08..ab8f0dcbd16595 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -5227,6 +5227,13 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl DoPhase(this, PHASE_OPTIMIZE_LAYOUT, &Compiler::fgSearchImprovedLayout); } + // 3-opt will mess with post-order numbers regardless of whether it modifies anything, + // so we always need to invalidate the flowgraph annotations after. + // If we didn't run 3-opt, we might still have a profile-aware DFS tree computed during LSRA available. + // This tree's presence can trigger asserts if pre/postorder numbers are recomputed, + // so invalidate the tree in both cases. + fgInvalidateDfsTree(); + // Now that the flowgraph is finalized, run post-layout optimizations. // DoPhase(this, PHASE_OPTIMIZE_POST_LAYOUT, &Compiler::optOptimizePostLayout); diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index e2328da9ab42b2..9ce4d65bc440e6 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -5295,9 +5295,6 @@ PhaseStatus Compiler::fgSearchImprovedLayout() JITDUMP("No hot blocks found. Skipping reordering.\n"); } - // 3-opt will mess with post-order numbers regardless of whether it modifies anything, - // so we always need to invalidate the flowgraph annotations after. - fgInvalidateDfsTree(); return modified ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING; }