@@ -126,6 +126,9 @@ CloneInstructionInExitBlock(Instruction &I, BasicBlock &ExitBlock, PHINode &PN,
126
126
static void eraseInstruction (Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
127
127
AliasSetTracker *AST);
128
128
129
+ static void moveInstructionBefore (Instruction &I, Instruction &Dest,
130
+ ICFLoopSafetyInfo &SafetyInfo);
131
+
129
132
namespace {
130
133
struct LoopInvariantCodeMotion {
131
134
using ASTrackerMapTy = DenseMap<Loop *, std::unique_ptr<AliasSetTracker>>;
@@ -890,6 +893,13 @@ static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
890
893
I.eraseFromParent ();
891
894
}
892
895
896
+ static void moveInstructionBefore (Instruction &I, Instruction &Dest,
897
+ ICFLoopSafetyInfo &SafetyInfo) {
898
+ SafetyInfo.removeInstruction (&I);
899
+ SafetyInfo.insertInstructionTo (Dest.getParent ());
900
+ I.moveBefore (&Dest);
901
+ }
902
+
893
903
static Instruction *sinkThroughTriviallyReplaceablePHI (
894
904
PHINode *TPN, Instruction *I, LoopInfo *LI,
895
905
SmallDenseMap<BasicBlock *, Instruction *, 32 > &SunkCopies,
@@ -1118,10 +1128,8 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
1118
1128
!SafetyInfo->isGuaranteedToExecute (I, DT, CurLoop))
1119
1129
I.dropUnknownNonDebugMetadata ();
1120
1130
1121
- SafetyInfo->removeInstruction (&I);
1122
- SafetyInfo->insertInstructionTo (Preheader);
1123
1131
// Move the new node to the Preheader, before its terminator.
1124
- I. moveBefore ( Preheader->getTerminator ());
1132
+ moveInstructionBefore (I, * Preheader->getTerminator (), *SafetyInfo );
1125
1133
1126
1134
// Do not retain debug locations when we are moving instructions to different
1127
1135
// basic blocks, because we want to avoid jumpy line tables. Calls, however,
0 commit comments