Skip to content

Commit 6942c64

Browse files
committed
[NFC][RemoveDIs] Prefer iterator-insertion over instructions
Continuing the patch series to get rid of debug intrinsics [0], instruction insertion needs to be done with iterators rather than instruction pointers, so that we can communicate information in the iterator class. This patch adds an iterator-taking insertBefore method and converts various call sites to take iterators. These are all sites where such debug-info needs to be preserved so that a stage2 clang can be built identically; it's likely that many more will need to be changed in the future. At this stage, this is just changing the spelling of a few operations, which will eventually become signifiant once the debug-info bearing iterator is used. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939 Differential Revision: https://reviews.llvm.org/D152537
1 parent 3787fd9 commit 6942c64

36 files changed

+159
-109
lines changed

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
173173
static_cast<const BasicBlock *>(this)->getFirstNonPHI());
174174
}
175175

176+
/// Iterator returning form of getFirstNonPHI. Installed as a placeholder for
177+
/// the RemoveDIs project that will eventually remove debug intrinsics.
178+
InstListType::const_iterator getFirstNonPHIIt() const;
179+
InstListType::iterator getFirstNonPHIIt() {
180+
BasicBlock::iterator It =
181+
static_cast<const BasicBlock *>(this)->getFirstNonPHIIt().getNonConst();
182+
return It;
183+
}
184+
176185
/// Returns a pointer to the first instruction in this block that is not a
177186
/// PHINode or a debug intrinsic, or any pseudo operation if \c SkipPseudoOp
178187
/// is true.

llvm/include/llvm/IR/Instruction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class Instruction : public User,
123123
/// Insert an unlinked instruction into a basic block immediately before
124124
/// the specified instruction.
125125
void insertBefore(Instruction *InsertPos);
126+
void insertBefore(SymbolTableList<Instruction>::iterator InsertPos) {
127+
insertBefore(&*InsertPos);
128+
}
126129

127130
/// Insert an unlinked instruction into a basic block immediately after the
128131
/// specified instruction.
@@ -133,6 +136,11 @@ class Instruction : public User,
133136
SymbolTableList<Instruction>::iterator
134137
insertInto(BasicBlock *ParentBB, SymbolTableList<Instruction>::iterator It);
135138

