@@ -1066,11 +1066,11 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
10661066 for (unsigned i = 0 ; i < jumpCnt - 1 ; ++i)
10671067 {
10681068 assert (currentBlock != nullptr );
1069- BasicBlock* const targetBlock = jumpTab[i]->getDestinationBlock ();
10701069
10711070 // Remove the switch from the predecessor list of this case target's block.
10721071 // We'll add the proper new predecessor edge later.
1073- FlowEdge* const oldEdge = jumpTab[i];
1072+ FlowEdge* const oldEdge = jumpTab[i];
1073+ BasicBlock* const targetBlock = oldEdge->getDestinationBlock ();
10741074
10751075 // Compute the likelihood that this test is successful.
10761076 // Divide by number of cases still sharing this edge (reduces likelihood)
@@ -1131,8 +1131,9 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
11311131 {
11321132 BasicBlock* const newBlock = comp->fgNewBBafter (BBJ_ALWAYS, currentBlock, true );
11331133 FlowEdge* const newEdge = comp->fgAddRefPred (newBlock, currentBlock);
1134- currentBlock = newBlock;
1135- currentBBRange = &LIR::AsRange (currentBlock);
1134+ newBlock->inheritWeight (currentBlock);
1135+ currentBlock = newBlock;
1136+ currentBBRange = &LIR::AsRange (currentBlock);
11361137 afterDefaultCondBlock->SetKindAndTargetEdge (BBJ_ALWAYS, newEdge);
11371138 }
11381139
@@ -1207,6 +1208,25 @@ GenTree* Lowering::LowerSwitch(GenTree* node)
12071208 currentBlock->RemoveFlags (BBF_DONT_REMOVE);
12081209 comp->fgRemoveBlock (currentBlock, /* unreachable */ false ); // It's an empty block.
12091210 }
1211+
1212+ // Update flow into switch targets
1213+ if (afterDefaultCondBlock->hasProfileWeight ())
1214+ {
1215+ bool profileInconsistent = false ;
1216+ for (unsigned i = 0 ; i < jumpCnt - 1 ; i++)
1217+ {
1218+ BasicBlock* const targetBlock = jumpTab[i]->getDestinationBlock ();
1219+ targetBlock->setBBProfileWeight (targetBlock->computeIncomingWeight ());
1220+ profileInconsistent |= (targetBlock->NumSucc () > 0 );
1221+ }
1222+
1223+ if (profileInconsistent)
1224+ {
1225+ JITDUMP (" Switch lowering: Flow out of " FMT_BB " needs to be propagated. Data %s inconsistent.\n " ,
1226+ afterDefaultCondBlock->bbNum , comp->fgPgoConsistent ? " is now" : " was already" );
1227+ comp->fgPgoConsistent = false ;
1228+ }
1229+ }
12101230 }
12111231 else
12121232 {
0 commit comments