@@ -413,6 +413,19 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
413
413
continue ;
414
414
WorkList.emplace_back (DT.getNode (&BB));
415
415
416
+ // Returns true if we can add a known condition from BB to its successor
417
+ // block Succ. Each predecessor of Succ can either be BB or be dominated by
418
+ // Succ (e.g. the case when adding a condition from a pre-header to a loop
419
+ // header).
420
+ auto CanAdd = [&BB, &DT](BasicBlock *Succ) {
421
+ assert (isa<BranchInst>(BB.getTerminator ()));
422
+ return any_of (successors (&BB),
423
+ [Succ](const BasicBlock *S) { return S != Succ; }) &&
424
+ all_of (predecessors (Succ), [&BB, &DT, Succ](BasicBlock *Pred) {
425
+ return Pred == &BB || DT.dominates (Succ, Pred);
426
+ });
427
+ };
428
+
416
429
// True as long as long as the current instruction is guaranteed to execute.
417
430
bool GuaranteedToExecute = true ;
418
431
// Scan BB for assume calls.
@@ -431,9 +444,12 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
431
444
WorkList.emplace_back (DT.getNode (&BB), cast<ICmpInst>(Cond), false );
432
445
} else {
433
446
// Otherwise the condition only holds in the successors.
434
- for (BasicBlock *Succ : successors (&BB))
447
+ for (BasicBlock *Succ : successors (&BB)) {
448
+ if (!CanAdd (Succ))
449
+ continue ;
435
450
WorkList.emplace_back (DT.getNode (Succ), cast<ICmpInst>(Cond),
436
451
false );
452
+ }
437
453
}
438
454
}
439
455
GuaranteedToExecute &= isGuaranteedToTransferExecutionToSuccessor (&I);
@@ -443,18 +459,6 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
443
459
if (!Br || !Br->isConditional ())
444
460
continue ;
445
461
446
- // Returns true if we can add a known condition from BB to its successor
447
- // block Succ. Each predecessor of Succ can either be BB or be dominated by
448
- // Succ (e.g. the case when adding a condition from a pre-header to a loop
449
- // header).
450
- auto CanAdd = [&BB, &DT](BasicBlock *Succ) {
451
- assert (isa<BranchInst>(BB.getTerminator ()));
452
- return any_of (successors (&BB),
453
- [Succ](const BasicBlock *S) { return S != Succ; }) &&
454
- all_of (predecessors (Succ), [&BB, &DT, Succ](BasicBlock *Pred) {
455
- return Pred == &BB || DT.dominates (Succ, Pred);
456
- });
457
- };
458
462
// If the condition is an OR of 2 compares and the false successor only has
459
463
// the current block as predecessor, queue both negated conditions for the
460
464
// false successor.
0 commit comments