Use IRBuilder while simplifying terminator.

llvm-svn: 131552
This commit is contained in:
Devang Patel 2011-05-18 18:43:31 +00:00
parent faedd704bb
commit f0b8a243b9

View File

@ -1835,16 +1835,19 @@ static bool SimplifyTerminatorOnSelect(TerminatorInst *OldTerm, Value *Cond,
Succ->removePredecessor(OldTerm->getParent()); Succ->removePredecessor(OldTerm->getParent());
} }
IRBuilder<> Builder(OldTerm);
Builder.SetCurrentDebugLocation(OldTerm->getDebugLoc());
// Insert an appropriate new terminator. // Insert an appropriate new terminator.
if ((KeepEdge1 == 0) && (KeepEdge2 == 0)) { if ((KeepEdge1 == 0) && (KeepEdge2 == 0)) {
if (TrueBB == FalseBB) if (TrueBB == FalseBB)
// We were only looking for one successor, and it was present. // We were only looking for one successor, and it was present.
// Create an unconditional branch to it. // Create an unconditional branch to it.
BranchInst::Create(TrueBB, OldTerm); Builder.CreateBr(TrueBB);
else else
// We found both of the successors we were looking for. // We found both of the successors we were looking for.
// Create a conditional branch sharing the condition of the select. // Create a conditional branch sharing the condition of the select.
BranchInst::Create(TrueBB, FalseBB, Cond, OldTerm); Builder.CreateCondBr(Cond, TrueBB, FalseBB);
} else if (KeepEdge1 && (KeepEdge2 || TrueBB == FalseBB)) { } else if (KeepEdge1 && (KeepEdge2 || TrueBB == FalseBB)) {
// Neither of the selected blocks were successors, so this // Neither of the selected blocks were successors, so this
// terminator must be unreachable. // terminator must be unreachable.
@ -1855,10 +1858,10 @@ static bool SimplifyTerminatorOnSelect(TerminatorInst *OldTerm, Value *Cond,
// the edge to the one that wasn't must be unreachable. // the edge to the one that wasn't must be unreachable.
if (KeepEdge1 == 0) if (KeepEdge1 == 0)
// Only TrueBB was found. // Only TrueBB was found.
BranchInst::Create(TrueBB, OldTerm); Builder.CreateBr(TrueBB);
else else
// Only FalseBB was found. // Only FalseBB was found.
BranchInst::Create(FalseBB, OldTerm); Builder.CreateBr(FalseBB);
} }
EraseTerminatorInstAndDCECond(OldTerm); EraseTerminatorInstAndDCECond(OldTerm);