[llvm] r351794 - [NFC] Factor out some reusable logic
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 02:13:37 PST 2019
Author: mkazantsev
Date: Tue Jan 22 02:13:36 2019
New Revision: 351794
URL: http://llvm.org/viewvc/llvm-project?rev=351794&view=rev
Log:
[NFC] Factor out some reusable logic
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp?rev=351794&r1=351793&r2=351794&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp Tue Jan 22 02:13:36 2019
@@ -272,6 +272,8 @@ class LoopPredication {
LoopICmp RangeCheck,
SCEVExpander &Expander,
IRBuilder<> &Builder);
+ unsigned collectChecks(SmallVectorImpl<Value *> &Checks, Value *Condition,
+ SCEVExpander &Expander, IRBuilder<> &Builder);
bool widenGuardConditions(IntrinsicInst *II, SCEVExpander &Expander);
// If the loop always exits through another block in the loop, we should not
@@ -573,26 +575,18 @@ Optional<Value *> LoopPredication::widen
}
}
-bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
- SCEVExpander &Expander) {
- LLVM_DEBUG(dbgs() << "Processing guard:\n");
- LLVM_DEBUG(Guard->dump());
-
- TotalConsidered++;
-
- IRBuilder<> Builder(cast<Instruction>(Preheader->getTerminator()));
-
+unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks,
+ Value *Condition,
+ SCEVExpander &Expander,
+ IRBuilder<> &Builder) {
+ unsigned NumWidened = 0;
// The guard condition is expected to be in form of:
// cond1 && cond2 && cond3 ...
// Iterate over subconditions looking for icmp conditions which can be
// widened across loop iterations. Widening these conditions remember the
// resulting list of subconditions in Checks vector.
- SmallVector<Value *, 4> Worklist(1, Guard->getOperand(0));
+ SmallVector<Value *, 4> Worklist(1, Condition);
SmallPtrSet<Value *, 4> Visited;
-
- SmallVector<Value *, 4> Checks;
-
- unsigned NumWidened = 0;
do {
Value *Condition = Worklist.pop_back_val();
if (!Visited.insert(Condition).second)
@@ -616,8 +610,20 @@ bool LoopPredication::widenGuardConditio
// Save the condition as is if we can't widen it
Checks.push_back(Condition);
- } while (Worklist.size() != 0);
+ } while (!Worklist.empty());
+ return NumWidened;
+}
+bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
+ SCEVExpander &Expander) {
+ LLVM_DEBUG(dbgs() << "Processing guard:\n");
+ LLVM_DEBUG(Guard->dump());
+
+ TotalConsidered++;
+ SmallVector<Value *, 4> Checks;
+ IRBuilder<> Builder(cast<Instruction>(Preheader->getTerminator()));
+ unsigned NumWidened = collectChecks(Checks, Guard->getOperand(0), Expander,
+ Builder);
if (NumWidened == 0)
return false;
More information about the llvm-commits
mailing list