@@ -137,7 +137,8 @@ static bool isNotUsedOrFreeInLoop(const Instruction &I, const Loop *CurLoop,
137
137
TargetTransformInfo *TTI, bool &FreeInLoop);
138
138
static void hoist (Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
139
139
BasicBlock *Dest, ICFLoopSafetyInfo *SafetyInfo,
140
- MemorySSAUpdater *MSSAU, OptimizationRemarkEmitter *ORE);
140
+ MemorySSAUpdater *MSSAU, ScalarEvolution *SE,
141
+ OptimizationRemarkEmitter *ORE);
141
142
static bool sink (Instruction &I, LoopInfo *LI, DominatorTree *DT,
142
143
const Loop *CurLoop, ICFLoopSafetyInfo *SafetyInfo,
143
144
MemorySSAUpdater *MSSAU, OptimizationRemarkEmitter *ORE);
@@ -162,7 +163,7 @@ static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
162
163
163
164
static void moveInstructionBefore (Instruction &I, Instruction &Dest,
164
165
ICFLoopSafetyInfo &SafetyInfo,
165
- MemorySSAUpdater *MSSAU);
166
+ MemorySSAUpdater *MSSAU, ScalarEvolution *SE );
166
167
167
168
namespace {
168
169
struct LoopInvariantCodeMotion {
@@ -390,8 +391,9 @@ bool LoopInvariantCodeMotion::runOnLoop(
390
391
CurAST.get (), MSSAU.get (), &SafetyInfo, Flags, ORE);
391
392
Flags.IsSink = false ;
392
393
if (Preheader)
393
- Changed |= hoistRegion (DT->getNode (L->getHeader ()), AA, LI, DT, TLI, L,
394
- CurAST.get (), MSSAU.get (), &SafetyInfo, Flags, ORE);
394
+ Changed |=
395
+ hoistRegion (DT->getNode (L->getHeader ()), AA, LI, DT, TLI, L,
396
+ CurAST.get (), MSSAU.get (), SE, &SafetyInfo, Flags, ORE);
395
397
396
398
// Now that all loop invariants have been removed from the loop, promote any
397
399
// memory references to scalars that we can.
@@ -795,7 +797,7 @@ class ControlFlowHoister {
795
797
bool llvm::hoistRegion (DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
796
798
DominatorTree *DT, TargetLibraryInfo *TLI, Loop *CurLoop,
797
799
AliasSetTracker *CurAST, MemorySSAUpdater *MSSAU,
798
- ICFLoopSafetyInfo *SafetyInfo,
800
+ ScalarEvolution *SE, ICFLoopSafetyInfo *SafetyInfo,
799
801
SinkAndHoistLICMFlags &Flags,
800
802
OptimizationRemarkEmitter *ORE) {
801
803
// Verify inputs.
@@ -855,7 +857,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
855
857
I, DT, CurLoop, SafetyInfo, ORE,
856
858
CurLoop->getLoopPreheader ()->getTerminator ())) {
857
859
hoist (I, DT, CurLoop, CFH.getOrCreateHoistedBlock (BB), SafetyInfo,
858
- MSSAU, ORE);
860
+ MSSAU, SE, ORE);
859
861
HoistedInstructions.push_back (&I);
860
862
Changed = true ;
861
863
continue ;
@@ -882,7 +884,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
882
884
eraseInstruction (I, *SafetyInfo, CurAST, MSSAU);
883
885
884
886
hoist (*ReciprocalDivisor, DT, CurLoop, CFH.getOrCreateHoistedBlock (BB),
885
- SafetyInfo, MSSAU, ORE);
887
+ SafetyInfo, MSSAU, SE, ORE);
886
888
HoistedInstructions.push_back (ReciprocalDivisor);
887
889
Changed = true ;
888
890
continue ;
@@ -901,7 +903,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
901
903
CurLoop->hasLoopInvariantOperands (&I) &&
902
904
MustExecuteWithoutWritesBefore (I)) {
903
905
hoist (I, DT, CurLoop, CFH.getOrCreateHoistedBlock (BB), SafetyInfo,
904
- MSSAU, ORE);
906
+ MSSAU, SE, ORE);
905
907
HoistedInstructions.push_back (&I);
906
908
Changed = true ;
907
909
continue ;
@@ -915,7 +917,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
915
917
PN->setIncomingBlock (
916
918
i, CFH.getOrCreateHoistedBlock (PN->getIncomingBlock (i)));
917
919
hoist (*PN, DT, CurLoop, CFH.getOrCreateHoistedBlock (BB), SafetyInfo,
918
- MSSAU, ORE);
920
+ MSSAU, SE, ORE);
919
921
assert (DT->dominates (PN, BB) && " Conditional PHIs not expected" );
920
922
Changed = true ;
921
923
continue ;
@@ -952,7 +954,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
952
954
LLVM_DEBUG (dbgs () << " LICM rehoisting to "
953
955
<< HoistPoint->getParent ()->getName ()
954
956
<< " : " << *I << " \n " );
955
- moveInstructionBefore (*I, *HoistPoint, *SafetyInfo, MSSAU);
957
+ moveInstructionBefore (*I, *HoistPoint, *SafetyInfo, MSSAU, SE );
956
958
HoistPoint = I;
957
959
Changed = true ;
958
960
}
@@ -1441,14 +1443,17 @@ static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
1441
1443
1442
1444
static void moveInstructionBefore (Instruction &I, Instruction &Dest,
1443
1445
ICFLoopSafetyInfo &SafetyInfo,
1444
- MemorySSAUpdater *MSSAU) {
1446
+ MemorySSAUpdater *MSSAU,
1447
+ ScalarEvolution *SE) {
1445
1448
SafetyInfo.removeInstruction (&I);
1446
1449
SafetyInfo.insertInstructionTo (&I, Dest.getParent ());
1447
1450
I.moveBefore (&Dest);
1448
1451
if (MSSAU)
1449
1452
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(
1450
1453
MSSAU->getMemorySSA ()->getMemoryAccess (&I)))
1451
1454
MSSAU->moveToPlace (OldMemAcc, Dest.getParent (), MemorySSA::End);
1455
+ if (SE)
1456
+ SE->forgetValue (&I);
1452
1457
}
1453
1458
1454
1459
static Instruction *sinkThroughTriviallyReplaceablePHI (
@@ -1662,7 +1667,8 @@ static bool sink(Instruction &I, LoopInfo *LI, DominatorTree *DT,
1662
1667
// /
1663
1668
static void hoist (Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
1664
1669
BasicBlock *Dest, ICFLoopSafetyInfo *SafetyInfo,
1665
- MemorySSAUpdater *MSSAU, OptimizationRemarkEmitter *ORE) {
1670
+ MemorySSAUpdater *MSSAU, ScalarEvolution *SE,
1671
+ OptimizationRemarkEmitter *ORE) {
1666
1672
LLVM_DEBUG (dbgs () << " LICM hoisting to " << Dest->getName () << " : " << I
1667
1673
<< " \n " );
1668
1674
ORE->emit ([&]() {
@@ -1683,10 +1689,10 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
1683
1689
1684
1690
if (isa<PHINode>(I))
1685
1691
// Move the new node to the end of the phi list in the destination block.
1686
- moveInstructionBefore (I, *Dest->getFirstNonPHI (), *SafetyInfo, MSSAU);
1692
+ moveInstructionBefore (I, *Dest->getFirstNonPHI (), *SafetyInfo, MSSAU, SE );
1687
1693
else
1688
1694
// Move the new node to the destination block, before its terminator.
1689
- moveInstructionBefore (I, *Dest->getTerminator (), *SafetyInfo, MSSAU);
1695
+ moveInstructionBefore (I, *Dest->getTerminator (), *SafetyInfo, MSSAU, SE );
1690
1696
1691
1697
// Apply line 0 debug locations when we are moving instructions to different
1692
1698
// basic blocks because we want to avoid jumpy line tables.
0 commit comments