(Almost) always call reserveOperandSpace() on newly created PHINodes.
authorJay Foad <jay.foad@gmail.com>
Wed, 30 Mar 2011 11:19:20 +0000 (11:19 +0000)
committerJay Foad <jay.foad@gmail.com>
Wed, 30 Mar 2011 11:19:20 +0000 (11:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128535 91177308-0d34-0410-b5e6-96231b3b80d8

26 files changed:
examples/Kaleidoscope/Chapter5/toy.cpp
examples/Kaleidoscope/Chapter6/toy.cpp
examples/Kaleidoscope/Chapter7/toy.cpp
lib/Analysis/ScalarEvolutionExpander.cpp
lib/CodeGen/DwarfEHPrepare.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/LowerSetJmp.cpp
lib/Transforms/IPO/PartialInlining.cpp
lib/Transforms/InstCombine/InstCombineCasts.cpp
lib/Transforms/InstCombine/InstCombinePHI.cpp
lib/Transforms/Instrumentation/PathProfiling.cpp
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Scalar/LoopStrengthReduce.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Scalar/SimplifyCFGPass.cpp
lib/Transforms/Scalar/TailRecursionElimination.cpp
lib/Transforms/Utils/BasicBlockUtils.cpp
lib/Transforms/Utils/BreakCriticalEdges.cpp
lib/Transforms/Utils/CodeExtractor.cpp
lib/Transforms/Utils/InlineFunction.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
tools/bugpoint/Miscompilation.cpp
unittests/Transforms/Utils/Local.cpp

index 26b3db66202f82270349eefd025947c1db3cf851..e3f7565aa98f0702ca45f202197caee3a7bf72eb 100644 (file)
@@ -552,6 +552,7 @@ Value *IfExprAST::Codegen() {
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
                                   "iftmp");
+  PN->reserveOperandSpace(2);
   
   PN->addIncoming(ThenV, ThenBB);
   PN->addIncoming(ElseV, ElseBB);
@@ -593,6 +594,7 @@ Value *ForExprAST::Codegen() {
   
   // Start the PHI node with an entry for Start.
   PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
+  Variable->reserveOperandSpace(2);
   Variable->addIncoming(StartVal, PreheaderBB);
   
   // Within the loop, the variable is defined equal to the PHI node.  If it
index 838125ae77dcfdde66950ed7b4e29117fa1e494e..5316b80be548b3604aa636616ac413d3b61b14ef 100644 (file)
@@ -656,6 +656,7 @@ Value *IfExprAST::Codegen() {
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
                                   "iftmp");
+  PN->reserveOperandSpace(2);
   
   PN->addIncoming(ThenV, ThenBB);
   PN->addIncoming(ElseV, ElseBB);
@@ -697,6 +698,7 @@ Value *ForExprAST::Codegen() {
   
   // Start the PHI node with an entry for Start.
   PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
+  Variable->reserveOperandSpace(2);
   Variable->addIncoming(StartVal, PreheaderBB);
   
   // Within the loop, the variable is defined equal to the PHI node.  If it
index e63578f57e6c91c8b205fcfcda4d5c9175afb0c9..4070d3f38e709d4f8f4fced9035cd229f16dc7a3 100644 (file)
@@ -752,6 +752,7 @@ Value *IfExprAST::Codegen() {
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
                                   "iftmp");
+  PN->reserveOperandSpace(2);
   
   PN->addIncoming(ThenV, ThenBB);
   PN->addIncoming(ElseV, ElseBB);
index c642f7ef0caafd182eea1a99e00280a302764953..f506514a618ab276fa51968ec9deb797bfdac7df 100644 (file)
@@ -932,14 +932,15 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
   Value *StepV = expandCodeFor(Step, IntTy, L->getHeader()->begin());
 
   // Create the PHI.
-  Builder.SetInsertPoint(L->getHeader(), L->getHeader()->begin());
+  BasicBlock *Header = L->getHeader();
+  Builder.SetInsertPoint(Header, Header->begin());
+  pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
   PHINode *PN = Builder.CreatePHI(ExpandTy, "lsr.iv");
+  PN->reserveOperandSpace(std::distance(HPB, HPE));
   rememberInstruction(PN);
 
   // Create the step instructions and populate the PHI.
-  BasicBlock *Header = L->getHeader();
-  for (pred_iterator HPI = pred_begin(Header), HPE = pred_end(Header);
-       HPI != HPE; ++HPI) {
+  for (pred_iterator HPI = HPB; HPI != HPE; ++HPI) {
     BasicBlock *Pred = *HPI;
 
     // Add a start value.
@@ -1141,12 +1142,13 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
     // Create and insert the PHI node for the induction variable in the
     // specified loop.
     BasicBlock *Header = L->getHeader();
+    pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
     CanonicalIV = PHINode::Create(Ty, "indvar", Header->begin());
+    CanonicalIV->reserveOperandSpace(std::distance(HPB, HPE));
     rememberInstruction(CanonicalIV);
 
     Constant *One = ConstantInt::get(Ty, 1);
-    for (pred_iterator HPI = pred_begin(Header), HPE = pred_end(Header);
-         HPI != HPE; ++HPI) {
+    for (pred_iterator HPI = HPB; HPI != HPE; ++HPI) {
       BasicBlock *HP = *HPI;
       if (L->contains(HP)) {
         // Insert a unit add instruction right before the terminator
index d5a2ed977f3a47b765cc8e301f631073bbd26ece..35c25e8a67ba83bda4af51c743c9777f132d8472 100644 (file)
@@ -441,6 +441,7 @@ bool DwarfEHPrepare::NormalizeLandingPads() {
         // in NewBB.
         PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".unwind",
                                          NewBB);
+        NewPN->reserveOperandSpace(PN->getNumIncomingValues());
         // Add an entry for each unwind edge, using the value from the old PHI.
         for (pred_iterator PI = PB; PI != PE; ++PI)
           NewPN->addIncoming(PN->getIncomingValueForBlock(*PI), *PI);
index 0087362e339d42fbd350413f10962dbfacf2ec23..5e21a21ea224544722f097c2256a92a298039102 100644 (file)
@@ -1193,9 +1193,11 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo,
     const StructType *ST =
       cast<StructType>(cast<PointerType>(PN->getType())->getElementType());
 
-    Result =
+    PHINode *NewPN =
      PHINode::Create(PointerType::getUnqual(ST->getElementType(FieldNo)),
                      PN->getName()+".f"+Twine(FieldNo), PN);
+    NewPN->reserveOperandSpace(PN->getNumIncomingValues());
+    Result = NewPN;
     PHIsToRewrite.push_back(std::make_pair(PN, FieldNo));
   } else {
     llvm_unreachable("Unknown usable value");
index b545f0bb267de040009dd6fa2e059fc6712464ce..cb3875ec1ead596d922b4323726b45865cd465a8 100644 (file)
@@ -432,6 +432,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
   // splitBasicBlock call.
   PHINode* PHI = PHINode::Create(Type::getInt32Ty(Inst->getContext()),
                                  "SetJmpReturn", Inst);
+  PHI->reserveOperandSpace(2);
 
   // Coming from a call to setjmp, the return is 0.
   PHI->addIncoming(Constant::getNullValue(Type::getInt32Ty(Inst->getContext())),
index 2afd02985764eb0357397bf171970537024edac0..7fa0de129359f61c230ffb58ba328bba9adafe53 100644 (file)
@@ -96,6 +96,7 @@ Function* PartialInliner::unswitchFunction(Function* F) {
     if (!OldPhi) break;
     
     PHINode* retPhi = PHINode::Create(OldPhi->getType(), "", Ins);
+    retPhi->reserveOperandSpace(2);
     OldPhi->replaceAllUsesWith(retPhi);
     Ins = newReturnBlock->getFirstNonPHI();
     
index dcf7be1a91a218dac61c1502cfaca750efd9e7f5..9976d82b8be62137b5373ff0abb4d39c3432f88b 100644 (file)
@@ -197,6 +197,7 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty,
   case Instruction::PHI: {
     PHINode *OPN = cast<PHINode>(I);
     PHINode *NPN = PHINode::Create(Ty);
+    NPN->reserveOperandSpace(OPN->getNumIncomingValues());
     for (unsigned i = 0, e = OPN->getNumIncomingValues(); i != e; ++i) {
       Value *V =EvaluateInDifferentType(OPN->getIncomingValue(i), Ty, isSigned);
       NPN->addIncoming(V, OPN->getIncomingBlock(i));
index 2c0714bfc5ae4f1ba7dcd833ca2e825ddac8229b..9e2e181d142ca436b9717c596d112b9a8f530b7f 100644 (file)
@@ -700,6 +700,7 @@ Instruction *InstCombiner::SliceUpIllegalIntegerPHI(PHINode &FirstPhi) {
       
       // Otherwise, Create the new PHI node for this user.
       EltPHI = PHINode::Create(Ty, PN->getName()+".off"+Twine(Offset), PN);
+      EltPHI->reserveOperandSpace(PN->getNumIncomingValues());
       assert(EltPHI->getType() != PN->getType() &&
              "Truncate didn't shrink phi?");
     
index 6449b39cfc9d7641b41e6d426c64c79e2dc4e9bf..ca2c6fbd95d144566cf8dff299c59f461b08cc92 100644 (file)
@@ -929,14 +929,16 @@ BasicBlock::iterator PathProfiler::getInsertionPoint(BasicBlock* block, Value*
 void PathProfiler::preparePHI(BLInstrumentationNode* node) {
   BasicBlock* block = node->getBlock();
   BasicBlock::iterator insertPoint = block->getFirstNonPHI();
+  pred_iterator PB = pred_begin(node->getBlock()),
+          PE = pred_end(node->getBlock());
   PHINode* phi = PHINode::Create(Type::getInt32Ty(*Context), "pathNumber",
                                  insertPoint );
+  phi->reserveOperandSpace(std::distance(PB, PE));
   node->setPathPHI(phi);
   node->setStartingPathNumber(phi);
   node->setEndingPathNumber(phi);
 
-  for(pred_iterator predIt = pred_begin(node->getBlock()),
-        end = pred_end(node->getBlock()); predIt != end; predIt++) {
+  for(pred_iterator predIt = PB; predIt != PE; predIt++) {
     BasicBlock* pred = (*predIt);
 
     if(pred != NULL)
index a0123f58981611b8a89631d51ee42345dd9b7142..9a7591e6c306933895052710ff4c8b5b7e09b35f 100644 (file)
@@ -1944,11 +1944,12 @@ bool GVN::performPRE(Function &F) {
       addToLeaderTable(ValNo, PREInstr, PREPred);
 
       // Create a PHI to make the value available in this block.
+      pred_iterator PB = pred_begin(CurrentBlock), PE = pred_end(CurrentBlock);
       PHINode* Phi = PHINode::Create(CurInst->getType(),
                                      CurInst->getName() + ".pre-phi",
                                      CurrentBlock->begin());
-      for (pred_iterator PI = pred_begin(CurrentBlock),
-           PE = pred_end(CurrentBlock); PI != PE; ++PI) {
+      Phi->reserveOperandSpace(std::distance(PB, PE));
+      for (pred_iterator PI = PB; PI != PE; ++PI) {
         BasicBlock *P = *PI;
         Phi->addIncoming(predMap[P], P);
       }
index bf327413932a0ad777720b2f266798f67c519db2..f9641c6322f19e0b02f819626629cc61d739fe20 100644 (file)
@@ -1039,6 +1039,7 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PN) {
 
   // Insert new integer induction variable.
   PHINode *NewPHI = PHINode::Create(Int32Ty, PN->getName()+".int", PN);
+  NewPHI->reserveOperandSpace(2);
   NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
                       PN->getIncomingBlock(IncomingEdge));
 
index 90094a8da2573244affe6e5bcd015ace6d2f0b93..a79b5b1938707ead9aa6534292eddaae2afecb60 100644 (file)
@@ -928,13 +928,14 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
   array_pod_sort(AvailablePreds.begin(), AvailablePreds.end());
 
   // Create a PHI node at the start of the block for the PRE'd load value.
+  pred_iterator PB = pred_begin(LoadBB), PE = pred_end(LoadBB);
   PHINode *PN = PHINode::Create(LI->getType(), "", LoadBB->begin());
+  PN->reserveOperandSpace(std::distance(PB, PE));
   PN->takeName(LI);
 
   // Insert new entries into the PHI for each predecessor.  A single block may
   // have multiple entries here.
-  for (pred_iterator PI = pred_begin(LoadBB), E = pred_end(LoadBB); PI != E;
-       ++PI) {
+  for (pred_iterator PI = PB; PI != PE; ++PI) {
     BasicBlock *P = *PI;
     AvailablePredsTy::iterator I =
       std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(),
index 1bc6f5259d2dc15351d0dffc543ad2ce1224fc1a..b816dd55bb46ac713bd3db1935ebef96239eec50 100644 (file)
@@ -1492,6 +1492,7 @@ void LSRInstance::OptimizeShadowIV() {
 
     /* Add new PHINode. */
     PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
+    NewPH->reserveOperandSpace(2);
 
     /* create new increment. '++d' in above example. */
     Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
index 191b667ea30de322bce222dbbea5c78b9c0bd15a..4fdaa1ef922c2d2cd1ff48f9e8aaf8bb00c03fd8 100644 (file)
@@ -1228,6 +1228,7 @@ static bool tryToMakeAllocaBePromotable(AllocaInst *AI, const TargetData *TD) {
     
     const Type *LoadTy = cast<PointerType>(PN->getType())->getElementType();
     PHINode *NewPN = PHINode::Create(LoadTy, PN->getName()+".ld", PN);
+    NewPN->reserveOperandSpace(PN->getNumIncomingValues());
 
     // Get the TBAA tag and alignment to use from one of the loads.  It doesn't
     // matter which one we get and if any differ, it doesn't matter.
index ce5dd73ace326ad6aa31868fe01948c593ff26b5..e3a9329a18dd79f051ee3b093091a699e8c88d61 100644 (file)
@@ -259,11 +259,12 @@ static bool MergeEmptyReturnBlocks(Function &F) {
     PHINode *RetBlockPHI = dyn_cast<PHINode>(RetBlock->begin());
     if (RetBlockPHI == 0) {
       Value *InVal = cast<ReturnInst>(RetBlock->getTerminator())->getOperand(0);
+      pred_iterator PB = pred_begin(RetBlock), PE = pred_end(RetBlock);
       RetBlockPHI = PHINode::Create(Ret->getOperand(0)->getType(), "merge",
                                     &RetBlock->front());
+      RetBlockPHI->reserveOperandSpace(std::distance(PB, PE));
       
-      for (pred_iterator PI = pred_begin(RetBlock), E = pred_end(RetBlock);
-           PI != E; ++PI)
+      for (pred_iterator PI = PB; PI != PE; ++PI)
         RetBlockPHI->addIncoming(InVal, *PI);
       RetBlock->getTerminator()->setOperand(0, RetBlockPHI);
     }
index 5b6bc04cc1c2dff3641cedd902c046bd710ccd70..51af6119f4b8a1c03d7540272d7d09a9b6fe06d1 100644 (file)
@@ -498,6 +498,7 @@ bool TailCallElim::EliminateRecursiveTailCall(CallInst *CI, ReturnInst *Ret,
          I != E; ++I) {
       PHINode *PN = PHINode::Create(I->getType(),
                                     I->getName() + ".tr", InsertPos);
+      PN->reserveOperandSpace(2);
       I->replaceAllUsesWith(PN); // Everyone use the PHI node now!
       PN->addIncoming(I, NewEntry);
       ArgumentPHIs.push_back(PN);
@@ -527,9 +528,11 @@ bool TailCallElim::EliminateRecursiveTailCall(CallInst *CI, ReturnInst *Ret,
   if (AccumulatorRecursionEliminationInitVal) {
     Instruction *AccRecInstr = AccumulatorRecursionInstr;
     // Start by inserting a new PHI node for the accumulator.
+    pred_iterator PB = pred_begin(OldEntry), PE = pred_end(OldEntry);
     PHINode *AccPN =
       PHINode::Create(AccumulatorRecursionEliminationInitVal->getType(),
                       "accumulator.tr", OldEntry->begin());
+    AccPN->reserveOperandSpace(std::distance(PB, PE) + 1);
 
     // Loop over all of the predecessors of the tail recursion block.  For the
     // real entry into the function we seed the PHI with the initial value,
@@ -537,8 +540,7 @@ bool TailCallElim::EliminateRecursiveTailCall(CallInst *CI, ReturnInst *Ret,
     // other tail recursions eliminated) the accumulator is not modified.
     // Because we haven't added the branch in the current block to OldEntry yet,
     // it will not show up as a predecessor.
-    for (pred_iterator PI = pred_begin(OldEntry), PE = pred_end(OldEntry);
-         PI != PE; ++PI) {
+    for (pred_iterator PI = PB; PI != PE; ++PI) {
       BasicBlock *P = *PI;
       if (P == &F->getEntryBlock())
         AccPN->addIncoming(AccumulatorRecursionEliminationInitVal, P);
index acaea195e710b982a72088678970ae68cca2f336..fb217bfa980a993072e910833a34f0798190b249 100644 (file)
@@ -448,6 +448,7 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
       // Create the new PHI node, insert it into NewBB at the end of the block
       PHINode *NewPHI =
         PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
+      NewPHI->reserveOperandSpace(NumPreds);
       if (AA) AA->copyValue(PN, NewPHI);
       
       // Move all of the PHI values for 'Preds' to the new PHI.
index 616b066b5ab140543399a0cd1f5049a7e0790ef6..3384cb6b5e1dd41774f212155ee1b1fb0a7adbcc 100644 (file)
@@ -142,6 +142,7 @@ static void CreatePHIsForSplitLoopExit(SmallVectorImpl<BasicBlock *> &Preds,
     // Otherwise a new PHI is needed. Create one and populate it.
     PHINode *NewPN = PHINode::Create(PN->getType(), "split",
                                      SplitBB->getTerminator());
+    NewPN->reserveOperandSpace(Preds.size());
     for (unsigned i = 0, e = Preds.size(); i != e; ++i)
       NewPN->addIncoming(V, Preds[i]);
     // Update the original PHI.
index e6337722c8bd65ea39134e8def3ba854ea16b159..7576717077f5038ad3aef77665ee708bfca9a8b5 100644 (file)
@@ -104,7 +104,7 @@ namespace {
 /// region, we need to split the entry block of the region so that the PHI node
 /// is easier to deal with.
 void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
-  bool HasPredsFromRegion = false;
+  unsigned NumPredsFromRegion = 0;
   unsigned NumPredsOutsideRegion = 0;
 
   if (Header != &Header->getParent()->getEntryBlock()) {
@@ -116,7 +116,7 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
     // header block into two.
     for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
       if (BlocksToExtract.count(PN->getIncomingBlock(i)))
-        HasPredsFromRegion = true;
+        ++NumPredsFromRegion;
       else
         ++NumPredsOutsideRegion;
 
@@ -147,7 +147,7 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
 
   // Okay, now we need to adjust the PHI nodes and any branches from within the
   // region to go to the new header block instead of the old header block.
-  if (HasPredsFromRegion) {
+  if (NumPredsFromRegion) {
     PHINode *PN = cast<PHINode>(OldPred->begin());
     // Loop over all of the predecessors of OldPred that are in the region,
     // changing them to branch to NewBB instead.
@@ -165,6 +165,7 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
       // from OldPred of PN.
       PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce",
                                        NewBB->begin());
+      NewPN->reserveOperandSpace(1+NumPredsFromRegion);
       NewPN->addIncoming(PN, OldPred);
 
       // Loop over all of the incoming value in PN, moving them to NewPN if they
index c1faf2411331c5a56bbbf965107e354df34fcf70..80d6770131815f447cdd675d7be375100e0256e5 100644 (file)
@@ -626,6 +626,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI) {
     if (!TheCall->use_empty()) {
       PHI = PHINode::Create(RTy, TheCall->getName(),
                             AfterCallBB->begin());
+      PHI->reserveOperandSpace(Returns.size());
       // Anything that used the result of the function call should now use the
       // PHI node as their operand.
       TheCall->replaceAllUsesWith(PHI);
index f924eebb0dfed53daf9f9335f7b05e2777341cbc..8b81555bc52e3a38ac756367c81a3e7fe803c512 100644 (file)
@@ -1598,13 +1598,15 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
     // in the constant and simplify the block result.  Subsequent passes of
     // simplifycfg will thread the block.
     if (BlockIsSimpleEnoughToThreadThrough(BB)) {
+      pred_iterator PB = pred_begin(BB), PE = pred_end(BB);
       PHINode *NewPN = PHINode::Create(Type::getInt1Ty(BB->getContext()),
                                        BI->getCondition()->getName() + ".pr",
                                        BB->begin());
+      NewPN->reserveOperandSpace(std::distance(PB, PE));
       // Okay, we're going to insert the PHI node.  Since PBI is not the only
       // predecessor, compute the PHI'd conditional value for all of the preds.
       // Any predecessor where the condition is not computable we keep symbolic.
-      for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
+      for (pred_iterator PI = PB; PI != PE; ++PI) {
         BasicBlock *P = *PI;
         if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) &&
             PBI != BI && PBI->isConditional() &&
index ccb8287d796980518ae1874d28b9748a6f89f720..24d20d0e84d34c786d7f69b232fa061686fa4fba 100644 (file)
@@ -117,6 +117,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
   } else {
     // If the function doesn't return void... add a PHI node to the block...
     PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
+    PN->reserveOperandSpace(ReturningBlocks.size());
     NewRetBlock->getInstList().push_back(PN);
     ReturnInst::Create(F.getContext(), PN, NewRetBlock);
   }
index 3a5f143ace64a7ac7375eefec6ea186ef673b884..eb609a79598aa653569afa7afcb3555d00dd80e1 100644 (file)
@@ -887,6 +887,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
 
           PHINode *FuncPtr = PHINode::Create(NullPtr->getType(),
                                              "fp", DoCallBB);
+          FuncPtr->reserveOperandSpace(2);
           FuncPtr->addIncoming(CastedResolver, LookupBB);
           FuncPtr->addIncoming(CachedVal, EntryBB);
 
index e0322b37d3326475ce3e042ee2655c48beacb574..7d173515f9aff4c4345fce058fe2ec3b17462ce1 100644 (file)
@@ -27,6 +27,7 @@ TEST(Local, RecursivelyDeleteDeadPHINodes) {
 
   builder.SetInsertPoint(bb0);
   PHINode    *phi = builder.CreatePHI(Type::getInt32Ty(C));
+  phi->reserveOperandSpace(2);
   BranchInst *br0 = builder.CreateCondBr(builder.getTrue(), bb0, bb1);
 
   builder.SetInsertPoint(bb1);