From e233b8c64bf0d5afeff2041b844689a3994a2848 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 29 Jan 2005 06:11:16 +0000 Subject: [PATCH] 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 --- lib/Analysis/LoadValueNumbering.cpp | 45 +++++++++-------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/lib/Analysis/LoadValueNumbering.cpp b/lib/Analysis/LoadValueNumbering.cpp index d69f83e8a73..32dfdc84e51 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().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 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 > CandidateLoads; std::map > CandidateStores; - std::set Allocations; - - while (!PointerSources.empty()) { - Value *Source = PointerSources.back(); - PointerSources.pop_back(); // Get a source pointer... - - if (AllocationInst *AI = dyn_cast(Source)) - Allocations.insert(AI); - for (Value::use_iterator UI = Source->use_begin(), UE = Source->use_end(); - UI != UE; ++UI) - if (LoadInst *Cand = dyn_cast(*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(*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(*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(*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(); @@ -358,7 +339,7 @@ void LoadVN::getEqualNumberNodes(Value *V, } else if (AllocationInst *AI = dyn_cast(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;