summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-08-30 23:22:36 +0000
committerOwen Anderson <resistor@mac.com>2010-08-30 23:22:36 +0000
commit327ca7bec274e25c05a0a4ae5b51a8a2062012c7 (patch)
treefd184446a64b3f7ba510b0e6f926fb7c114e60a5
parent6d1e29d2f203093e3e03f15173c0f36637d3afe3 (diff)
downloadllvm-327ca7bec274e25c05a0a4ae5b51a8a2062012c7.tar.gz
llvm-327ca7bec274e25c05a0a4ae5b51a8a2062012c7.tar.bz2
llvm-327ca7bec274e25c05a0a4ae5b51a8a2062012c7.tar.xz
Re-apply r112539, being more careful to respect the return values of the constant folding methods. Additionally,
use the ConstantExpr::get*() methods to simplify some constant folding. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112550 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index c0b0cbebde..7a4c685516 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -16,6 +16,7 @@
#include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
+#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/Analysis/Loads.h"
@@ -325,9 +326,10 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
} else if (LVI) {
Constant *CI = LVI->getConstantOnEdge(InVal,
PN->getIncomingBlock(i), BB);
- ConstantInt *CInt = dyn_cast_or_null<ConstantInt>(CI);
- if (CInt)
- Result.push_back(std::make_pair(CInt, PN->getIncomingBlock(i)));
+ // LVI returns null is no value could be determined.
+ if (!CI) continue;
+ ConstantInt *CInt = dyn_cast<ConstantInt>(CI);
+ Result.push_back(std::make_pair(CInt, PN->getIncomingBlock(i)));
}
}
return !Result.empty();
@@ -373,10 +375,6 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
}
}
return !Result.empty();
-
- // Try to process a few other binary operator patterns.
- } else if (isa<BinaryOperator>(I)) {
-
}
// Handle the NOT form of XOR.
@@ -400,12 +398,19 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
// AND or OR of a value with itself is that value.
ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1));
if (CI && (BO->getOpcode() == Instruction::And ||
- BO->getOpcode() == Instruction::Or)) {
+ BO->getOpcode() == Instruction::Or)) {
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals);
- for (unsigned i = 0, e = LHSVals.size(); i != e; ++i)
- if (LHSVals[i].first == CI)
- Result.push_back(std::make_pair(CI, LHSVals[i].second));
+ for (unsigned i = 0, e = LHSVals.size(); i != e; ++i)
+ if (LHSVals[i].first == 0) {
+ ConstantInt *Zero =
+ cast<ConstantInt>(ConstantInt::get(BO->getType(), 0));
+ Result.push_back(std::make_pair(Zero, LHSVals[i].second));
+ } else if (Constant *Folded = ConstantExpr::get(BO->getOpcode(),
+ LHSVals[i].first, CI)) {
+ Result.push_back(std::make_pair(cast<ConstantInt>(Folded),
+ LHSVals[i].second));
+ }
return !Result.empty();
}
@@ -450,7 +455,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
if (LVI && isa<Constant>(Cmp->getOperand(1)) &&
Cmp->getType()->isIntegerTy()) {
if (!isa<Instruction>(Cmp->getOperand(0)) ||
- cast<Instruction>(Cmp->getOperand(0))->getParent() != BB) {
+ 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){
@@ -472,20 +477,18 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
// Try to find a constant value for the LHS of an equality comparison,
// and evaluate it statically if we can.
- if (Cmp->getPredicate() == CmpInst::ICMP_EQ ||
- Cmp->getPredicate() == CmpInst::ICMP_NE) {
+ if (Constant *CmpConst = dyn_cast<Constant>(Cmp->getOperand(1))) {
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
ComputeValueKnownInPredecessors(I->getOperand(0), BB, LHSVals);
- ConstantInt *True = ConstantInt::getTrue(I->getContext());
- ConstantInt *False = ConstantInt::getFalse(I->getContext());
- if (Cmp->getPredicate() == CmpInst::ICMP_NE) std::swap(True, False);
-
for (unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
- if (LHSVals[i].first == Cmp->getOperand(1))
- Result.push_back(std::make_pair(True, LHSVals[i].second));
- else
- Result.push_back(std::make_pair(False, LHSVals[i].second));
+ if (LHSVals[i].first == 0)
+ Result.push_back(std::make_pair((ConstantInt*)0,
+ LHSVals[i].second));
+ else if (Constant *Folded = ConstantExpr::getCompare(
+ Cmp->getPredicate(), LHSVals[i].first, CmpConst))
+ Result.push_back(std::make_pair(cast<ConstantInt>(Folded),
+ LHSVals[i].second));
}
return !Result.empty();