Deleted Added
full compact
62,64c62,63
< if (isa<FreeInst>(BBI) ||
< (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
< !isa<DbgInfoIntrinsic>(BBI)))
---
> if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
> !isa<DbgInfoIntrinsic>(BBI))
113c112,114
< } else if (Dest2 == Dest1) { // Conditional branch to same location?
---
> }
>
> if (Dest2 == Dest1) { // Conditional branch to same location?
126c127,130
< } else if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) {
---
> return false;
> }
>
> if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) {
135c139
< // Figure out which case it goes to...
---
> // Figure out which case it goes to.
146c150
< // Remove this entry...
---
> // Remove this entry.
168c172
< // Insert the new branch..
---
> // Insert the new branch.
182c186
< // Delete the old switch...
---
> // Delete the old switch.
185c189,191
< } else if (SI->getNumSuccessors() == 2) {
---
> }
>
> if (SI->getNumSuccessors() == 2) {
190c196
< // Insert the new branch...
---
> // Insert the new branch.
193c199
< // Delete the old switch...
---
> // Delete the old switch.
196a203
> return false;
197a205,233
>
> if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(T)) {
> // indirectbr blockaddress(@F, @BB) -> br label @BB
> if (BlockAddress *BA =
> dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
> BasicBlock *TheOnlyDest = BA->getBasicBlock();
> // Insert the new branch.
> BranchInst::Create(TheOnlyDest, IBI);
>
> for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
> if (IBI->getDestination(i) == TheOnlyDest)
> TheOnlyDest = 0;
> else
> IBI->getDestination(i)->removePredecessor(IBI->getParent());
> }
> IBI->eraseFromParent();
>
> // If we didn't find our destination in the IBI successor list, then we
> // have undefined behavior. Replace the unconditional branch with an
> // 'unreachable' instruction.
> if (TheOnlyDest) {
> BB->getTerminator()->eraseFromParent();
> new UnreachableInst(BB->getContext(), BB);
> }
>
> return true;
> }
> }
>