Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 99ddd77

Browse files
author
Max Kazantsev
committed
[NFC] Factor out some reusable logic
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351794 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6c51542 commit 99ddd77

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ class LoopPredication {
272272
LoopICmp RangeCheck,
273273
SCEVExpander &Expander,
274274
IRBuilder<> &Builder);
275+
unsigned collectChecks(SmallVectorImpl<Value *> &Checks, Value *Condition,
276+
SCEVExpander &Expander, IRBuilder<> &Builder);
275277
bool widenGuardConditions(IntrinsicInst *II, SCEVExpander &Expander);
276278

277279
// If the loop always exits through another block in the loop, we should not
@@ -573,26 +575,18 @@ Optional<Value *> LoopPredication::widenICmpRangeCheck(ICmpInst *ICI,
573575
}
574576
}
575577

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;
585583
// The guard condition is expected to be in form of:
586584
// cond1 && cond2 && cond3 ...
587585
// Iterate over subconditions looking for icmp conditions which can be
588586
// widened across loop iterations. Widening these conditions remember the
589587
// resulting list of subconditions in Checks vector.
590-
SmallVector<Value *, 4> Worklist(1, Guard->getOperand(0));
588+
SmallVector<Value *, 4> Worklist(1, Condition);
591589
SmallPtrSet<Value *, 4> Visited;
592-
593-
SmallVector<Value *, 4> Checks;
594-
595-
unsigned NumWidened = 0;
596590
do {
597591
Value *Condition = Worklist.pop_back_val();
598592
if (!Visited.insert(Condition).second)
@@ -616,8 +610,20 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
616610

617611
// Save the condition as is if we can't widen it
618612
Checks.push_back(Condition);
619-
} while (Worklist.size() != 0);
613+
} while (!Worklist.empty());
614+
return NumWidened;
615+
}
620616

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);
621627
if (NumWidened == 0)
622628
return false;
623629

0 commit comments

Comments
 (0)