Skip to content

Commit

Permalink
[LoopPredication] NFC. Extract LoopPredication::expandCheck helper
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303426 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arpilipe committed May 19, 2017
1 parent f7a7324 commit 481df10
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/Transforms/Scalar/LoopPredication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class LoopPredication {
const DataLayout *DL;
BasicBlock *Preheader;

Value *expandCheck(SCEVExpander &Expander, IRBuilder<> &Builder,
ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS,
Instruction *InsertAt);

Optional<Value *> widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander,
IRBuilder<> &Builder);
bool widenGuardConditions(IntrinsicInst *II, SCEVExpander &Expander);
Expand Down Expand Up @@ -116,6 +120,17 @@ PreservedAnalyses LoopPredicationPass::run(Loop &L, LoopAnalysisManager &AM,
return getLoopPassPreservedAnalyses();
}

Value *LoopPredication::expandCheck(SCEVExpander &Expander,
IRBuilder<> &Builder,
ICmpInst::Predicate Pred, const SCEV *LHS,
const SCEV *RHS, Instruction *InsertAt) {
Type *Ty = LHS->getType();
assert(Ty == RHS->getType() && "expandCheck operands have different types?");
Value *LHSV = Expander.expandCodeFor(LHS, Ty, InsertAt);
Value *RHSV = Expander.expandCodeFor(RHS, Ty, InsertAt);
return Builder.CreateICmp(Pred, LHSV, RHSV);
}

/// If ICI can be widened to a loop invariant condition emits the loop
/// invariant condition in the loop preheader and return it, otherwise
/// returns None.
Expand Down Expand Up @@ -179,12 +194,8 @@ Optional<Value *> LoopPredication::widenICmpRangeCheck(ICmpInst *ICI,

DEBUG(dbgs() << "NewLHSS is loop invariant and safe to expand. Expand!\n");

Type *Ty = LHS->getType();
Instruction *InsertAt = Preheader->getTerminator();
assert(Ty == RHS->getType() && "icmp operands have different types?");
Value *NewLHS = Expander.expandCodeFor(NewLHSS, Ty, InsertAt);
Value *NewRHS = Expander.expandCodeFor(RHSS, Ty, InsertAt);
return Builder.CreateICmp(Pred, NewLHS, NewRHS);
return expandCheck(Expander, Builder, Pred, NewLHSS, RHSS, InsertAt);
}

bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
Expand Down

0 comments on commit 481df10

Please sign in to comment.