diff options
author | Philip Reames <listmail@philipreames.com> | 2019-04-15 15:53:25 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-04-15 15:53:25 +0000 |
commit | fbe64a2cfb413181b23cf5f307af8f86bf3c870a (patch) | |
tree | b3688e237a1f7868d67c0b6aac57bf6fd93202c6 /llvm/lib/Transforms/Scalar/LoopPredication.cpp | |
parent | 204339a2348d179206fc41c9fa3b6f827281fba5 (diff) | |
download | llvm-fbe64a2cfb413181b23cf5f307af8f86bf3c870a.zip llvm-fbe64a2cfb413181b23cf5f307af8f86bf3c870a.tar.gz llvm-fbe64a2cfb413181b23cf5f307af8f86bf3c870a.tar.bz2 |
[LoopPred] Hoist and of predicated checks where legal
If we have multiple range checks which can be predicated, hoist the and of the results outside the loop. This minorly cleans up the resulting IR, but the main motivation is as a building block for D60093.
llvm-svn: 358419
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopPredication.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopPredication.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 8487278..3b27364 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -264,6 +264,12 @@ class LoopPredication { Optional<LoopICmp> parseLoopLatchICmp(); + /// Return an insertion point suitable for inserting a safe to speculate + /// instruction whose only user will be 'User' which has operands 'Ops'. A + /// trivial result would be the at the User itself, but we try to return a + /// loop invariant location if possible. + Instruction *findInsertPt(Instruction *User, ArrayRef<Value*> Ops); + bool CanExpand(const SCEV* S); Value *expandCheck(SCEVExpander &Expander, IRBuilder<> &Builder, ICmpInst::Predicate Pred, const SCEV *LHS, @@ -438,6 +444,14 @@ bool LoopPredication::isSupportedStep(const SCEV* Step) { return Step->isOne() || (Step->isAllOnesValue() && EnableCountDownLoop); } +Instruction *LoopPredication::findInsertPt(Instruction *Use, + ArrayRef<Value*> Ops) { + for (Value *Op : Ops) + if (!L->isLoopInvariant(Op)) + return Use; + return Preheader->getTerminator(); +} + bool LoopPredication::CanExpand(const SCEV* S) { return SE->isLoopInvariant(S, L) && isSafeToExpand(S, *SE); } @@ -652,7 +666,7 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, TotalWidened += NumWidened; // Emit the new guard condition - Builder.SetInsertPoint(Guard); + Builder.SetInsertPoint(findInsertPt(Guard, Checks)); Value *LastCheck = nullptr; for (auto *Check : Checks) if (!LastCheck) @@ -684,7 +698,7 @@ bool LoopPredication::widenWidenableBranchGuardConditions( TotalWidened += NumWidened; // Emit the new guard condition - Builder.SetInsertPoint(BI); + Builder.SetInsertPoint(findInsertPt(BI, Checks)); Value *LastCheck = nullptr; for (auto *Check : Checks) if (!LastCheck) |