From 519718b1069280761ae6596eb09008ce536f6c07 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Thu, 23 Jan 2025 17:17:34 -0500 Subject: [PATCH] Don't run optSetBlockWeights when we have PGO data --- src/coreclr/jit/optimizer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index c0049564371ebf..f427e3fc068d07 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -40,9 +40,20 @@ DataFlow::DataFlow(Compiler* pCompiler) PhaseStatus Compiler::optSetBlockWeights() { noway_assert(opts.OptimizationEnabled()); + assert(m_dfsTree != nullptr); + const bool usingProfileWeights = fgIsUsingProfileWeights(); + + // Rely on profile synthesis to propagate weights when we have PGO data. + // TODO: Replace optSetBlockWeights with profile synthesis entirely. + if (usingProfileWeights) + { + // Leave breadcrumb for loop alignment + fgHasLoops = m_dfsTree->HasCycle(); + return PhaseStatus::MODIFIED_NOTHING; + } + bool madeChanges = false; - assert(m_dfsTree != nullptr); if (m_domTree == nullptr) { m_domTree = FlowGraphDominatorTree::Build(m_dfsTree); @@ -59,8 +70,7 @@ PhaseStatus Compiler::optSetBlockWeights() optFindAndScaleGeneralLoopBlocks(); } - bool firstBBDominatesAllReturns = true; - const bool usingProfileWeights = fgIsUsingProfileWeights(); + bool firstBBDominatesAllReturns = true; fgComputeReturnBlocks();