aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-08-14 18:33:27 +0000
committerOwen Anderson <resistor@mac.com>2007-08-14 18:33:27 +0000
commit31f496755a421a4bc0d07e7c927a14ee50d58763 (patch)
treea9cc0fd1e812fd8f61e85a324b8290de615c0758
parent36057c7834e54d4326bcdc9d182036b2ffa2aa3d (diff)
Eliminate PHI nodes with constant values during normal GVN processing, even when
they're not related to eliminating a load. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41081 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/GVN.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index a7e22dd583..d1a15c1081 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -946,7 +946,27 @@ bool GVN::processInstruction(Instruction* I,
unsigned num = VN.lookup_or_add(I);
- if (currAvail.test(num)) {
+ if (PHINode* p = dyn_cast<PHINode>(I)) {
+ Value* constVal = p->hasConstantValue();
+
+ if (constVal) {
+ if (Instruction* inst = dyn_cast<Instruction>(constVal)) {
+ DominatorTree &DT = getAnalysis<DominatorTree>();
+ if (DT.dominates(inst, p)) {
+ for (PhiMapType::iterator PI = phiMap.begin(), PE = phiMap.end();
+ PI != PE; ++PI)
+ if (PI->second.count(p))
+ PI->second.erase(p);
+
+ p->replaceAllUsesWith(inst);
+ toErase.push_back(p);
+ }
+ } else {
+ p->replaceAllUsesWith(constVal);
+ toErase.push_back(p);
+ }
+ }
+ } else if (currAvail.test(num)) {
Value* repl = find_leader(currAvail, num);
VN.erase(I);