aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/LoadValueNumbering.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-29 06:11:16 +0000
committerChris Lattner <sabre@nondot.org>2005-01-29 06:11:16 +0000
commite233b8c64bf0d5afeff2041b844689a3994a2848 (patch)
treeaf499eeebe950b77f114de62a8549e4789e54e38 /lib/Analysis/LoadValueNumbering.cpp
parent2652da6af93360e5e5598bc3ca105439a7a8e1a9 (diff)
Eliminate generality that is not buying us anything. In particular, this
will cause us to miss cases where the input pointer to a load could be value numbered to another load. Something like this: %X = load int* %P1 %Y = load int* %P2 Those are obviously the same if P1/P2 are the same. The code this patch removes attempts to handle that. However, since GCSE iterates, this doesn't actually buy us anything: GCSE will first replace P1 or P2 with the other one, then the load can be value numbered as equal. Removing this code speeds up gcse a lot. On 176.gcc in debug mode, this speeds up gcse from 29.08s -> 25.73s, a 13% savings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LoadValueNumbering.cpp')
-rw-r--r--lib/Analysis/LoadValueNumbering.cpp45
1 files changed, 13 insertions, 32 deletions
diff --git a/lib/Analysis/LoadValueNumbering.cpp b/lib/Analysis/LoadValueNumbering.cpp
index d69f83e8a7..32dfdc84e5 100644
--- a/lib/Analysis/LoadValueNumbering.cpp
+++ b/lib/Analysis/LoadValueNumbering.cpp
@@ -284,17 +284,7 @@ void LoadVN::getEqualNumberNodes(Value *V,
if (LI->isVolatile())
return getAnalysis<ValueNumbering>().getEqualNumberNodes(V, RetVals);
- // If we have a load instruction, find all of the load and store instructions
- // that use the same source operand. We implement this recursively, because
- // there could be a load of a load of a load that are all identical. We are
- // guaranteed that this cannot be an infinite recursion because load
- // instructions would have to pass through a PHI node in order for there to be
- // a cycle. The PHI node would be handled by the else case here, breaking the
- // infinite recursion.
- //
- std::vector<Value*> PointerSources;
- getEqualNumberNodes(LI->getOperand(0), PointerSources);
- PointerSources.push_back(LI->getOperand(0));
+ Value *PointerSource = LI->getOperand(0);
BasicBlock *LoadBB = LI->getParent();
Function *F = LoadBB->getParent();
@@ -305,27 +295,18 @@ void LoadVN::getEqualNumberNodes(Value *V,
//
std::map<BasicBlock*, std::vector<LoadInst*> > CandidateLoads;
std::map<BasicBlock*, std::vector<StoreInst*> > CandidateStores;
- std::set<AllocationInst*> Allocations;
-
- while (!PointerSources.empty()) {
- Value *Source = PointerSources.back();
- PointerSources.pop_back(); // Get a source pointer...
-
- if (AllocationInst *AI = dyn_cast<AllocationInst>(Source))
- Allocations.insert(AI);
- for (Value::use_iterator UI = Source->use_begin(), UE = Source->use_end();
- UI != UE; ++UI)
- if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
- if (Cand->getParent()->getParent() == F && // In the same function?
- Cand != LI && !Cand->isVolatile()) // Not LI itself?
- CandidateLoads[Cand->getParent()].push_back(Cand); // Got one...
- } else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
- if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
- Cand->getOperand(1) == Source) // It's a store THROUGH the ptr...
- CandidateStores[Cand->getParent()].push_back(Cand);
- }
- }
+ for (Value::use_iterator UI = PointerSource->use_begin(),
+ UE = PointerSource->use_end(); UI != UE; ++UI)
+ if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
+ if (Cand->getParent()->getParent() == F && // In the same function?
+ Cand != LI && !Cand->isVolatile()) // Not LI itself?
+ CandidateLoads[Cand->getParent()].push_back(Cand); // Got one...
+ } else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
+ if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
+ Cand->getOperand(1) == PointerSource) // It's a store THROUGH the ptr.
+ CandidateStores[Cand->getParent()].push_back(Cand);
+ }
// Get alias analysis & dominators.
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
@@ -358,7 +339,7 @@ void LoadVN::getEqualNumberNodes(Value *V,
} else if (AllocationInst *AI = dyn_cast<AllocationInst>(I)) {
// If we run into an allocation of the value being loaded, then the
// contents are not initialized.
- if (Allocations.count(AI)) {
+ if ((Value*)AI == PointerSource) {
LoadInvalidatedInBBBefore = true;
RetVals.push_back(UndefValue::get(LI->getType()));
break;