From d529943a27dc22269070f883877531fc4b52cdca Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Mon, 11 Sep 2023 15:00:13 +0100 Subject: [PATCH] [NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine As per my proposal for how to eliminate debug intrinsics [0], for various places in InstCombine prefer to insert using an instruction iterator rather than an instruction pointer. This is so that we can eventually pass more information in the iterator class. These call-sites where I've changed the spelling are those that necessary to build a stage2clang to produce an identical binary in the coming no-debug-intrinsics mode. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939 Differential Revision: https://reviews.llvm.org/D152543 --- .../llvm/Transforms/InstCombine/InstCombiner.h | 9 +++---- .../Transforms/InstCombine/InstCombineCalls.cpp | 2 +- .../Transforms/InstCombine/InstCombineCasts.cpp | 2 +- .../Transforms/InstCombine/InstCombineInternal.h | 2 +- .../InstCombine/InstCombineLoadStoreAlloca.cpp | 18 ++++++------- llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 22 ++++++++-------- .../Transforms/InstCombine/InstCombineSelect.cpp | 4 +-- .../Transforms/InstCombine/InstCombineShifts.cpp | 4 +-- .../InstCombine/InstCombineSimplifyDemanded.cpp | 30 +++++++++++----------- .../InstCombine/InstCombineVectorOps.cpp | 12 ++++----- .../InstCombine/InstructionCombining.cpp | 10 ++++---- 11 files changed, 57 insertions(+), 58 deletions(-) diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h index 6b5a7c3634dc..b16a60c423ab 100644 --- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h @@ -398,18 +398,17 @@ public: /// /// Also adds the new instruction to the worklist and returns \p New so that /// it is suitable for use as the return from the visitation patterns. - Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) { + Instruction *InsertNewInstBefore(Instruction *New, BasicBlock::iterator Old) { assert(New && !New->getParent() && "New instruction already inserted into a basic block!"); - BasicBlock *BB = Old.getParent(); - New->insertInto(BB, Old.getIterator()); // Insert inst + New->insertBefore(Old); // Insert inst Worklist.add(New); return New; } /// Same as InsertNewInstBefore, but also sets the debug loc. - Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) { - New->setDebugLoc(Old.getDebugLoc()); + Instruction *InsertNewInstWith(Instruction *New, BasicBlock::iterator Old) { + New->setDebugLoc(Old->getDebugLoc()); return InsertNewInstBefore(New, Old); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index b493dff23fc0..17cfd90ac209 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3994,7 +3994,7 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) { Instruction *InsertPt = NewCall->getInsertionPointAfterDef(); assert(InsertPt && "No place to insert cast"); - InsertNewInstBefore(NC, *InsertPt); + InsertNewInstBefore(NC, InsertPt->getIterator()); Worklist.pushUsersToWorkList(*Caller); } else { NV = PoisonValue::get(Caller->getType()); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 5c84f666616d..8ff61ab36da3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -112,7 +112,7 @@ Value *InstCombinerImpl::EvaluateInDifferentType(Value *V, Type *Ty, } Res->takeName(I); - return InsertNewInstWith(Res, *I); + return InsertNewInstWith(Res, I->getIterator()); } Instruction::CastOps diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index e742564c1300..e8d85134cf77 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -423,7 +423,7 @@ public: auto *SI = new StoreInst(ConstantInt::getTrue(Ctx), PoisonValue::get(PointerType::getUnqual(Ctx)), /*isVolatile*/ false, Align(1)); - InsertNewInstBefore(SI, *InsertAt); + InsertNewInstBefore(SI, InsertAt->getIterator()); } /// Combiner aware instruction erasure. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 6617a7ed5aff..6e491acc1403 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -224,7 +224,7 @@ static Instruction *simplifyAllocaArraySize(InstCombinerImpl &IC, Value *Idx[2] = {NullIdx, NullIdx}; Instruction *GEP = GetElementPtrInst::CreateInBounds( NewTy, New, Idx, New->getName() + ".sub"); - IC.InsertNewInstBefore(GEP, *It); + IC.InsertNewInstBefore(GEP, It); // Now make everything use the getelementptr instead of the original // allocation. @@ -380,7 +380,7 @@ void PointerReplacer::replace(Instruction *I) { NewI->takeName(LT); copyMetadataForLoad(*NewI, *LT); - IC.InsertNewInstWith(NewI, *LT); + IC.InsertNewInstWith(NewI, LT->getIterator()); IC.replaceInstUsesWith(*LT, NewI); WorkMap[LT] = NewI; } else if (auto *PHI = dyn_cast(I)) { @@ -398,7 +398,7 @@ void PointerReplacer::replace(Instruction *I) { Indices.append(GEP->idx_begin(), GEP->idx_end()); auto *NewI = GetElementPtrInst::Create(GEP->getSourceElementType(), V, Indices); - IC.InsertNewInstWith(NewI, *GEP); + IC.InsertNewInstWith(NewI, GEP->getIterator()); NewI->takeName(GEP); WorkMap[GEP] = NewI; } else if (auto *BC = dyn_cast(I)) { @@ -407,14 +407,14 @@ void PointerReplacer::replace(Instruction *I) { auto *NewT = PointerType::get(BC->getType()->getContext(), V->getType()->getPointerAddressSpace()); auto *NewI = new BitCastInst(V, NewT); - IC.InsertNewInstWith(NewI, *BC); + IC.InsertNewInstWith(NewI, BC->getIterator()); NewI->takeName(BC); WorkMap[BC] = NewI; } else if (auto *SI = dyn_cast(I)) { auto *NewSI = SelectInst::Create( SI->getCondition(), getReplacement(SI->getTrueValue()), getReplacement(SI->getFalseValue()), SI->getName(), nullptr, SI); - IC.InsertNewInstWith(NewSI, *SI); + IC.InsertNewInstWith(NewSI, SI->getIterator()); NewSI->takeName(SI); WorkMap[SI] = NewSI; } else if (auto *MemCpy = dyn_cast(I)) { @@ -449,7 +449,7 @@ void PointerReplacer::replace(Instruction *I) { ASC->getType()->getPointerAddressSpace()) { auto *NewI = new AddrSpaceCastInst(V, ASC->getType(), ""); NewI->takeName(ASC); - IC.InsertNewInstWith(NewI, *ASC); + IC.InsertNewInstWith(NewI, ASC->getIterator()); NewV = NewI; } IC.replaceInstUsesWith(*ASC, NewV); @@ -1006,7 +1006,7 @@ static Instruction *replaceGEPIdxWithZero(InstCombinerImpl &IC, Value *Ptr, Instruction *NewGEPI = GEPI->clone(); NewGEPI->setOperand(Idx, ConstantInt::get(GEPI->getOperand(Idx)->getType(), 0)); - IC.InsertNewInstBefore(NewGEPI, *GEPI); + IC.InsertNewInstBefore(NewGEPI, GEPI->getIterator()); return NewGEPI; } } @@ -1669,7 +1669,7 @@ bool InstCombinerImpl::mergeStoreIntoSuccessor(StoreInst &SI) { Builder.SetInsertPoint(OtherStore); PN->addIncoming(Builder.CreateBitOrPointerCast(MergedVal, PN->getType()), OtherBB); - MergedVal = InsertNewInstBefore(PN, DestBB->front()); + MergedVal = InsertNewInstBefore(PN, DestBB->begin()); PN->setDebugLoc(MergedLoc); } @@ -1678,7 +1678,7 @@ bool InstCombinerImpl::mergeStoreIntoSuccessor(StoreInst &SI) { StoreInst *NewSI = new StoreInst(MergedVal, SI.getOperand(1), SI.isVolatile(), SI.getAlign(), SI.getOrdering(), SI.getSyncScopeID()); - InsertNewInstBefore(NewSI, *BBI); + InsertNewInstBefore(NewSI, BBI); NewSI->setDebugLoc(MergedLoc); NewSI->mergeDIAssignID({&SI, OtherStore}); diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index 2f6aa85062a5..82ade691736f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -248,7 +248,7 @@ bool InstCombinerImpl::foldIntegerTypedPHI(PHINode &PN) { PHINode *NewPtrPHI = PHINode::Create( IntToPtr->getType(), PN.getNumIncomingValues(), PN.getName() + ".ptr"); - InsertNewInstBefore(NewPtrPHI, PN); + InsertNewInstBefore(NewPtrPHI, PN.getIterator()); SmallDenseMap Casts; for (auto Incoming : zip(PN.blocks(), AvailablePtrVals)) { auto *IncomingBB = std::get<0>(Incoming); @@ -285,10 +285,10 @@ bool InstCombinerImpl::foldIntegerTypedPHI(PHINode &PN) { if (isa(IncomingI)) InsertPos = BB->getFirstInsertionPt(); assert(InsertPos != BB->end() && "should have checked above"); - InsertNewInstBefore(CI, *InsertPos); + InsertNewInstBefore(CI, InsertPos); } else { auto *InsertBB = &IncomingBB->getParent()->getEntryBlock(); - InsertNewInstBefore(CI, *InsertBB->getFirstInsertionPt()); + InsertNewInstBefore(CI, InsertBB->getFirstInsertionPt()); } } NewPtrPHI->addIncoming(CI, IncomingBB); @@ -353,7 +353,7 @@ InstCombinerImpl::foldPHIArgInsertValueInstructionIntoPHI(PHINode &PN) { NewOperand->addIncoming( cast(std::get<1>(Incoming))->getOperand(OpIdx), std::get<0>(Incoming)); - InsertNewInstBefore(NewOperand, PN); + InsertNewInstBefore(NewOperand, PN.getIterator()); } // And finally, create `insertvalue` over the newly-formed PHI nodes. @@ -391,7 +391,7 @@ InstCombinerImpl::foldPHIArgExtractValueInstructionIntoPHI(PHINode &PN) { NewAggregateOperand->addIncoming( cast(std::get<1>(Incoming))->getAggregateOperand(), std::get<0>(Incoming)); - InsertNewInstBefore(NewAggregateOperand, PN); + InsertNewInstBefore(NewAggregateOperand, PN.getIterator()); // And finally, create `extractvalue` over the newly-formed PHI nodes. auto *NewEVI = ExtractValueInst::Create(NewAggregateOperand, @@ -450,7 +450,7 @@ Instruction *InstCombinerImpl::foldPHIArgBinOpIntoPHI(PHINode &PN) { NewLHS = PHINode::Create(LHSType, PN.getNumIncomingValues(), FirstInst->getOperand(0)->getName() + ".pn"); NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0)); - InsertNewInstBefore(NewLHS, PN); + InsertNewInstBefore(NewLHS, PN.getIterator()); LHSVal = NewLHS; } @@ -458,7 +458,7 @@ Instruction *InstCombinerImpl::foldPHIArgBinOpIntoPHI(PHINode &PN) { NewRHS = PHINode::Create(RHSType, PN.getNumIncomingValues(), FirstInst->getOperand(1)->getName() + ".pn"); NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0)); - InsertNewInstBefore(NewRHS, PN); + InsertNewInstBefore(NewRHS, PN.getIterator()); RHSVal = NewRHS; } @@ -581,7 +581,7 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) { Value *FirstOp = FirstInst->getOperand(I); PHINode *NewPN = PHINode::Create(FirstOp->getType(), E, FirstOp->getName() + ".pn"); - InsertNewInstBefore(NewPN, PN); + InsertNewInstBefore(NewPN, PN.getIterator()); NewPN->addIncoming(FirstOp, PN.getIncomingBlock(0)); OperandPhis[I] = NewPN; @@ -769,7 +769,7 @@ Instruction *InstCombinerImpl::foldPHIArgLoadIntoPHI(PHINode &PN) { NewLI->setOperand(0, InVal); delete NewPN; } else { - InsertNewInstBefore(NewPN, PN); + InsertNewInstBefore(NewPN, PN.getIterator()); } // If this was a volatile load that we are merging, make sure to loop through @@ -853,7 +853,7 @@ Instruction *InstCombinerImpl::foldPHIArgZextsIntoPHI(PHINode &Phi) { for (unsigned I = 0; I != NumIncomingValues; ++I) NewPhi->addIncoming(NewIncoming[I], Phi.getIncomingBlock(I)); - InsertNewInstBefore(NewPhi, Phi); + InsertNewInstBefore(NewPhi, Phi.getIterator()); return CastInst::CreateZExtOrBitCast(NewPhi, Phi.getType()); } @@ -943,7 +943,7 @@ Instruction *InstCombinerImpl::foldPHIArgOpIntoPHI(PHINode &PN) { PhiVal = InVal; delete NewPN; } else { - InsertNewInstBefore(NewPN, PN); + InsertNewInstBefore(NewPN, PN.getIterator()); PhiVal = NewPN; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 33d370690e71..1fe28486c14a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -876,7 +876,7 @@ static Instruction *foldSelectZeroOrMul(SelectInst &SI, InstCombinerImpl &IC) { auto *FalseValI = cast(FalseVal); auto *FrY = IC.InsertNewInstBefore(new FreezeInst(Y, Y->getName() + ".fr"), - *FalseValI); + FalseValI->getIterator()); IC.replaceOperand(*FalseValI, FalseValI->getOperand(0) == Y ? 0 : 1, FrY); return IC.replaceInstUsesWith(SI, FalseValI); } @@ -3118,7 +3118,7 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { Value *Op1 = IsAnd ? TrueVal : FalseVal; if (isCheckForZeroAndMulWithOverflow(CondVal, Op1, IsAnd, Y)) { auto *FI = new FreezeInst(*Y, (*Y)->getName() + ".fr"); - InsertNewInstBefore(FI, *cast(Y->getUser())); + InsertNewInstBefore(FI, cast(Y->getUser())->getIterator()); replaceUse(*Y, FI); return replaceInstUsesWith(SI, Op1); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 89dad455f015..75f4b2444228 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -709,13 +709,13 @@ static Value *getShiftedValue(Value *V, unsigned NumBits, bool isLeftShift, case Instruction::Mul: { assert(!isLeftShift && "Unexpected shift direction!"); auto *Neg = BinaryOperator::CreateNeg(I->getOperand(0)); - IC.InsertNewInstWith(Neg, *I); + IC.InsertNewInstWith(Neg, I->getIterator()); unsigned TypeWidth = I->getType()->getScalarSizeInBits(); APInt Mask = APInt::getLowBitsSet(TypeWidth, TypeWidth - NumBits); auto *And = BinaryOperator::CreateAnd(Neg, ConstantInt::get(I->getType(), Mask)); And->takeName(I); - return IC.InsertNewInstWith(And, *I); + return IC.InsertNewInstWith(And, I->getIterator()); } } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index f6fbe51cfe28..be005e61a8d2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -286,7 +286,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Instruction *Or = BinaryOperator::CreateOr(I->getOperand(0), I->getOperand(1), I->getName()); - return InsertNewInstWith(Or, *I); + return InsertNewInstWith(Or, I->getIterator()); } // If all of the demanded bits on one side are known, and all of the set @@ -298,7 +298,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Constant *AndC = Constant::getIntegerValue(VTy, ~RHSKnown.One & DemandedMask); Instruction *And = BinaryOperator::CreateAnd(I->getOperand(0), AndC); - return InsertNewInstWith(And, *I); + return InsertNewInstWith(And, I->getIterator()); } // If the RHS is a constant, see if we can change it. Don't alter a -1 @@ -330,11 +330,11 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Constant *AndC = ConstantInt::get(VTy, NewMask & AndRHS->getValue()); Instruction *NewAnd = BinaryOperator::CreateAnd(I->getOperand(0), AndC); - InsertNewInstWith(NewAnd, *I); + InsertNewInstWith(NewAnd, I->getIterator()); Constant *XorC = ConstantInt::get(VTy, NewMask & XorRHS->getValue()); Instruction *NewXor = BinaryOperator::CreateXor(NewAnd, XorC); - return InsertNewInstWith(NewXor, *I); + return InsertNewInstWith(NewXor, I->getIterator()); } } break; @@ -462,7 +462,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, DemandedMask.getActiveBits() <= SrcBitWidth) { // Convert to ZExt cast. CastInst *NewCast = new ZExtInst(I->getOperand(0), VTy, I->getName()); - return InsertNewInstWith(NewCast, *I); + return InsertNewInstWith(NewCast, I->getIterator()); } // If the sign bit of the input is known set or clear, then we know the @@ -586,7 +586,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, if (match(I->getOperand(1), m_APInt(C)) && C->countr_zero() == CTZ) { Constant *ShiftC = ConstantInt::get(VTy, CTZ); Instruction *Shl = BinaryOperator::CreateShl(I->getOperand(0), ShiftC); - return InsertNewInstWith(Shl, *I); + return InsertNewInstWith(Shl, I->getIterator()); } } // For a squared value "X * X", the bottom 2 bits are 0 and X[0] because: @@ -595,7 +595,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, if (I->getOperand(0) == I->getOperand(1) && DemandedMask.ult(4)) { Constant *One = ConstantInt::get(VTy, 1); Instruction *And1 = BinaryOperator::CreateAnd(I->getOperand(0), One); - return InsertNewInstWith(And1, *I); + return InsertNewInstWith(And1, I->getIterator()); } computeKnownBits(I, Known, Depth, CxtI); @@ -627,7 +627,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Constant *NewC = ConstantExpr::getShl(C, LeftShiftAmtC); if (ConstantExpr::getLShr(NewC, LeftShiftAmtC) == C) { Instruction *Lshr = BinaryOperator::CreateLShr(NewC, X); - return InsertNewInstWith(Lshr, *I); + return InsertNewInstWith(Lshr, I->getIterator()); } } @@ -691,7 +691,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Constant *NewC = ConstantExpr::getLShr(C, RightShiftAmtC); if (ConstantExpr::getShl(NewC, RightShiftAmtC) == C) { Instruction *Shl = BinaryOperator::CreateShl(NewC, X); - return InsertNewInstWith(Shl, *I); + return InsertNewInstWith(Shl, I->getIterator()); } } } @@ -733,7 +733,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // Perform the logical shift right. Instruction *NewVal = BinaryOperator::CreateLShr( I->getOperand(0), I->getOperand(1), I->getName()); - return InsertNewInstWith(NewVal, *I); + return InsertNewInstWith(NewVal, I->getIterator()); } const APInt *SA; @@ -770,7 +770,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, BinaryOperator *LShr = BinaryOperator::CreateLShr(I->getOperand(0), I->getOperand(1)); LShr->setIsExact(cast(I)->isExact()); - return InsertNewInstWith(LShr, *I); + return InsertNewInstWith(LShr, I->getIterator()); } else if (Known.One[BitWidth-ShiftAmt-1]) { // New bits are known one. Known.One |= HighBits; } @@ -867,7 +867,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, match(II->getArgOperand(0), m_Not(m_Value(X)))) { Function *Ctpop = Intrinsic::getDeclaration( II->getModule(), Intrinsic::ctpop, VTy); - return InsertNewInstWith(CallInst::Create(Ctpop, {X}), *I); + return InsertNewInstWith(CallInst::Create(Ctpop, {X}), I->getIterator()); } break; } @@ -894,7 +894,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, NewVal = BinaryOperator::CreateShl( II->getArgOperand(0), ConstantInt::get(VTy, NTZ - NLZ)); NewVal->takeName(I); - return InsertNewInstWith(NewVal, *I); + return InsertNewInstWith(NewVal, I->getIterator()); } break; } @@ -1219,7 +1219,7 @@ Value *InstCombinerImpl::simplifyShrShlDemandedBits( New->setIsExact(true); } - return InsertNewInstWith(New, *Shl); + return InsertNewInstWith(New, Shl->getIterator()); } return nullptr; @@ -1549,7 +1549,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V, Instruction *New = InsertElementInst::Create( Op, Value, ConstantInt::get(Type::getInt64Ty(I->getContext()), Idx), Shuffle->getName()); - InsertNewInstWith(New, *Shuffle); + InsertNewInstWith(New, Shuffle->getIterator()); return New; } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index ce370a5e4ef4..7a5c157ccf1f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -132,7 +132,7 @@ Instruction *InstCombinerImpl::scalarizePHI(ExtractElementInst &EI, // Create a scalar PHI node that will replace the vector PHI node // just before the current PHI node. PHINode *scalarPHI = cast(InsertNewInstWith( - PHINode::Create(EI.getType(), PN->getNumIncomingValues(), ""), *PN)); + PHINode::Create(EI.getType(), PN->getNumIncomingValues(), ""), PN->getIterator())); // Scalarize each PHI operand. for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) { Value *PHIInVal = PN->getIncomingValue(i); @@ -148,10 +148,10 @@ Instruction *InstCombinerImpl::scalarizePHI(ExtractElementInst &EI, Value *Op = InsertNewInstWith( ExtractElementInst::Create(B0->getOperand(opId), Elt, B0->getOperand(opId)->getName() + ".Elt"), - *B0); + B0->getIterator()); Value *newPHIUser = InsertNewInstWith( BinaryOperator::CreateWithCopiedFlags(B0->getOpcode(), - scalarPHI, Op, B0), *B0); + scalarPHI, Op, B0), B0->getIterator()); scalarPHI->addIncoming(newPHIUser, inBB); } else { // Scalarize PHI input: @@ -165,7 +165,7 @@ Instruction *InstCombinerImpl::scalarizePHI(ExtractElementInst &EI, InsertPos = inBB->getFirstInsertionPt(); } - InsertNewInstWith(newEI, *InsertPos); + InsertNewInstWith(newEI, InsertPos); scalarPHI->addIncoming(newEI, inBB); } @@ -742,7 +742,7 @@ static bool replaceExtractElements(InsertElementInst *InsElt, if (ExtVecOpInst && !isa(ExtVecOpInst)) WideVec->insertAfter(ExtVecOpInst); else - IC.InsertNewInstWith(WideVec, *ExtElt->getParent()->getFirstInsertionPt()); + IC.InsertNewInstWith(WideVec, ExtElt->getParent()->getFirstInsertionPt()); // Replace extracts from the original narrow vector with extracts from the new // wide vector. @@ -751,7 +751,7 @@ static bool replaceExtractElements(InsertElementInst *InsElt, if (!OldExt || OldExt->getParent() != WideVec->getParent()) continue; auto *NewExt = ExtractElementInst::Create(WideVec, OldExt->getOperand(1)); - IC.InsertNewInstWith(NewExt, *OldExt); + IC.InsertNewInstWith(NewExt, OldExt->getIterator()); IC.replaceInstUsesWith(*OldExt, NewExt); // Add the old extracts to the worklist for DCE. We can't remove the // extracts directly, because they may still be used by the calling code. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index f4c6cb5b4610..1b9943f7025e 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -549,7 +549,7 @@ bool InstCombinerImpl::SimplifyAssociativeOrCommutative(BinaryOperator &I) { Op1->getFastMathFlags(); NewBO->setFastMathFlags(Flags); } - InsertNewInstWith(NewBO, I); + InsertNewInstWith(NewBO, I.getIterator()); NewBO->takeName(Op1); replaceOperand(I, 0, NewBO); replaceOperand(I, 1, CRes); @@ -1295,7 +1295,7 @@ static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI, Value *NewOp, InstCombiner &IC) { Instruction *Clone = I.clone(); Clone->replaceUsesOfWith(SI, NewOp); - IC.InsertNewInstBefore(Clone, *SI); + IC.InsertNewInstBefore(Clone, SI->getIterator()); return Clone; } @@ -1467,7 +1467,7 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) { // Okay, we can do the transformation: create the new PHI node. PHINode *NewPN = PHINode::Create(I.getType(), PN->getNumIncomingValues()); - InsertNewInstBefore(NewPN, *PN); + InsertNewInstBefore(NewPN, PN->getIterator()); NewPN->takeName(PN); NewPN->setDebugLoc(PN->getDebugLoc()); @@ -1482,7 +1482,7 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) { else U = U->DoPHITranslation(PN->getParent(), NonSimplifiedBB); } - InsertNewInstBefore(Clone, *NonSimplifiedBB->getTerminator()); + InsertNewInstBefore(Clone, NonSimplifiedBB->getTerminator()->getIterator()); } for (unsigned i = 0; i != NumPHIValues; ++i) { @@ -2286,7 +2286,7 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { NewGEP->setOperand(DI, NewPN); } - NewGEP->insertInto(GEP.getParent(), GEP.getParent()->getFirstInsertionPt()); + NewGEP->insertBefore(*GEP.getParent(), GEP.getParent()->getFirstInsertionPt()); return replaceOperand(GEP, 0, NewGEP); } -- 2.11.4.GIT