@@ -3962,6 +3962,28 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
3962
3962
return !TrivialUnwindBlocks.empty ();
3963
3963
}
3964
3964
3965
+ // Check if cleanup block is empty
3966
+ static bool isCleanupBlockEmpty (Instruction *Inst, Instruction *RI) {
3967
+ BasicBlock::iterator I = Inst->getIterator (), E = RI->getIterator ();
3968
+ while (++I != E) {
3969
+ auto *II = dyn_cast<IntrinsicInst>(I);
3970
+ if (!II)
3971
+ return false ;
3972
+
3973
+ Intrinsic::ID IntrinsicID = II->getIntrinsicID ();
3974
+ switch (IntrinsicID) {
3975
+ case Intrinsic::dbg_declare:
3976
+ case Intrinsic::dbg_value:
3977
+ case Intrinsic::dbg_label:
3978
+ case Intrinsic::lifetime_end:
3979
+ break ;
3980
+ default :
3981
+ return false ;
3982
+ }
3983
+ }
3984
+ return true ;
3985
+ }
3986
+
3965
3987
// Simplify resume that is only used by a single (non-phi) landing pad.
3966
3988
bool SimplifyCFGOpt::simplifySingleResume (ResumeInst *RI) {
3967
3989
BasicBlock *BB = RI->getParent ();
@@ -3970,10 +3992,8 @@ bool SimplifyCFGOpt::simplifySingleResume(ResumeInst *RI) {
3970
3992
" Resume must unwind the exception that caused control to here" );
3971
3993
3972
3994
// Check that there are no other instructions except for debug intrinsics.
3973
- BasicBlock::iterator I = LPInst->getIterator (), E = RI->getIterator ();
3974
- while (++I != E)
3975
- if (!isa<DbgInfoIntrinsic>(I))
3976
- return false ;
3995
+ if (!isCleanupBlockEmpty (LPInst, RI))
3996
+ return false ;
3977
3997
3978
3998
// Turn all invokes that unwind here into calls and delete the basic block.
3979
3999
for (pred_iterator PI = pred_begin (BB), PE = pred_end (BB); PI != PE;) {
@@ -4009,23 +4029,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
4009
4029
return false ;
4010
4030
4011
4031
// Check that there are no other instructions except for benign intrinsics.
4012
- BasicBlock::iterator I = CPInst->getIterator (), E = RI->getIterator ();
4013
- while (++I != E) {
4014
- auto *II = dyn_cast<IntrinsicInst>(I);
4015
- if (!II)
4016
- return false ;
4017
-
4018
- Intrinsic::ID IntrinsicID = II->getIntrinsicID ();
4019
- switch (IntrinsicID) {
4020
- case Intrinsic::dbg_declare:
4021
- case Intrinsic::dbg_value:
4022
- case Intrinsic::dbg_label:
4023
- case Intrinsic::lifetime_end:
4024
- break ;
4025
- default :
4026
- return false ;
4027
- }
4028
- }
4032
+ if (!isCleanupBlockEmpty (CPInst, RI))
4033
+ return false ;
4029
4034
4030
4035
// If the cleanup return we are simplifying unwinds to the caller, this will
4031
4036
// set UnwindDest to nullptr.
0 commit comments