@@ -612,25 +612,28 @@ void StructurizeCFG::insertConditions(bool Loops) {
612
612
BasicBlock *SuccTrue = Term->getSuccessor (0 );
613
613
BasicBlock *SuccFalse = Term->getSuccessor (1 );
614
614
615
- BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
615
+ PhiInserter.Initialize (Boolean, " " );
616
+ PhiInserter.AddAvailableValue (Loops ? SuccFalse : Parent, Default);
616
617
617
- if (Preds.size () == 1 && Preds.begin ()->first == Parent) {
618
- auto &PI = Preds.begin ()->second ;
619
- Term->setCondition (PI.Pred );
620
- CondBranchWeights::setMetadata (*Term, PI.Weights );
621
- } else {
622
- PhiInserter.Initialize (Boolean, " " );
623
- PhiInserter.AddAvailableValue (Loops ? SuccFalse : Parent, Default);
618
+ BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
624
619
625
- NearestCommonDominator Dominator (DT);
626
- Dominator.addBlock (Parent);
620
+ NearestCommonDominator Dominator (DT);
621
+ Dominator.addBlock (Parent);
627
622
628
- for (auto [BB, PI] : Preds) {
629
- assert (BB != Parent);
630
- PhiInserter.AddAvailableValue (BB, PI.Pred );
631
- Dominator.addAndRememberBlock (BB);
623
+ PredInfo ParentInfo{nullptr , std::nullopt};
624
+ for (auto [BB, PI] : Preds) {
625
+ if (BB == Parent) {
626
+ ParentInfo = PI;
627
+ break ;
632
628
}
629
+ PhiInserter.AddAvailableValue (BB, PI.Pred );
630
+ Dominator.addAndRememberBlock (BB);
631
+ }
633
632
633
+ if (ParentInfo.Pred ) {
634
+ Term->setCondition (ParentInfo.Pred );
635
+ CondBranchWeights::setMetadata (*Term, ParentInfo.Weights );
636
+ } else {
634
637
if (!Dominator.resultIsRememberedBlock ())
635
638
PhiInserter.AddAvailableValue (Dominator.result (), Default);
636
639
0 commit comments