diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index 01c1e52b996139..33dfd017e8505e 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -1665,9 +1665,9 @@ weight_t BasicBlock::getBBWeight(Compiler* comp) { weight_t calledCount = getCalledCount(comp); - // Normalize the bbWeights by multiplying by BB_UNITY_WEIGHT and dividing by the calledCount. + // Normalize the bbWeight. // - weight_t fullResult = this->bbWeight * BB_UNITY_WEIGHT / calledCount; + weight_t fullResult = (this->bbWeight / calledCount) * BB_UNITY_WEIGHT; return fullResult; } diff --git a/src/coreclr/jit/ifconversion.cpp b/src/coreclr/jit/ifconversion.cpp index c7441458556bc4..f51417453225a2 100644 --- a/src/coreclr/jit/ifconversion.cpp +++ b/src/coreclr/jit/ifconversion.cpp @@ -656,10 +656,11 @@ bool OptIfConversionDsc::optIfConvert() if (!m_comp->compStressCompile(Compiler::STRESS_IF_CONVERSION_INNER_LOOPS, 25)) { - // Don't optimise the block if it is inside a loop - // When inside a loop, branches are quicker than selects. + // Don't optimise the block if it is inside a loop. Loop-carried + // dependencies can cause significant stalls if if-converted. // Detect via the block weight as that will be high when inside a loop. - if (m_startBlock->getBBWeight(m_comp) > BB_UNITY_WEIGHT) + + if (m_startBlock->getBBWeight(m_comp) > BB_UNITY_WEIGHT * 1.05) { JITDUMP("Skipping if-conversion inside loop (via weight)\n"); return false;