@@ -540,14 +540,12 @@ void Compiler::fgReplaceSwitchJumpTarget(BasicBlock* blockSwitch, BasicBlock* ne
540540//
541541// Notes:
542542// 1. Only branches are changed: BBJ_ALWAYS, the non-fallthrough path of BBJ_COND, BBJ_SWITCH, etc.
543- // We ignore other block types .
543+ // We assert for other jump kinds .
544544// 2. All branch targets found are updated. If there are multiple ways for a block
545545// to reach 'oldTarget' (e.g., multiple arms of a switch), all of them are changed.
546- // 3. The predecessor lists are not changed .
546+ // 3. The predecessor lists are updated, if they've been built .
547547// 4. If any switch table entry was updated, the switch table "unique successor" cache is invalidated.
548548//
549- // This function is most useful early, before the full predecessor lists have been computed.
550- //
551549void Compiler::fgReplaceJumpTarget (BasicBlock* block, BasicBlock* newTarget, BasicBlock* oldTarget)
552550{
553551 assert (block != nullptr );
@@ -559,18 +557,18 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* newTarget, Bas
559557 case BBJ_ALWAYS:
560558 case BBJ_EHCATCHRET:
561559 case BBJ_EHFILTERRET:
562- case BBJ_LEAVE: // This function will be called before import, so we still have BBJ_LEAVE
560+ case BBJ_LEAVE: // This function can be called before import, so we still have BBJ_LEAVE
563561
564562 if (block->bbJumpDest == oldTarget)
565563 {
566564 block->bbJumpDest = newTarget;
567- }
568- break ;
569565
570- case BBJ_NONE:
571- case BBJ_EHFINALLYRET:
572- case BBJ_THROW:
573- case BBJ_RETURN:
566+ if (fgComputePredsDone)
567+ {
568+ fgRemoveRefPred (oldTarget, block);
569+ fgAddRefPred (newTarget, block);
570+ }
571+ }
574572 break ;
575573
576574 case BBJ_SWITCH:
@@ -585,6 +583,12 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* newTarget, Bas
585583 {
586584 jumpTab[i] = newTarget;
587585 changed = true ;
586+
587+ if (fgComputePredsDone)
588+ {
589+ fgRemoveRefPred (oldTarget, block);
590+ fgAddRefPred (newTarget, block);
591+ }
588592 }
589593 }
590594
@@ -596,7 +600,7 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* newTarget, Bas
596600 }
597601
598602 default :
599- assert (!" Block doesn't have a valid bbJumpKind!!! !" );
603+ assert (!" Block doesn't have a jump target !" );
600604 unreached ();
601605 break ;
602606 }
0 commit comments