@@ -142,6 +142,7 @@ class DFAJumpThreading {
142
142
: AC(AC), DT(DT), LI(LI), TTI(TTI), ORE(ORE) {}
143
143
144
144
bool run (Function &F);
145
+ bool LoopInfoBroken;
145
146
146
147
private:
147
148
void
@@ -1297,6 +1298,7 @@ bool DFAJumpThreading::run(Function &F) {
1297
1298
1298
1299
SmallVector<AllSwitchPaths, 2 > ThreadableLoops;
1299
1300
bool MadeChanges = false ;
1301
+ LoopInfoBroken = false ;
1300
1302
1301
1303
for (BasicBlock &BB : F) {
1302
1304
auto *SI = dyn_cast<SwitchInst>(BB.getTerminator ());
@@ -1329,10 +1331,15 @@ bool DFAJumpThreading::run(Function &F) {
1329
1331
// strict requirement but it can cause buggy behavior if there is an
1330
1332
// overlap of blocks in different opportunities. There is a lot of room to
1331
1333
// experiment with catching more opportunities here.
1334
+ // NOTE: To release this contraint, we must handle LoopInfo invalidation
1332
1335
break ;
1333
1336
}
1334
1337
}
1335
1338
1339
+ #ifdef NDEBUG
1340
+ LI->verify (*DT);
1341
+ #endif
1342
+
1336
1343
SmallPtrSet<const Value *, 32 > EphValues;
1337
1344
if (ThreadableLoops.size () > 0 )
1338
1345
CodeMetrics::collectEphemeralValues (&F, AC, EphValues);
@@ -1341,6 +1348,7 @@ bool DFAJumpThreading::run(Function &F) {
1341
1348
TransformDFA Transform (&SwitchPaths, DT, AC, TTI, ORE, EphValues);
1342
1349
Transform.run ();
1343
1350
MadeChanges = true ;
1351
+ LoopInfoBroken = true ;
1344
1352
}
1345
1353
1346
1354
#ifdef EXPENSIVE_CHECKS
@@ -1361,11 +1369,13 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
1361
1369
LoopInfo &LI = AM.getResult <LoopAnalysis>(F);
1362
1370
TargetTransformInfo &TTI = AM.getResult <TargetIRAnalysis>(F);
1363
1371
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))
1366
1374
return PreservedAnalyses::all ();
1367
1375
1368
1376
PreservedAnalyses PA;
1369
1377
PA.preserve <DominatorTreeAnalysis>();
1378
+ if (!ThreadImpl.LoopInfoBroken )
1379
+ PA.preserve <LoopAnalysis>();
1370
1380
return PA;
1371
1381
}
0 commit comments