[llvm-commits] [llvm] r42080 - /llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp
Tanya Lattner
tonic at nondot.org
Mon Sep 17 22:28:53 PDT 2007
Author: tbrethou
Date: Tue Sep 18 00:28:53 2007
New Revision: 42080
URL: http://llvm.org/viewvc/llvm-project?rev=42080&view=rev
Log:
Merge from mainline because Owen said so.
Modified:
llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp?rev=42080&r1=42079&r2=42080&view=diff
==============================================================================
--- llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/branches/release_21/lib/Transforms/Scalar/GVN.cpp Tue Sep 18 00:28:53 2007
@@ -673,6 +673,7 @@
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 @@
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 @@
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,
More information about the llvm-commits
mailing list