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
commit5da2c85166476ed983e39826f302753e62f61ded (patch)
treecb40645e51ab8ad25667de45d723aea5d119cfdf
parent987b27b723806a69b7106a7161ebac741d3445ff (diff)
Merge from mainline because Owen said so.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_21@42080 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/GVN.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 75edd8eaf9..7f809e7397 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/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,