summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMichael Zolotukhin <mzolotukhin@apple.com>2015-07-24 01:53:04 +0000
committerMichael Zolotukhin <mzolotukhin@apple.com>2015-07-24 01:53:04 +0000
commit57776b8159eb9eeaa2ef43f36b8fbeb3d6b5cf64 (patch)
tree120588478833a7a22fc37893f4ce244b6a74cea8 /llvm/lib
parentb4bc424c9acd787fbfcd1506aadd6e49113f6b1c (diff)
downloadbcm5719-llvm-57776b8159eb9eeaa2ef43f36b8fbeb3d6b5cf64.tar.gz
bcm5719-llvm-57776b8159eb9eeaa2ef43f36b8fbeb3d6b5cf64.zip
Handle resolvable branches in complete loop unroll heuristic.
Summary: Resolving a branch allows us to ignore blocks that won't be executed, and thus make our estimate more accurate. This patch is intended to be applied after D10205 (though it could be applied independently). Reviewers: chandlerc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10206 llvm-svn: 243084
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index ff1acc1f579..89b3d47c88f 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -368,8 +368,6 @@ private:
return simplifyInstWithSCEV(&I);
}
- /// TODO: Add visitors for other instruction types, e.g. ZExt, SExt.
-
/// Try to simplify binary operator I.
///
/// TODO: Probaly it's worth to hoist the code for estimating the
@@ -451,6 +449,44 @@ private:
return Base::visitCastInst(I);
}
+
+ bool visitCmpInst(CmpInst &I) {
+ Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
+
+ // First try to handle simplified comparisons.
+ if (!isa<Constant>(LHS))
+ if (Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
+ LHS = SimpleLHS;
+ if (!isa<Constant>(RHS))
+ if (Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
+ RHS = SimpleRHS;
+
+ if (!isa<Constant>(LHS) && !isa<Constant>(RHS)) {
+ auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
+ if (SimplifiedLHS != SimplifiedAddresses.end()) {
+ auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
+ if (SimplifiedRHS != SimplifiedAddresses.end()) {
+ SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
+ SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
+ if (LHSAddr.Base == RHSAddr.Base) {
+ LHS = LHSAddr.Offset;
+ RHS = RHSAddr.Offset;
+ }
+ }
+ }
+ }
+
+ if (Constant *CLHS = dyn_cast<Constant>(LHS)) {
+ if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
+ if (Constant *C = ConstantExpr::getCompare(I.getPredicate(), CLHS, CRHS)) {
+ SimplifiedValues[&I] = C;
+ return true;
+ }
+ }
+ }
+
+ return Base::visitCmpInst(I);
+ }
};
} // namespace
@@ -542,6 +578,28 @@ analyzeLoopUnrollCost(const Loop *L, unsigned TripCount, ScalarEvolution &SE,
return None;
}
+ TerminatorInst *TI = BB->getTerminator();
+
+ // Add in the live successors by first checking whether we have terminator
+ // that may be simplified based on the values simplified by this call.
+ if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+ if (BI->isConditional()) {
+ if (Constant *SimpleCond =
+ SimplifiedValues.lookup(BI->getCondition())) {
+ BBWorklist.insert(BI->getSuccessor(
+ cast<ConstantInt>(SimpleCond)->isZero() ? 1 : 0));
+ continue;
+ }
+ }
+ } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+ if (Constant *SimpleCond =
+ SimplifiedValues.lookup(SI->getCondition())) {
+ BBWorklist.insert(
+ SI->getSuccessor(cast<ConstantInt>(SimpleCond)->getSExtValue()));
+ continue;
+ }
+ }
+
// Add BB's successors to the worklist.
for (BasicBlock *Succ : successors(BB))
if (L->contains(Succ))
OpenPOWER on IntegriCloud