@@ -9492,24 +9492,14 @@ ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
9492
9492
return false ;
9493
9493
}
9494
9494
9495
- bool
9496
- ScalarEvolution::isLoopEntryGuardedByCond (const Loop *L,
9497
- ICmpInst::Predicate Pred,
9498
- const SCEV *LHS, const SCEV *RHS) {
9499
- // Interpret a null as meaning no loop, where there is obviously no guard
9500
- // (interprocedural conditions notwithstanding).
9501
- if (!L) return false ;
9502
-
9495
+ bool ScalarEvolution::isBasicBlockEntryGuardedByCond (const BasicBlock *BB,
9496
+ ICmpInst::Predicate Pred,
9497
+ const SCEV *LHS,
9498
+ const SCEV *RHS) {
9503
9499
if (VerifyIR)
9504
- assert (!verifyFunction (*L-> getHeader () ->getParent (), &dbgs ()) &&
9500
+ assert (!verifyFunction (*BB ->getParent (), &dbgs ()) &&
9505
9501
" This cannot be done on broken IR!" );
9506
9502
9507
- // Both LHS and RHS must be available at loop entry.
9508
- assert (isAvailableAtLoopEntry (LHS, L) &&
9509
- " LHS is not available at Loop Entry" );
9510
- assert (isAvailableAtLoopEntry (RHS, L) &&
9511
- " RHS is not available at Loop Entry" );
9512
-
9513
9503
if (isKnownViaNonRecursiveReasoning (Pred, LHS, RHS))
9514
9504
return true ;
9515
9505
@@ -9566,13 +9556,17 @@ ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L,
9566
9556
return false ;
9567
9557
};
9568
9558
9569
- // Starting at the loop predecessor, climb up the predecessor chain, as long
9559
+ // Starting at the block's predecessor, climb up the predecessor chain, as long
9570
9560
// as there are predecessors that can be found that have unique successors
9571
- // leading to the original header.
9572
- for (std::pair<const BasicBlock *, const BasicBlock *> Pair (
9573
- L->getLoopPredecessor (), L->getHeader ());
9561
+ // leading to the original block.
9562
+ const Loop *ContainingLoop = LI.getLoopFor (BB);
9563
+ const BasicBlock *PredBB;
9564
+ if (ContainingLoop && ContainingLoop->getHeader () == BB)
9565
+ PredBB = ContainingLoop->getLoopPredecessor ();
9566
+ else
9567
+ PredBB = BB->getSinglePredecessor ();
9568
+ for (std::pair<const BasicBlock *, const BasicBlock *> Pair (PredBB, BB);
9574
9569
Pair.first ; Pair = getPredecessorWithUniqueSuccessorForBB (Pair.first )) {
9575
-
9576
9570
if (ProveViaGuard (Pair.first ))
9577
9571
return true ;
9578
9572
@@ -9592,7 +9586,7 @@ ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L,
9592
9586
if (!AssumeVH)
9593
9587
continue ;
9594
9588
auto *CI = cast<CallInst>(AssumeVH);
9595
- if (!DT.dominates (CI, L-> getHeader () ))
9589
+ if (!DT.dominates (CI, BB ))
9596
9590
continue ;
9597
9591
9598
9592
if (ProveViaCond (CI->getArgOperand (0 ), false ))
@@ -9602,6 +9596,23 @@ ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L,
9602
9596
return false ;
9603
9597
}
9604
9598
9599
+ bool ScalarEvolution::isLoopEntryGuardedByCond (const Loop *L,
9600
+ ICmpInst::Predicate Pred,
9601
+ const SCEV *LHS,
9602
+ const SCEV *RHS) {
9603
+ // Interpret a null as meaning no loop, where there is obviously no guard
9604
+ // (interprocedural conditions notwithstanding).
9605
+ if (!L)
9606
+ return false ;
9607
+
9608
+ // Both LHS and RHS must be available at loop entry.
9609
+ assert (isAvailableAtLoopEntry (LHS, L) &&
9610
+ " LHS is not available at Loop Entry" );
9611
+ assert (isAvailableAtLoopEntry (RHS, L) &&
9612
+ " RHS is not available at Loop Entry" );
9613
+ return isBasicBlockEntryGuardedByCond (L->getHeader (), Pred, LHS, RHS);
9614
+ }
9615
+
9605
9616
bool ScalarEvolution::isImpliedCond (ICmpInst::Predicate Pred, const SCEV *LHS,
9606
9617
const SCEV *RHS,
9607
9618
const Value *FoundCondValue, bool Inverse) {
0 commit comments