@@ -1260,11 +1260,28 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
12601260 JITDUMP (" Zero weight switch block " FMT_BB " , distributing likelihoods equally per case\n " ,
12611261 afterDefaultCondBlock->bbNum );
12621262 // jumpCnt-1 here because we peeled the default after copying this value.
1263- weight_t const newLikelihood = 1.0 / (jumpCnt - 1 );
1263+ weight_t const newLikelihood = 1.0 / (jumpCnt - 1 );
1264+ bool profileInconsistent = false ;
12641265 for (unsigned i = 0 ; i < successors.numDistinctSuccs ; i++)
12651266 {
1266- FlowEdge* const edge = successors.nonDuplicates [i];
1267+ FlowEdge* const edge = successors.nonDuplicates [i];
1268+ weight_t const oldEdgeWeight = edge->getLikelyWeight ();
12671269 edge->setLikelihood (newLikelihood * edge->getDupCount ());
1270+ weight_t const newEdgeWeight = edge->getLikelyWeight ();
1271+
1272+ if (afterDefaultCondBlock->hasProfileWeight ())
1273+ {
1274+ BasicBlock* const targetBlock = edge->getDestinationBlock ();
1275+ targetBlock->increaseBBProfileWeight (newEdgeWeight - oldEdgeWeight);
1276+ profileInconsistent |= (targetBlock->NumSucc () > 0 );
1277+ }
1278+ }
1279+
1280+ if (profileInconsistent)
1281+ {
1282+ JITDUMP (" Switch lowering: Flow out of " FMT_BB " needs to be propagated. Data %s inconsistent.\n " ,
1283+ afterDefaultCondBlock->bbNum , comp->fgPgoConsistent ? " is now" : " was already" );
1284+ comp->fgPgoConsistent = false ;
12681285 }
12691286 }
12701287 else
@@ -1447,6 +1464,22 @@ bool Lowering::TryLowerSwitchToBitTest(FlowEdge* jumpTable[],
14471464
14481465 bbSwitch->SetCond (case1Edge, case0Edge);
14491466
1467+ //
1468+ // Update profile
1469+ //
1470+ if (bbSwitch->hasProfileWeight ())
1471+ {
1472+ bbCase0->setBBProfileWeight (bbCase0->computeIncomingWeight ());
1473+ bbCase1->setBBProfileWeight (bbCase1->computeIncomingWeight ());
1474+
1475+ if ((bbCase0->NumSucc () > 0 ) || (bbCase1->NumSucc () > 0 ))
1476+ {
1477+ JITDUMP (" TryLowerSwitchToBitTest: Flow out of " FMT_BB " needs to be propagated. Data %s inconsistent.\n " ,
1478+ bbSwitch->bbNum , comp->fgPgoConsistent ? " is now" : " was already" );
1479+ comp->fgPgoConsistent = false ;
1480+ }
1481+ }
1482+
14501483 var_types bitTableType = (bitCount <= (genTypeSize (TYP_INT) * 8 )) ? TYP_INT : TYP_LONG;
14511484 GenTree* bitTableIcon = comp->gtNewIconNode (bitTable, bitTableType);
14521485
0 commit comments