@@ -2240,13 +2240,6 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block)
2240
2240
//
2241
2241
bNewCond->inheritWeight (block);
2242
2242
2243
- const weight_t totalWeight = bTest->bbWeight ;
2244
-
2245
- if (haveProfileWeights)
2246
- {
2247
- bTest->decreaseBBProfileWeight (block->bbWeight );
2248
- }
2249
-
2250
2243
// Move all predecessor edges that look like loop entry edges to point to the new cloned condition
2251
2244
// block, not the existing condition block. The idea is that if we only move `block` to point to
2252
2245
// `bNewCond`, but leave other `bTest` predecessors still pointing to `bTest`, when we eventually
@@ -2281,14 +2274,6 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block)
2281
2274
case BBJ_SWITCH:
2282
2275
case BBJ_EHFINALLYRET:
2283
2276
fgReplaceJumpTarget (predBlock, bTest, bNewCond);
2284
-
2285
- // Redirect profile weight, too
2286
- if (haveProfileWeights)
2287
- {
2288
- const weight_t edgeWeight = predEdge->getLikelyWeight ();
2289
- bNewCond->increaseBBProfileWeight (edgeWeight);
2290
- bTest->decreaseBBProfileWeight (edgeWeight);
2291
- }
2292
2277
break ;
2293
2278
2294
2279
case BBJ_EHCATCHRET:
@@ -2302,13 +2287,21 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block)
2302
2287
}
2303
2288
}
2304
2289
2305
- const weight_t loopWeight = bTest->bbWeight ;
2306
- const weight_t nonLoopWeight = bNewCond->bbWeight ;
2307
- if (haveProfileWeights && !fgProfileWeightsConsistent (totalWeight, loopWeight + nonLoopWeight))
2290
+ if (haveProfileWeights)
2308
2291
{
2309
- JITDUMP (" Redirecting flow from " FMT_BB " to " FMT_BB " introduced inconsistency. Data %s inconsistent.\n " ,
2310
- bTest->bbNum , bNewCond->bbNum , fgPgoConsistent ? " is now" : " was already" );
2311
- fgPgoConsistent = false ;
2292
+ // The above change should have moved some flow out of 'bTest', and into 'bNewCond'.
2293
+ // Check that no extraneous flow was lost or gained in the process.
2294
+ //
2295
+ const weight_t totalWeight = bTest->bbWeight ;
2296
+ bTest->setBBProfileWeight (bTest->computeIncomingWeight ());
2297
+ bNewCond->setBBProfileWeight (bNewCond->computeIncomingWeight ());
2298
+
2299
+ if (!fgProfileWeightsConsistent (totalWeight, bTest->bbWeight + bNewCond->bbWeight ))
2300
+ {
2301
+ JITDUMP (" Redirecting flow from " FMT_BB " to " FMT_BB " introduced inconsistency. Data %s inconsistent.\n " ,
2302
+ bTest->bbNum , bNewCond->bbNum , fgPgoConsistent ? " is now" : " was already" );
2303
+ fgPgoConsistent = false ;
2304
+ }
2312
2305
}
2313
2306
2314
2307
#ifdef DEBUG
0 commit comments