File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -3602,7 +3602,30 @@ Function *EnzymeLogic::CreatePrimalAndGradient(
3602
3602
}
3603
3603
3604
3604
for (auto sucBB : toRemove) {
3605
- sucBB->removePredecessor (newBB);
3605
+ if (sucBB->empty () || !isa<PHINode>(sucBB->begin ()))
3606
+ continue ;
3607
+
3608
+ SmallVector<PHINode *, 2 > phis;
3609
+ for (PHINode &Phi : sucBB->phis ()) {
3610
+ phis.push_back (&Phi);
3611
+ }
3612
+ for (PHINode *Phi : phis) {
3613
+ unsigned NumPreds = Phi->getNumIncomingValues ();
3614
+ if (NumPreds == 0 )
3615
+ continue ;
3616
+ Phi->removeIncomingValue (newBB);
3617
+
3618
+ // If we have a single predecessor, removeIncomingValue may have
3619
+ // erased the PHI node itself.
3620
+ if (NumPreds == 1 )
3621
+ continue ;
3622
+
3623
+ // Try to replace the PHI node with a constant value.
3624
+ if (Value *PhiConstant = Phi->hasConstantValue ()) {
3625
+ Phi->replaceAllUsesWith (PhiConstant);
3626
+ Phi->eraseFromParent ();
3627
+ }
3628
+ }
3606
3629
}
3607
3630
3608
3631
SmallVector<Instruction *, 2 > toerase;
You can’t perform that action at this time.
0 commit comments