139+
void insertBefore(BasicBlock &BB,
140+
SymbolTableList<Instruction>::iterator InsertPos) {
141+
insertInto(&BB, InsertPos);
142+
}
143+
136144
/// Unlink this instruction from its current basic block and insert it into
137145
/// the basic block that MovePos lives in, right before MovePos.
138146
void moveBefore(Instruction *MovePos);

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7097,7 +7097,8 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
70977097
// to get the PHI operand.
70987098
for (SelectInst *SI : llvm::reverse(ASI)) {
70997099
// The select itself is replaced with a PHI Node.
7100-
PHINode *PN = PHINode::Create(SI->getType(), 2, "", &EndBlock->front());
7100+
PHINode *PN = PHINode::Create(SI->getType(), 2, "");
7101+
PN->insertBefore(EndBlock->begin());
71017102
PN->takeName(SI);
71027103
PN->addIncoming(getTrueOrFalseValue(SI, true, INS), TrueBlock);
71037104
PN->addIncoming(getTrueOrFalseValue(SI, false, INS), FalseBlock);

llvm/lib/CodeGen/SelectOptimize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ void SelectOptimize::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
505505
for (auto It = ASI.rbegin(); It != ASI.rend(); ++It) {
506506
SelectInst *SI = *It;
507507
// The select itself is replaced with a PHI Node.
508-
PHINode *PN = PHINode::Create(SI->getType(), 2, "", &EndBlock->front());
508+
PHINode *PN = PHINode::Create(SI->getType(), 2, "");
509+
PN->insertBefore(EndBlock->begin());
509510
PN->takeName(SI);
510511
PN->addIncoming(getTrueOrFalseValue(SI, true, INS), TrueBlock);
511512
PN->addIncoming(getTrueOrFalseValue(SI, false, INS), FalseBlock);

llvm/lib/IR/BasicBlock.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ const Instruction* BasicBlock::getFirstNonPHI() const {
220220
return nullptr;
221221
}
222222

223+
BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const {
224+
return getFirstNonPHI()->getIterator();
225+
}
226+
223227
const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
224228
for (const Instruction &I : *this) {
225229
if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))

llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ bool SIAnnotateControlFlow::handleLoop(BranchInst *Term) {
268268
return false;
269269

270270
BasicBlock *Target = Term->getSuccessor(1);
271-
PHINode *Broken = PHINode::Create(IntMask, 0, "phi.broken", &Target->front());
271+
PHINode *Broken = PHINode::Create(IntMask, 0, "phi.broken");
272+
Broken->insertBefore(Target->begin());
272273

273274
Value *Cond = Term->getCondition();
274275
Term->setCondition(BoolTrue);

llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,8 @@ PPCLoopInstrFormPrep::rewriteForBase(Loop *L, const SCEVAddRecExpr *BasePtrSCEV,
707707
BasicBlock *LoopPredecessor = L->getLoopPredecessor();
708708

709709
PHINode *NewPHI = PHINode::Create(I8PtrTy, HeaderLoopPredCount,
710-
getInstrName(BaseMemI, PHINodeNameSuffix),
711-
Header->getFirstNonPHI());
710+
getInstrName(BaseMemI, PHINodeNameSuffix));
711+
NewPHI->insertBefore(Header->getFirstNonPHIIt());
712712

713713
Value *BasePtrStart = SCEVE.expandCodeFor(BasePtrStartSCEV, I8PtrTy,
714714
LoopPredecessor->getTerminator());

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,8 +2051,8 @@ static void movePHIValuesToInsertedBlock(BasicBlock *SuccBB,
20512051
int Index = PN->getBasicBlockIndex(InsertedBB);
20522052
Value *V = PN->getIncomingValue(Index);
20532053
PHINode *InputV = PHINode::Create(
2054-
V->getType(), 1, V->getName() + Twine(".") + SuccBB->getName(),
2055-
&InsertedBB->front());
2054+
V->getType(), 1, V->getName() + Twine(".") + SuccBB->getName());
2055+
InputV->insertBefore(InsertedBB->begin());
20562056
InputV->addIncoming(V, PredBB);
20572057
PN->setIncomingValue(Index, InputV);
20582058
PN = dyn_cast<PHINode>(PN->getNextNode());
@@ -2198,7 +2198,8 @@ static void rewritePHIs(BasicBlock &BB) {
21982198
// ehAwareSplitEdge will clone the LandingPad in all the edge blocks.
21992199
// We replace the original landing pad with a PHINode that will collect the
22002200
// results from all of them.
2201-
ReplPHI = PHINode::Create(LandingPad->getType(), 1, "", LandingPad);
2201+
ReplPHI = PHINode::Create(LandingPad->getType(), 1, "");
2202+
ReplPHI->insertBefore(LandingPad->getIterator());
22022203
ReplPHI->takeName(LandingPad);
22032204
LandingPad->replaceAllUsesWith(ReplPHI);
22042205
// We will erase the original landing pad at the end of this function after

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ static void createResumeEntryBlock(Function &F, coro::Shape &Shape) {
457457
Switch->addCase(IndexVal, ResumeBB);
458458

459459
cast<BranchInst>(SuspendBB->getTerminator())->setSuccessor(0, LandingBB);
460-
auto *PN = PHINode::Create(Builder.getInt8Ty(), 2, "", &LandingBB->front());
460+
auto *PN = PHINode::Create(Builder.getInt8Ty(), 2, "");
461+
PN->insertBefore(LandingBB->begin());
461462
S->replaceAllUsesWith(PN);
462463
PN->addIncoming(Builder.getInt8(-1), SuspendBB);
463464
PN->addIncoming(S, ResumeBB);

llvm/lib/Transforms/IPO/PartialInlining.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,17 +1042,18 @@ void PartialInlinerImpl::FunctionCloner::normalizeReturnBlock() const {
10421042
ClonedOI->ReturnBlock = ClonedOI->ReturnBlock->splitBasicBlock(
10431043
ClonedOI->ReturnBlock->getFirstNonPHI()->getIterator());
10441044
BasicBlock::iterator I = PreReturn->begin();
1045-
Instruction *Ins = &ClonedOI->ReturnBlock->front();
1045+
BasicBlock::iterator Ins = ClonedOI->ReturnBlock->begin();
10461046
SmallVector<Instruction *, 4> DeadPhis;
10471047
while (I != PreReturn->end()) {
10481048
PHINode *OldPhi = dyn_cast<PHINode>(I);
10491049
if (!OldPhi)
10501050
break;
10511051

10521052
PHINode *RetPhi =
1053-
PHINode::Create(OldPhi->getType(), NumPredsFromEntries + 1, "", Ins);
1053+
PHINode::Create(OldPhi->getType(), NumPredsFromEntries + 1, "");
1054+
RetPhi->insertBefore(Ins);
10541055
OldPhi->replaceAllUsesWith(RetPhi);
1055-
Ins = ClonedOI->ReturnBlock->getFirstNonPHI();
1056+
Ins = ClonedOI->ReturnBlock->getFirstNonPHIIt();
10561057

10571058
RetPhi->addIncoming(&*I, PreReturn);
10581059
for (BasicBlock *E : ClonedOI->ReturnBlockPreds) {

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,7 +3680,7 @@ bool InstCombinerImpl::freezeOtherUses(FreezeInst &FI) {
36803680

36813681
bool Changed = false;
36823682
if (&FI != MoveBefore) {
3683-
FI.moveBefore(MoveBefore);
3683+
FI.moveBefore(*MoveBefore->getParent(), MoveBefore->getIterator());
36843684
Changed = true;
36853685
}
36863686

@@ -3883,7 +3883,7 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
38833883
/// the new position.
38843884

38853885
BasicBlock::iterator InsertPos = DestBlock->getFirstInsertionPt();
3886-
I->moveBefore(&*InsertPos);
3886+
I->moveBefore(*DestBlock, InsertPos);
38873887
++NumSunkInst;
38883888

38893889
// Also sink all related debug uses from the source basic block. Otherwise we

llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ static void insertTrivialPHIs(CHRScope *Scope,
15931593
// Insert a trivial phi for I (phi [&I, P0], [&I, P1], ...) at
15941594
// ExitBlock. Replace I with the new phi in UI unless UI is another
15951595
// phi at ExitBlock.
1596-
PHINode *PN = PHINode::Create(I.getType(), pred_size(ExitBlock), "",
1597-
&ExitBlock->front());
1596+
PHINode *PN = PHINode::Create(I.getType(), pred_size(ExitBlock), "");
1597+
PN->insertBefore(ExitBlock->begin());
15981598
for (BasicBlock *Pred : predecessors(ExitBlock)) {
15991599
PN->addIncoming(&I, Pred);
16001600
}

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,9 +2987,9 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
29872987
++NumGVNPRE;
29882988

29892989
// Create a PHI to make the value available in this block.
2990-
PHINode *Phi =
2991-
PHINode::Create(CurInst->getType(), predMap.size(),
2992-
CurInst->getName() + ".pre-phi", &CurrentBlock->front());
2990+
PHINode *Phi = PHINode::Create(CurInst->getType(), predMap.size(),
2991+
CurInst->getName() + ".pre-phi");
2992+
Phi->insertBefore(CurrentBlock->begin());
29932993
for (unsigned i = 0, e = predMap.size(); i != e; ++i) {
29942994
if (Value *V = predMap[i].first) {
29952995
// If we use an existing value in this phi, we have to patch the original

llvm/lib/Transforms/Scalar/GVNSink.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,9 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks,
850850
// Create a new PHI in the successor block and populate it.
851851
auto *Op = I0->getOperand(O);
852852
assert(!Op->getType()->isTokenTy() && "Can't PHI tokens!");
853-
auto *PN = PHINode::Create(Op->getType(), Insts.size(),
854-
Op->getName() + ".sink", &BBEnd->front());
853+
auto *PN =
854+
PHINode::Create(Op->getType(), Insts.size(), Op->getName() + ".sink");
855+
PN->insertBefore(BBEnd->begin());
855856
for (auto *I : Insts)
856857
PN->addIncoming(I->getOperand(O), I->getParent());
857858
NewOperands.push_back(PN);

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,8 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
14331433

14341434
// Create a PHI node at the start of the block for the PRE'd load value.
14351435
pred_iterator PB = pred_begin(LoadBB), PE = pred_end(LoadBB);
1436-
PHINode *PN = PHINode::Create(LoadI->getType(), std::distance(PB, PE), "",
1437-
&LoadBB->front());
1436+
PHINode *PN = PHINode::Create(LoadI->getType(), std::distance(PB, PE), "");
1437+
PN->insertBefore(LoadBB->begin());
14381438
PN->takeName(LoadI);
14391439
PN->setDebugLoc(LoadI->getDebugLoc());
14401440

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,8 +1489,9 @@ static Instruction *cloneInstructionInExitBlock(
14891489
if (LI->wouldBeOutOfLoopUseRequiringLCSSA(Op.get(), PN.getParent())) {
14901490
auto *OInst = cast<Instruction>(Op.get());
14911491
PHINode *OpPN =
1492-
PHINode::Create(OInst->getType(), PN.getNumIncomingValues(),
1493-
OInst->getName() + ".lcssa", &ExitBlock.front());
1492+
PHINode::Create(OInst->getType(), PN.getNumIncomingValues(),
1493+
OInst->getName() + ".lcssa");
1494+
OpPN->insertBefore(ExitBlock.begin());
14941495
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
14951496
OpPN->addIncoming(OInst, PN.getIncomingBlock(i));
14961497
Op = OpPN;
@@ -1832,7 +1833,8 @@ class LoopPromoter : public LoadAndStorePromoter {
18321833
// We need to create an LCSSA PHI node for the incoming value and
18331834
// store that.
18341835
PHINode *PN = PHINode::Create(I->getType(), PredCache.size(BB),
1835-
I->getName() + ".lcssa", &BB->front());
1836+
I->getName() + ".lcssa");
1837+
PN->insertBefore(BB->begin());
18361838
for (BasicBlock *Pred : PredCache.get(BB))
18371839
PN->addIncoming(I, Pred);
18381840
return PN;

llvm/lib/Transforms/Scalar/LoopFuse.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,13 @@ struct LoopFuser {
14731473

14741474
for (Instruction *I : HoistInsts) {
14751475
assert(I->getParent() == FC1.Preheader);
1476-
I->moveBefore(FC0.Preheader->getTerminator());
1476+
I->moveBefore(*FC0.Preheader,
1477+
FC0.Preheader->getTerminator()->getIterator());
14771478
}
14781479
// insert instructions in reverse order to maintain dominance relationship
14791480
for (Instruction *I : reverse(SinkInsts)) {
14801481
assert(I->getParent() == FC1.Preheader);
1481-
I->moveBefore(&*FC1.ExitBlock->getFirstInsertionPt());
1482+
I->moveBefore(*FC1.ExitBlock, FC1.ExitBlock->getFirstInsertionPt());
14821483
}
14831484
}
14841485

@@ -1671,16 +1672,17 @@ struct LoopFuser {
16711672
// exiting the first and jumping to the header of the second does not break
16721673
// the SSA property of the phis originally in the first loop. See also the
16731674
// comment above.
1674-
Instruction *L1HeaderIP = &FC1.Header->front();
1675+
BasicBlock::iterator L1HeaderIP = FC1.Header->begin();
16751676
for (PHINode *LCPHI : OriginalFC0PHIs) {
16761677
int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
16771678
assert(L1LatchBBIdx >= 0 &&
16781679
"Expected loop carried value to be rewired at this point!");
16791680

16801681
Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
16811682

1682-
PHINode *L1HeaderPHI = PHINode::Create(
1683-
LCV->getType(), 2, LCPHI->getName() + ".afterFC0", L1HeaderIP);
1683+
PHINode *L1HeaderPHI =
1684+
PHINode::Create(LCV->getType(), 2, LCPHI->getName() + ".afterFC0");
1685+
L1HeaderPHI->insertBefore(L1HeaderIP);
16841686
L1HeaderPHI->addIncoming(LCV, FC0.Latch);
16851687
L1HeaderPHI->addIncoming(UndefValue::get(LCV->getType()),
16861688
FC0.ExitingBlock);
@@ -1953,16 +1955,17 @@ struct LoopFuser {
19531955
// exiting the first and jumping to the header of the second does not break
19541956
// the SSA property of the phis originally in the first loop. See also the
19551957
// comment above.
1956-
Instruction *L1HeaderIP = &FC1.Header->front();
1958+
BasicBlock::iterator L1HeaderIP = FC1.Header->begin();
19571959
for (PHINode *LCPHI : OriginalFC0PHIs) {
19581960
int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
19591961
assert(L1LatchBBIdx >= 0 &&
19601962
"Expected loop carried value to be rewired at this point!");
19611963

19621964
Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
19631965

1964-
PHINode *L1HeaderPHI = PHINode::Create(
1965-
LCV->getType(), 2, LCPHI->getName() + ".afterFC0", L1HeaderIP);
1966+
PHINode *L1HeaderPHI =
1967+
PHINode::Create(LCV->getType(), 2, LCPHI->getName() + ".afterFC0");
1968+
L1HeaderPHI->insertBefore(L1HeaderIP);
19661969
L1HeaderPHI->addIncoming(LCV, FC0.Latch);
19671970
L1HeaderPHI->addIncoming(UndefValue::get(LCV->getType()),
19681971
FC0.ExitingBlock);

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,8 @@ void LoopIdiomRecognize::transformLoopToCountable(
20262026
auto *LbBr = cast<BranchInst>(Body->getTerminator());
20272027
ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
20282028

2029-
PHINode *TcPhi = PHINode::Create(CountTy, 2, "tcphi", &Body->front());
2029+
PHINode *TcPhi = PHINode::Create(CountTy, 2, "tcphi");
2030+
TcPhi->insertBefore(Body->begin());
20302031

20312032
Builder.SetInsertPoint(LbCond);
20322033
Instruction *TcDec = cast<Instruction>(Builder.CreateSub(
@@ -2132,7 +2133,8 @@ void LoopIdiomRecognize::transformLoopToPopcount(BasicBlock *PreCondBB,
21322133
ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
21332134
Type *Ty = TripCnt->getType();
21342135

2135-
PHINode *TcPhi = PHINode::Create(Ty, 2, "tcphi", &Body->front());
2136+
PHINode *TcPhi = PHINode::Create(Ty, 2, "tcphi");
2137+
TcPhi->insertBefore(Body->begin());
21362138

21372139
Builder.SetInsertPoint(LbCond);
21382140
Instruction *TcDec = cast<Instruction>(

llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ class LoadEliminationForLoop {
443443
Cand.Load->getType(), InitialPtr, "load_initial",
444444
/* isVolatile */ false, Cand.Load->getAlign(), PH->getTerminator());
445445

446-
PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded",
447-
&L->getHeader()->front());
446+
PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded");
447+
PHI->insertBefore(L->getHeader()->begin());
448448
PHI->addIncoming(Initial, PH);
449449

450450
Type *LoadType = Initial->getType();

llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
217217
if (Opd1 == Opd2)
218218
return nullptr;
219219

220-
auto *NewPN = PHINode::Create(Opd1->getType(), 2, Opd2->getName() + ".sink",
221-
&BB->front());
220+
auto *NewPN = PHINode::Create(Opd1->getType(), 2, Opd2->getName() + ".sink");
221+
NewPN->insertBefore(BB->begin());
222222
NewPN->applyMergedLocation(S0->getDebugLoc(), S1->getDebugLoc());
223223
NewPN->addIncoming(Opd1, S0->getParent());
224224
NewPN->addIncoming(Opd2, S1->getParent());
@@ -269,7 +269,7 @@ void MergedLoadStoreMotion::sinkStoresAndGEPs(BasicBlock *BB, StoreInst *S0,
269269

270270
// Create the new store to be inserted at the join point.
271271
StoreInst *SNew = cast<StoreInst>(S0->clone());
272-
SNew->insertBefore(&*InsertPt);
272+
SNew->insertBefore(InsertPt);
273273
// New PHI operand? Use it.
274274
if (PHINode *NewPN = getPHIOperand(BB, S0, S1))
275275
SNew->setOperand(0, NewPN);

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ static void rewritePHINodesForExitAndUnswitchedBlocks(BasicBlock &ExitBB,
368368
bool FullUnswitch) {
369369
assert(&ExitBB != &UnswitchedBB &&
370370
"Must have different loop exit and unswitched blocks!");
371-
Instruction *InsertPt = &*UnswitchedBB.begin();
371+
BasicBlock::iterator InsertPt = UnswitchedBB.begin();
372372
for (PHINode &PN : ExitBB.phis()) {
373373
auto *NewPN = PHINode::Create(PN.getType(), /*NumReservedValues*/ 2,
374-
PN.getName() + ".split", InsertPt);
374+
PN.getName() + ".split");
375+
NewPN->insertBefore(InsertPt);
375376

376377
// Walk backwards over the old PHI node's inputs to minimize the cost of
377378
// removing each one. We have to do this weird loop manually so that we
@@ -623,7 +624,7 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
623624
// If fully unswitching, we can use the existing branch instruction.
624625
// Splice it into the old PH to gate reaching the new preheader and re-point
625626
// its successors.
626-
OldPH->splice(OldPH->end(), BI.getParent(), BI.getIterator());
627+
BI.moveBefore(*OldPH, OldPH->end());
627628
BI.setCondition(Cond);
628629
if (MSSAU) {
629630
// Temporarily clone the terminator, to make MSSA update cheaper by
@@ -1246,8 +1247,8 @@ static BasicBlock *buildClonedLoopBlocks(
12461247
SE->forgetValue(&I);
12471248

12481249
auto *MergePN =
1249-
PHINode::Create(I.getType(), /*NumReservedValues*/ 2, ".us-phi",
1250-
&*MergeBB->getFirstInsertionPt());
1250+
PHINode::Create(I.getType(), /*NumReservedValues*/ 2, ".us-phi");
1251+
MergePN->insertBefore(MergeBB->getFirstInsertionPt());
12511252
I.replaceAllUsesWith(MergePN);
12521253
MergePN->addIncoming(&I, ExitBB);
12531254
MergePN->addIncoming(&ClonedI, ClonedExitBB);
@@ -2295,7 +2296,7 @@ static void unswitchNontrivialInvariants(
22952296
if (FullUnswitch) {
22962297
// Splice the terminator from the original loop and rewrite its
22972298
// successors.
2298-
SplitBB->splice(SplitBB->end(), ParentBB, TI.getIterator());
2299+
TI.moveBefore(*SplitBB, SplitBB->end());
22992300

23002301
// Keep a clone of the terminator for MSSA updates.
23012302
Instruction *NewTI = TI.clone();

0 commit comments

Comments
 (0)