@@ -2794,13 +2794,12 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2794
2794
// in the predecessor blocks can be promoted as well. If not, we won't be able
2795
2795
// to get rid of the control flow, so it's not worth promoting to select
2796
2796
// instructions.
2797
- BasicBlock *DomBlock = nullptr ;
2797
+ BasicBlock *DomBlock = DomBI-> getParent () ;
2798
2798
BasicBlock *IfBlock1 = PN->getIncomingBlock (0 );
2799
2799
BasicBlock *IfBlock2 = PN->getIncomingBlock (1 );
2800
2800
if (cast<BranchInst>(IfBlock1->getTerminator ())->isConditional ()) {
2801
2801
IfBlock1 = nullptr ;
2802
2802
} else {
2803
- DomBlock = *pred_begin (IfBlock1);
2804
2803
for (BasicBlock::iterator I = IfBlock1->begin (); !I->isTerminator (); ++I)
2805
2804
if (!AggressiveInsts.count (&*I) && !isa<DbgInfoIntrinsic>(I) &&
2806
2805
!isa<PseudoProbeInst>(I)) {
@@ -2814,7 +2813,6 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2814
2813
if (cast<BranchInst>(IfBlock2->getTerminator ())->isConditional ()) {
2815
2814
IfBlock2 = nullptr ;
2816
2815
} else {
2817
- DomBlock = *pred_begin (IfBlock2);
2818
2816
for (BasicBlock::iterator I = IfBlock2->begin (); !I->isTerminator (); ++I)
2819
2817
if (!AggressiveInsts.count (&*I) && !isa<DbgInfoIntrinsic>(I) &&
2820
2818
!isa<PseudoProbeInst>(I)) {
@@ -2824,7 +2822,6 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2824
2822
return Changed;
2825
2823
}
2826
2824
}
2827
- assert (DomBlock && " Failed to find root DomBlock" );
2828
2825
2829
2826
// If either of the blocks has it's address taken, we can't do this fold.
2830
2827
if ((IfBlock1 && IfBlock1->hasAddressTaken ()) ||
@@ -2837,16 +2834,15 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2837
2834
2838
2835
// If we can still promote the PHI nodes after this gauntlet of tests,
2839
2836
// do all of the PHI's now.
2840
- Instruction *InsertPt = DomBlock->getTerminator ();
2841
- IRBuilder<NoFolder> Builder (InsertPt);
2842
2837
2843
2838
// Move all 'aggressive' instructions, which are defined in the
2844
2839
// conditional parts of the if's up to the dominating block.
2845
2840
if (IfBlock1)
2846
- hoistAllInstructionsInto (DomBlock, InsertPt , IfBlock1);
2841
+ hoistAllInstructionsInto (DomBlock, DomBI , IfBlock1);
2847
2842
if (IfBlock2)
2848
- hoistAllInstructionsInto (DomBlock, InsertPt , IfBlock2);
2843
+ hoistAllInstructionsInto (DomBlock, DomBI , IfBlock2);
2849
2844
2845
+ IRBuilder<NoFolder> Builder (DomBI);
2850
2846
// Propagate fast-math-flags from phi nodes to replacement selects.
2851
2847
IRBuilder<>::FastMathFlagGuard FMFGuard (Builder);
2852
2848
while (PHINode *PN = dyn_cast<PHINode>(BB->begin ())) {
@@ -2857,7 +2853,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2857
2853
Value *TrueVal = PN->getIncomingValue (PN->getIncomingBlock (0 ) == IfFalse);
2858
2854
Value *FalseVal = PN->getIncomingValue (PN->getIncomingBlock (0 ) == IfTrue);
2859
2855
2860
- Value *Sel = Builder.CreateSelect (IfCond, TrueVal, FalseVal, " " , InsertPt );
2856
+ Value *Sel = Builder.CreateSelect (IfCond, TrueVal, FalseVal, " " , DomBI );
2861
2857
PN->replaceAllUsesWith (Sel);
2862
2858
Sel->takeName (PN);
2863
2859
PN->eraseFromParent ();
@@ -2866,8 +2862,6 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2866
2862
// At this point, IfBlock1 and IfBlock2 are both empty, so our if statement
2867
2863
// has been flattened. Change DomBlock to jump directly to our new block to
2868
2864
// avoid other simplifycfg's kicking in on the diamond.
2869
- Instruction *OldTI = DomBlock->getTerminator ();
2870
- Builder.SetInsertPoint (OldTI);
2871
2865
Builder.CreateBr (BB);
2872
2866
2873
2867
SmallVector<DominatorTree::UpdateType, 3 > Updates;
@@ -2877,7 +2871,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
2877
2871
Updates.push_back ({DominatorTree::Delete, DomBlock, Successor});
2878
2872
}
2879
2873
2880
- OldTI ->eraseFromParent ();
2874
+ DomBI ->eraseFromParent ();
2881
2875
if (DTU)
2882
2876
DTU->applyUpdates (Updates);
2883
2877
0 commit comments