Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 47bc554

Browse files
committed
[SimplifyCFG] Use a more elegant solution than r261731
The cleanupret instruction has an invariant that it's 'from' operand be a cleanuppad. This invariant was violated when we removed a dead block which removed a cleanuppad leaving behind a cleanupret with an undef 'from' operand. This was solved in r261731 by staving off the removal of the dead block to a later pass. However, it occured to me that we do not need to do this. Instead, we can simply avoid processing the cleanupret if it has an undef 'from' operand because we know that it will be removed soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261754 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6eb6867 commit 47bc554

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,12 @@ static bool mergeCleanupPad(CleanupReturnInst *RI) {
35213521
}
35223522

35233523
bool SimplifyCFGOpt::SimplifyCleanupReturn(CleanupReturnInst *RI) {
3524+
// It is possible to transiantly have an undef cleanuppad operand because we
3525+
// have deleted some, but not all, dead blocks.
3526+
// Eventually, this block will be deleted.
3527+
if (isa<UndefValue>(RI->getOperand(0)))
3528+
return false;
3529+
35243530
if (removeEmptyCleanup(RI))
35253531
return true;
35263532

@@ -5278,17 +5284,9 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
52785284
if ((pred_empty(BB) &&
52795285
BB != &BB->getParent()->getEntryBlock()) ||
52805286
BB->getSinglePredecessor() == BB) {
5281-
// Get the block mostly empty.
5282-
Changed |= removeAllNonTerminatorAndEHPadInstructions(BB) > 0;
5283-
// Now, verify that we succeeded getting the block empty.
5284-
// This will not be the case if this unreachable BB creates a token which is
5285-
// consumed by other unreachable blocks.
5286-
Instruction *FirstNonPHI = BB->getFirstNonPHI();
5287-
if (isa<TerminatorInst>(FirstNonPHI) && FirstNonPHI->use_empty()) {
5288-
DEBUG(dbgs() << "Removing BB: \n" << *BB);
5289-
DeleteDeadBlock(BB);
5290-
return true;
5291-
}
5287+
DEBUG(dbgs() << "Removing BB: \n" << *BB);
5288+
DeleteDeadBlock(BB);
5289+
return true;
52925290
}
52935291

52945292
// Check to see if we can constant propagate this terminator instruction

0 commit comments

Comments
 (0)