summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/GuardUtils.cpp7
-rw-r--r--llvm/lib/Transforms/Scalar/GuardWidening.cpp7
-rw-r--r--llvm/lib/Transforms/Scalar/LoopPredication.cpp10
-rw-r--r--llvm/lib/Transforms/Utils/GuardUtils.cpp26
4 files changed, 37 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/GuardUtils.cpp b/llvm/lib/Analysis/GuardUtils.cpp
index 863443cea35..6dc2b740ac9 100644
--- a/llvm/lib/Analysis/GuardUtils.cpp
+++ b/llvm/lib/Analysis/GuardUtils.cpp
@@ -19,6 +19,13 @@ bool llvm::isGuard(const User *U) {
return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
}
+bool llvm::isWidenableBranch(const User *U) {
+ Value *Condition, *WidenableCondition;
+ BasicBlock *GuardedBB, *DeoptBB;
+ return parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
+ DeoptBB);
+}
+
bool llvm::isGuardAsWidenableBranch(const User *U) {
Value *Condition, *WidenableCondition;
BasicBlock *GuardedBB, *DeoptBB;
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index 27439a206d1..943cc9ac593 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -58,6 +58,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include <functional>
@@ -277,11 +278,7 @@ class GuardWideningImpl {
widenCondCommon(getCondition(ToWiden), NewCondition, ToWiden, Result,
InvertCondition);
if (isGuardAsWidenableBranch(ToWiden)) {
- auto *BI = cast<BranchInst>(ToWiden);
- auto *And = cast<Instruction>(BI->getCondition());
- And->setOperand(0, Result);
- And->moveBefore(ToWiden);
- assert(isGuardAsWidenableBranch(ToWiden) && "still widenable?");
+ setWidenableBranchCond(cast<BranchInst>(ToWiden), Result);
return;
}
setCondition(ToWiden, Result);
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index 9d67046d743..1962c8ba39f 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -196,6 +196,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
@@ -1144,14 +1145,7 @@ bool LoopPredication::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
// context.
NewCond = B.CreateFreeze(NewCond);
- Value *Cond, *WC;
- BasicBlock *IfTrueBB, *IfFalseBB;
- bool Success =
- parseWidenableBranch(WidenableBR, Cond, WC, IfTrueBB, IfFalseBB);
- assert(Success && "implied from above");
- (void)Success;
- Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
- WCAnd->setOperand(0, B.CreateAnd(NewCond, Cond));
+ widenWidenableBranch(WidenableBR, NewCond);
Value *OldCond = BI->getCondition();
BI->setCondition(ConstantInt::get(OldCond->getType(), !ExitIfTrue));
diff --git a/llvm/lib/Transforms/Utils/GuardUtils.cpp b/llvm/lib/Transforms/Utils/GuardUtils.cpp
index 8069aba1fd1..37fca0d129b 100644
--- a/llvm/lib/Transforms/Utils/GuardUtils.cpp
+++ b/llvm/lib/Transforms/Utils/GuardUtils.cpp
@@ -10,6 +10,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/GuardUtils.h"
+#include "llvm/Analysis/GuardUtils.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
@@ -62,3 +63,28 @@ void llvm::makeGuardControlFlowExplicit(Function *DeoptIntrinsic,
DeoptCall->setCallingConv(Guard->getCallingConv());
DeoptBlockTerm->eraseFromParent();
}
+
+
+void llvm::widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond) {
+ assert(isWidenableBranch(WidenableBR) && "precondition");
+
+ Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
+ // Condition is only guaranteed to dominate branch
+ WCAnd->moveBefore(WidenableBR);
+ Value *OldCond = WCAnd->getOperand(0);
+ IRBuilder<> B(WCAnd);
+ WCAnd->setOperand(0, B.CreateAnd(NewCond, OldCond));
+
+ assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
+}
+
+void llvm::setWidenableBranchCond(BranchInst *WidenableBR, Value *NewCond) {
+ assert(isWidenableBranch(WidenableBR) && "precondition");
+
+ Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
+ // Condition is only guaranteed to dominate branch
+ WCAnd->moveBefore(WidenableBR);
+ WCAnd->setOperand(0, NewCond);
+
+ assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
+}
OpenPOWER on IntegriCloud