aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/JumpThreading.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-11 22:31:38 +0000
committerChris Lattner <sabre@nondot.org>2009-11-11 22:31:38 +0000
commit2ad00bf99d5738c39dbc8cab7e30a0b55e0714ad (patch)
treeae3e30704ab59f4547150133b41dc74f50b368d7 /lib/Transforms/Scalar/JumpThreading.cpp
parentffe644ebf4dcc50b314261ddd2d08c841f629349 (diff)
pass TD into a SimplifyCmpInst call. Add another case that
uses LVI info when -enable-jump-threading-lvi is passed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86886 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index 03b32540c9..e93e9cb4d3 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -361,7 +361,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
Value *LHS = PN->getIncomingValue(i);
Value *RHS = Cmp->getOperand(1)->DoPHITranslation(BB, PredBB);
- Value *Res = SimplifyCmpInst(Cmp->getPredicate(), LHS, RHS);
+ Value *Res = SimplifyCmpInst(Cmp->getPredicate(), LHS, RHS, TD);
if (Res == 0) continue;
if (isa<UndefValue>(Res))
@@ -373,8 +373,29 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
return !Result.empty();
}
- // TODO: We could also recurse to see if we can determine constants another
- // way.
+
+ // If comparing a live-in value against a constant, see if we know the
+ // live-in value on any predecessors.
+ if (LVI && isa<Constant>(Cmp->getOperand(1)) &&
+ (!isa<Instruction>(Cmp->getOperand(0)) ||
+ cast<Instruction>(Cmp->getOperand(0))->getParent() != BB)) {
+ Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
+
+ for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
+ // If the value is known by LazyValueInfo to be a constant in a
+ // predecessor, use that information to try to thread this block.
+ Constant *PredCst = LVI->getConstant(Cmp->getOperand(0), *PI);
+ if (PredCst == 0)
+ continue;
+
+ // Constant fold the compare.
+ Value *Res = SimplifyCmpInst(Cmp->getPredicate(), PredCst, RHSCst, TD);
+ if (isa<ConstantInt>(Res) || isa<UndefValue>(Res))
+ Result.push_back(std::make_pair(dyn_cast<ConstantInt>(Res), *PI));
+ }
+
+ return !Result.empty();
+ }
}
return false;
}