Skip to content

Commit 94cbd89

Browse files
committed
[DFAJumpThreading] Add checks about LoopInfo
1 parent 35bc0a3 commit 94cbd89

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class DFAJumpThreading {
142142
: AC(AC), DT(DT), LI(LI), TTI(TTI), ORE(ORE) {}
143143

144144
bool run(Function &F);
145+
bool LoopInfoBroken;
145146

146147
private:
147148
void
@@ -1297,6 +1298,7 @@ bool DFAJumpThreading::run(Function &F) {
12971298

12981299
SmallVector<AllSwitchPaths, 2> ThreadableLoops;
12991300
bool MadeChanges = false;
1301+
LoopInfoBroken = false;
13001302

13011303
for (BasicBlock &BB : F) {
13021304
auto *SI = dyn_cast<SwitchInst>(BB.getTerminator());
@@ -1329,10 +1331,15 @@ bool DFAJumpThreading::run(Function &F) {
13291331
// strict requirement but it can cause buggy behavior if there is an
13301332
// overlap of blocks in different opportunities. There is a lot of room to
13311333
// experiment with catching more opportunities here.
1334+
// NOTE: To release this contraint, we must handle LoopInfo invalidation
13321335
break;
13331336
}
13341337
}
13351338

1339+
#ifdef NDEBUG
1340+
LI->verify(*DT);
1341+
#endif
1342+
13361343
SmallPtrSet<const Value *, 32> EphValues;
13371344
if (ThreadableLoops.size() > 0)
13381345
CodeMetrics::collectEphemeralValues(&F, AC, EphValues);
@@ -1341,6 +1348,7 @@ bool DFAJumpThreading::run(Function &F) {
13411348
TransformDFA Transform(&SwitchPaths, DT, AC, TTI, ORE, EphValues);
13421349
Transform.run();
13431350
MadeChanges = true;
1351+
LoopInfoBroken = true;
13441352
}
13451353

13461354
#ifdef EXPENSIVE_CHECKS
@@ -1361,11 +1369,13 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
13611369
LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
13621370
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
13631371
OptimizationRemarkEmitter ORE(&F);
1364-
1365-
if (!DFAJumpThreading(&AC, &DT, &LI, &TTI, &ORE).run(F))
1372+
DFAJumpThreading ThreadImpl(&AC, &DT, &LI, &TTI, &ORE);
1373+
if (!ThreadImpl.run(F))
13661374
return PreservedAnalyses::all();
13671375

13681376
PreservedAnalyses PA;
13691377
PA.preserve<DominatorTreeAnalysis>();
1378+
if (!ThreadImpl.LoopInfoBroken)
1379+
PA.preserve<LoopAnalysis>();
13701380
return PA;
13711381
}

0 commit comments

Comments
 (0)