@@ -3587,54 +3587,43 @@ bool Compiler::fgReorderBlocks(bool useProfile)
3587
3587
{
3588
3588
noway_assert (bPrev->KindIs (BBJ_COND));
3589
3589
//
3590
- // We will reverse branch if the taken-jump to bDest ratio (i.e. 'takenRatio')
3591
- // is more than 51%
3590
+ // We will reverse branch if the true edge's likelihood is more than 51%.
3592
3591
//
3593
- // We will setup profHotWeight to be maximum bbWeight that a block
3594
- // could have for us not to want to reverse the conditional branch
3592
+ // We will set up profHotWeight to be maximum bbWeight that a block
3593
+ // could have for us not to want to reverse the conditional branch.
3595
3594
//
3596
3595
// We will consider all blocks that have less weight than profHotWeight to be
3597
- // uncommonly run blocks as compared with the hot path of bPrev taken-jump to bDest
3596
+ // uncommonly run blocks compared to the weight of bPrev's true edge.
3598
3597
//
3599
- // We will check that the weight of the bPrev to bDest edge
3600
- // is more than twice the weight of the bPrev to block edge.
3598
+ // We will check if bPrev's true edge weight
3599
+ // is more than twice bPrev's false edge weight .
3601
3600
//
3602
- // bPrev --> [BB04, weight 31 ]
3601
+ // bPrev --> [BB04, weight 100 ]
3603
3602
// | \.
3604
- // edgeToBlock -------------> O \.
3605
- // [min=8,max=10] V \.
3606
- // block --> [BB05, weight 10 ] \.
3603
+ // falseEdge -- -------------> O \.
3604
+ // [likelihood=0.33] V \.
3605
+ // block --> [BB05, weight 33 ] \.
3607
3606
// \.
3608
- // edgeToDest ----------------------------> O
3609
- // [min=21,max=23] |
3607
+ // trueEdge -- ----------------------------> O
3608
+ // [likelihood=0.67] |
3610
3609
// V
3611
- // bDest ---------------> [BB08, weight 21 ]
3610
+ // bDest ---------------> [BB08, weight 67 ]
3612
3611
//
3613
3612
assert (bPrev->FalseTargetIs (block));
3614
- FlowEdge* edgeToDest = bPrev->GetTrueEdge ();
3615
- FlowEdge* edgeToBlock = bPrev->GetFalseEdge ();
3616
- noway_assert (edgeToDest != nullptr );
3617
- noway_assert (edgeToBlock != nullptr );
3618
- //
3619
- // Calculate the taken ratio
3620
- // A takenRatio of 0.10 means taken 10% of the time, not taken 90% of the time
3621
- // A takenRatio of 0.50 means taken 50% of the time, not taken 50% of the time
3622
- // A takenRatio of 0.90 means taken 90% of the time, not taken 10% of the time
3623
- //
3624
- double takenCount = edgeToDest->getLikelyWeight ();
3625
- double notTakenCount = edgeToBlock->getLikelyWeight ();
3626
- double totalCount = takenCount + notTakenCount;
3613
+ FlowEdge* trueEdge = bPrev->GetTrueEdge ();
3614
+ FlowEdge* falseEdge = bPrev->GetFalseEdge ();
3615
+ noway_assert (trueEdge != nullptr );
3616
+ noway_assert (falseEdge != nullptr );
3627
3617
3628
- // If the takenRatio (takenCount / totalCount) is greater or equal to 51% then we will reverse
3629
- // the branch
3630
- if (takenCount < (0.51 * totalCount))
3618
+ // If we take the true branch more than half the time, we will reverse the branch.
3619
+ if (trueEdge->getLikelihood () < 0.51 )
3631
3620
{
3632
3621
reorderBlock = false ;
3633
3622
}
3634
3623
else
3635
3624
{
3636
3625
// set profHotWeight
3637
- profHotWeight = edgeToBlock ->getLikelyWeight () - 1 ;
3626
+ profHotWeight = falseEdge ->getLikelyWeight () - 1 ;
3638
3627
}
3639
3628
}
3640
3629
}
0 commit comments