summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-09-16 08:04:16 +0000
committerOwen Anderson <resistor@mac.com>2007-09-16 08:04:16 +0000
commit4cd516b50bf9b5751b90c7aa407b0c4702dca278 (patch)
treef6e4d48e5d1e791d37491e9a6831b5a524ec9466 /llvm/lib
parent83895f7888a7e0341b0fc034508bfc9a7c2a76e4 (diff)
downloadbcm5719-llvm-4cd516b50bf9b5751b90c7aa407b0c4702dca278.tar.gz
bcm5719-llvm-4cd516b50bf9b5751b90c7aa407b0c4702dca278.zip
Be more careful when constant-folding PHI nodes.
llvm-svn: 41998
Diffstat (limited to 'llvm/lib')
-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 75edd8eaf9e..7f809e73978 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,
OpenPOWER on IntegriCloud