[llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp PromoteMemoryToRegister.cpp
Nate Begeman
natebegeman at mac.com
Thu Aug 4 16:24:31 PDT 2005
Changes in directory llvm/lib/Transforms/Utils:
Local.cpp updated: 1.41 -> 1.42
PromoteMemoryToRegister.cpp updated: 1.78 -> 1.79
---
Log message:
Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into
BasicBlock's removePredecessor routine. This requires shuffling around
the definition and implementation of hasContantValue from Utils.h,cpp into
Instructions.h,cpp
---
Diffs of the changes: (+1 -36)
Local.cpp | 34 ----------------------------------
PromoteMemoryToRegister.cpp | 3 +--
2 files changed, 1 insertion(+), 36 deletions(-)
Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.41 llvm/lib/Transforms/Utils/Local.cpp:1.42
--- llvm/lib/Transforms/Utils/Local.cpp:1.41 Wed Jul 27 01:12:34 2005
+++ llvm/lib/Transforms/Utils/Local.cpp Thu Aug 4 18:24:19 2005
@@ -406,37 +406,3 @@
}
return false;
}
-
-//===----------------------------------------------------------------------===//
-// PHI Instruction Simplification
-//
-
-/// hasConstantValue - If the specified PHI node always merges together the same
-/// value, return the value, otherwise return null.
-///
-Value *llvm::hasConstantValue(PHINode *PN) {
- // If the PHI node only has one incoming value, eliminate the PHI node...
- if (PN->getNumIncomingValues() == 1)
- return PN->getIncomingValue(0);
-
- // Otherwise if all of the incoming values are the same for the PHI, replace
- // the PHI node with the incoming value.
- //
- Value *InVal = 0;
- for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
- if (PN->getIncomingValue(i) != PN && // Not the PHI node itself...
- !isa<UndefValue>(PN->getIncomingValue(i)))
- if (InVal && PN->getIncomingValue(i) != InVal)
- return 0; // Not the same, bail out.
- else
- InVal = PN->getIncomingValue(i);
-
- // The only case that could cause InVal to be null is if we have a PHI node
- // that only has entries for itself. In this case, there is no entry into the
- // loop, so kill the PHI.
- //
- if (InVal == 0) InVal = UndefValue::get(PN->getType());
-
- // All of the incoming values are the same, return the value now.
- return InVal;
-}
Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.78 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.79
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.78 Wed Jul 27 01:12:34 2005
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Thu Aug 4 18:24:19 2005
@@ -24,7 +24,6 @@
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/ADT/StringExtras.h"
-#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/StableBasicBlockNumbering.h"
#include <algorithm>
@@ -348,7 +347,7 @@
PHINode *SomePHI = 0;
for (unsigned i = 0, e = PNs.size(); i != e; ++i)
if (PNs[i]) {
- if (Value *V = hasConstantValue(PNs[i])) {
+ if (Value *V = PNs[i]->hasConstantValue()) {
if (!isa<Instruction>(V) || dominates(cast<Instruction>(V), PNs[i])) {
if (AST && isa<PointerType>(PNs[i]->getType()))
AST->deleteValue(PNs[i]);
More information about the llvm-commits
mailing list