@@ -272,6 +272,8 @@ class LoopPredication {
272
272
LoopICmp RangeCheck,
273
273
SCEVExpander &Expander,
274
274
IRBuilder<> &Builder);
275
+ unsigned collectChecks (SmallVectorImpl<Value *> &Checks, Value *Condition,
276
+ SCEVExpander &Expander, IRBuilder<> &Builder);
275
277
bool widenGuardConditions (IntrinsicInst *II, SCEVExpander &Expander);
276
278
277
279
// If the loop always exits through another block in the loop, we should not
@@ -573,26 +575,18 @@ Optional<Value *> LoopPredication::widenICmpRangeCheck(ICmpInst *ICI,
573
575
}
574
576
}
575
577
576
- bool LoopPredication::widenGuardConditions (IntrinsicInst *Guard,
577
- SCEVExpander &Expander) {
578
- LLVM_DEBUG (dbgs () << " Processing guard:\n " );
579
- LLVM_DEBUG (Guard->dump ());
580
-
581
- TotalConsidered++;
582
-
583
- IRBuilder<> Builder (cast<Instruction>(Preheader->getTerminator ()));
584
-
578
+ unsigned LoopPredication::collectChecks (SmallVectorImpl<Value *> &Checks,
579
+ Value *Condition,
580
+ SCEVExpander &Expander,
581
+ IRBuilder<> &Builder) {
582
+ unsigned NumWidened = 0 ;
585
583
// The guard condition is expected to be in form of:
586
584
// cond1 && cond2 && cond3 ...
587
585
// Iterate over subconditions looking for icmp conditions which can be
588
586
// widened across loop iterations. Widening these conditions remember the
589
587
// resulting list of subconditions in Checks vector.
590
- SmallVector<Value *, 4 > Worklist (1 , Guard-> getOperand ( 0 ) );
588
+ SmallVector<Value *, 4 > Worklist (1 , Condition );
591
589
SmallPtrSet<Value *, 4 > Visited;
592
-
593
- SmallVector<Value *, 4 > Checks;
594
-
595
- unsigned NumWidened = 0 ;
596
590
do {
597
591
Value *Condition = Worklist.pop_back_val ();
598
592
if (!Visited.insert (Condition).second )
@@ -616,8 +610,20 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
616
610
617
611
// Save the condition as is if we can't widen it
618
612
Checks.push_back (Condition);
619
- } while (Worklist.size () != 0 );
613
+ } while (!Worklist.empty ());
614
+ return NumWidened;
615
+ }
620
616
617
+ bool LoopPredication::widenGuardConditions (IntrinsicInst *Guard,
618
+ SCEVExpander &Expander) {
619
+ LLVM_DEBUG (dbgs () << " Processing guard:\n " );
620
+ LLVM_DEBUG (Guard->dump ());
621
+
622
+ TotalConsidered++;
623
+ SmallVector<Value *, 4 > Checks;
624
+ IRBuilder<> Builder (cast<Instruction>(Preheader->getTerminator ()));
625
+ unsigned NumWidened = collectChecks (Checks, Guard->getOperand (0 ), Expander,
626
+ Builder);
621
627
if (NumWidened == 0 )
622
628
return false ;
623
629
0 commit comments