From: Max Kazantsev Date: Tue, 22 Jan 2019 10:13:36 +0000 (+0000) Subject: [NFC] Factor out some reusable logic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99ddd77ed3f32f479b1eadcb41666aeed6907177;p=llvm [NFC] Factor out some reusable logic git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopPredication.cpp b/lib/Transforms/Scalar/LoopPredication.cpp index 624fe0dd83f..b2ff6925978 100644 --- a/lib/Transforms/Scalar/LoopPredication.cpp +++ b/lib/Transforms/Scalar/LoopPredication.cpp @@ -272,6 +272,8 @@ class LoopPredication { LoopICmp RangeCheck, SCEVExpander &Expander, IRBuilder<> &Builder); + unsigned collectChecks(SmallVectorImpl &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 LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, } } -bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, - SCEVExpander &Expander) { - LLVM_DEBUG(dbgs() << "Processing guard:\n"); - LLVM_DEBUG(Guard->dump()); - - TotalConsidered++; - - IRBuilder<> Builder(cast(Preheader->getTerminator())); - +unsigned LoopPredication::collectChecks(SmallVectorImpl &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 Worklist(1, Guard->getOperand(0)); + SmallVector Worklist(1, Condition); SmallPtrSet Visited; - - SmallVector Checks; - - unsigned NumWidened = 0; do { Value *Condition = Worklist.pop_back_val(); if (!Visited.insert(Condition).second) @@ -616,8 +610,20 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, // 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 Checks; + IRBuilder<> Builder(cast(Preheader->getTerminator())); + unsigned NumWidened = collectChecks(Checks, Guard->getOperand(0), Expander, + Builder); if (NumWidened == 0) return false;