summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/Instruction.h4
-rw-r--r--llvm/lib/CodeGen/AtomicExpandPass.cpp10
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp9
-rw-r--r--llvm/lib/IR/Instruction.cpp4
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp3
5 files changed, 14 insertions, 16 deletions
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 8dc02111b86..0cf8003423f 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -113,6 +113,10 @@ public:
/// \pre I is a valid iterator into BB.
void moveBefore(BasicBlock &BB, SymbolTableList<Instruction>::iterator I);
+ /// Unlink this instruction from its current basic block and insert it into
+ /// the basic block that MovePos lives in, right after MovePos.
+ void moveAfter(Instruction *MovePos);
+
//===--------------------------------------------------------------------===//
// Subclass classification.
//===--------------------------------------------------------------------===//
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index aa9c8e94d08..9d1f94a8a43 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -320,16 +320,10 @@ bool AtomicExpand::bracketInstWithFences(Instruction *I, AtomicOrdering Order) {
auto LeadingFence = TLI->emitLeadingFence(Builder, I, Order);
auto TrailingFence = TLI->emitTrailingFence(Builder, I, Order);
- // The trailing fence is emitted before the instruction instead of after
- // because there is no easy way of setting Builder insertion point after
- // an instruction. So we must erase it from the BB, and insert it back
- // in the right place.
// We have a guard here because not every atomic operation generates a
// trailing fence.
- if (TrailingFence) {
- TrailingFence->removeFromParent();
- TrailingFence->insertAfter(I);
- }
+ if (TrailingFence)
+ TrailingFence->moveAfter(I);
return (LeadingFence || TrailingFence);
}
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 03ef8985210..1250d025fbc 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -3586,9 +3586,8 @@ Value *TypePromotionHelper::promoteOperandForOther(
// Create the truncate now.
Value *Trunc = TPT.createTrunc(Ext, ExtOpnd->getType());
if (Instruction *ITrunc = dyn_cast<Instruction>(Trunc)) {
- ITrunc->removeFromParent();
// Insert it just after the definition.
- ITrunc->insertAfter(ExtOpnd);
+ ITrunc->moveAfter(ExtOpnd);
if (Truncs)
Truncs->push_back(ITrunc);
}
@@ -4943,8 +4942,7 @@ bool CodeGenPrepare::optimizeExt(Instruction *&Inst) {
assert(LI && ExtFedByLoad && "Expect a valid load and extension");
TPT.commit();
// Move the extend into the same block as the load
- ExtFedByLoad->removeFromParent();
- ExtFedByLoad->insertAfter(LI);
+ ExtFedByLoad->moveAfter(LI);
// CGP does not check if the zext would be speculatively executed when moved
// to the same basic block as the load. Preserving its original location
// would pessimize the debugging experience, as well as negatively impact
@@ -5936,8 +5934,7 @@ void VectorPromoteHelper::promoteImpl(Instruction *ToBePromoted) {
"this?");
ToBePromoted->setOperand(U.getOperandNo(), NewVal);
}
- Transition->removeFromParent();
- Transition->insertAfter(ToBePromoted);
+ Transition->moveAfter(ToBePromoted);
Transition->setOperand(getTransitionOriginalValueIdx(), ToBePromoted);
}
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 365cb019aec..ceb521c4c48 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -89,6 +89,10 @@ void Instruction::moveBefore(Instruction *MovePos) {
moveBefore(*MovePos->getParent(), MovePos->getIterator());
}
+void Instruction::moveAfter(Instruction *MovePos) {
+ moveBefore(*MovePos->getParent(), ++MovePos->getIterator());
+}
+
void Instruction::moveBefore(BasicBlock &BB,
SymbolTableList<Instruction>::iterator I) {
assert(I == BB.end() || I->getParent() == &BB);
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d8da03ae2a9..1f530cbb5d2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4467,8 +4467,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
cast<Instruction>(Builder.CreateExtractElement(
VectorizedRoot, Builder.getInt32(VecIdx++)));
I->setOperand(1, Extract);
- I->removeFromParent();
- I->insertAfter(Extract);
+ I->moveAfter(Extract);
InsertAfter = I;
}
}
OpenPOWER on IntegriCloud