@@ -606,7 +606,7 @@ static bool CanFlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
606
606
607
607
static bool DoFlattenLoopPair (FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
608
608
ScalarEvolution *SE, AssumptionCache *AC,
609
- const TargetTransformInfo *TTI) {
609
+ const TargetTransformInfo *TTI, LPMUpdater *U ) {
610
610
Function *F = FI.OuterLoop ->getHeader ()->getParent ();
611
611
LLVM_DEBUG (dbgs () << " Checks all passed, doing the transformation\n " );
612
612
{
@@ -662,6 +662,8 @@ static bool DoFlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
662
662
// deleted, and any information that have about the outer loop invalidated.
663
663
SE->forgetLoop (FI.OuterLoop );
664
664
SE->forgetLoop (FI.InnerLoop );
665
+ if (U)
666
+ U->markLoopAsDeleted (*FI.InnerLoop , FI.InnerLoop ->getName ());
665
667
LI->erase (FI.InnerLoop );
666
668
667
669
// Increment statistic value.
@@ -737,7 +739,7 @@ static bool CanWidenIV(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
737
739
738
740
static bool FlattenLoopPair (FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
739
741
ScalarEvolution *SE, AssumptionCache *AC,
740
- const TargetTransformInfo *TTI) {
742
+ const TargetTransformInfo *TTI, LPMUpdater *U ) {
741
743
LLVM_DEBUG (
742
744
dbgs () << " Loop flattening running on outer loop "
743
745
<< FI.OuterLoop ->getHeader ()->getName () << " and inner loop "
@@ -766,7 +768,7 @@ static bool FlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
766
768
767
769
// If we have widened and can perform the transformation, do that here.
768
770
if (CanFlatten)
769
- return DoFlattenLoopPair (FI, DT, LI, SE, AC, TTI);
771
+ return DoFlattenLoopPair (FI, DT, LI, SE, AC, TTI, U );
770
772
771
773
// Otherwise, if we haven't widened the IV, check if the new iteration
772
774
// variable might overflow. In this case, we need to version the loop, and
@@ -784,18 +786,18 @@ static bool FlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
784
786
}
785
787
786
788
LLVM_DEBUG (dbgs () << " Multiply cannot overflow, modifying loop in-place\n " );
787
- return DoFlattenLoopPair (FI, DT, LI, SE, AC, TTI);
789
+ return DoFlattenLoopPair (FI, DT, LI, SE, AC, TTI, U );
788
790
}
789
791
790
792
bool Flatten (LoopNest &LN, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE,
791
- AssumptionCache *AC, TargetTransformInfo *TTI) {
793
+ AssumptionCache *AC, TargetTransformInfo *TTI, LPMUpdater *U ) {
792
794
bool Changed = false ;
793
795
for (Loop *InnerLoop : LN.getLoops ()) {
794
796
auto *OuterLoop = InnerLoop->getParentLoop ();
795
797
if (!OuterLoop)
796
798
continue ;
797
799
FlattenInfo FI (OuterLoop, InnerLoop);
798
- Changed |= FlattenLoopPair (FI, DT, LI, SE, AC, TTI);
800
+ Changed |= FlattenLoopPair (FI, DT, LI, SE, AC, TTI, U );
799
801
}
800
802
return Changed;
801
803
}
@@ -810,7 +812,7 @@ PreservedAnalyses LoopFlattenPass::run(LoopNest &LN, LoopAnalysisManager &LAM,
810
812
// in simplified form, and also needs LCSSA. Running
811
813
// this pass will simplify all loops that contain inner loops,
812
814
// regardless of whether anything ends up being flattened.
813
- Changed |= Flatten (LN, &AR.DT , &AR.LI , &AR.SE , &AR.AC , &AR.TTI );
815
+ Changed |= Flatten (LN, &AR.DT , &AR.LI , &AR.SE , &AR.AC , &AR.TTI , &U );
814
816
815
817
if (!Changed)
816
818
return PreservedAnalyses::all ();
@@ -860,7 +862,7 @@ bool LoopFlattenLegacyPass::runOnFunction(Function &F) {
860
862
bool Changed = false ;
861
863
for (Loop *L : *LI) {
862
864
auto LN = LoopNest::getLoopNest (*L, *SE);
863
- Changed |= Flatten (*LN, DT, LI, SE, AC, TTI);
865
+ Changed |= Flatten (*LN, DT, LI, SE, AC, TTI, nullptr );
864
866
}
865
867
return Changed;
866
868
}
0 commit comments