aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2007-09-18 05:28:53 +0000
committerTanya Lattner <tonic@nondot.org>2007-09-18 05:28:53 +0000
commiteb9b0330a146043413bf8c938adf91f369a25883 (patch)
treeb4022008754dd0421dbaf02801e521cca5a45d24
parent9641951f9ca1dfeb528da0cd425f6330ec249a0b (diff)
downloadllvm-eb9b0330a146043413bf8c938adf91f369a25883.zip
llvm-eb9b0330a146043413bf8c938adf91f369a25883.tar.gz
llvm-eb9b0330a146043413bf8c938adf91f369a25883.tar.bz2
Merge from mainline because Owen said so.
llvm-svn: 42080
-rw-r--r--llvm/lib/Transforms/Scalar/GVN.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 75edd8e..7f809e7 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -673,6 +673,7 @@ namespace {
void dump(DenseMap<BasicBlock*, Value*>& d);
bool iterateOnFunction(Function &F);
Value* CollapsePhi(PHINode* p);
+ bool isSafeReplacement(PHINode* p, Instruction* inst);
};
char GVN::ID = 0;
@@ -731,7 +732,8 @@ Value* GVN::CollapsePhi(PHINode* p) {
if (constVal) {
if (Instruction* inst = dyn_cast<Instruction>(constVal)) {
if (DT.dominates(inst, p))
- return inst;
+ if (isSafeReplacement(p, inst))
+ return inst;
} else {
return constVal;
}
@@ -740,6 +742,19 @@ Value* GVN::CollapsePhi(PHINode* p) {
return 0;
}
+bool GVN::isSafeReplacement(PHINode* p, Instruction* inst) {
+ if (!isa<PHINode>(inst))
+ return true;
+
+ for (Instruction::use_iterator UI = p->use_begin(), E = p->use_end();
+ UI != E; ++UI)
+ if (PHINode* use_phi = dyn_cast<PHINode>(UI))
+ if (use_phi->getParent() == inst->getParent())
+ return false;
+
+ return true;
+}
+
/// GetValueForBlock - Get the value to use within the specified basic block.
/// available values are in Phis.
Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,