diff options
author | Philip Reames <listmail@philipreames.com> | 2016-02-22 20:45:56 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2016-02-22 20:45:56 +0000 |
commit | 79fa9b75c07fe7aa6fa48b4e3c16a1f8f40ac8d4 (patch) | |
tree | 6e02222ac0c196a1f59a6d7281ae3f8c476a7fc1 /llvm/lib | |
parent | 437786cf6065d86ddc9e8e30ea545e59ed89394d (diff) | |
download | bcm5719-llvm-79fa9b75c07fe7aa6fa48b4e3c16a1f8f40ac8d4.tar.gz bcm5719-llvm-79fa9b75c07fe7aa6fa48b4e3c16a1f8f40ac8d4.zip |
[RS4GC] Revert optimization attempt due to memory corruption
This change reverts "246133 [RewriteStatepointsForGC] Reduce the number of new instructions for base pointers" and a follow on bugfix 12575.
As pointed out in pr25846, this code suffers from a memory corruption bug. Since I'm (empirically) not going to get back to this any time soon, simply reverting the problematic change is the right answer.
llvm-svn: 261565
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 66 |
1 files changed, 3 insertions, 63 deletions
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index 4c86eeb7350..d2eac9112ea 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -14,7 +14,6 @@ #include "llvm/Pass.h" #include "llvm/Analysis/CFG.h" -#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/Statistic.h" @@ -1025,68 +1024,6 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache) { } - // Now that we're done with the algorithm, see if we can optimize the - // results slightly by reducing the number of new instructions needed. - // Arguably, this should be integrated into the algorithm above, but - // doing as a post process step is easier to reason about for the moment. - DenseMap<Value *, Value *> ReverseMap; - SmallPtrSet<Instruction *, 16> NewInsts; - SmallSetVector<AssertingVH<Instruction>, 16> Worklist; - // Note: We need to visit the states in a deterministic order. We uses the - // Keys we sorted above for this purpose. Note that we are papering over a - // bigger problem with the algorithm above - it's visit order is not - // deterministic. A larger change is needed to fix this. - for (auto Pair : States) { - auto *BDV = Pair.first; - auto State = Pair.second; - Value *Base = State.getBase(); - assert(BDV && Base); - assert(!isKnownBaseResult(BDV) && "why did it get added?"); - assert(isKnownBaseResult(Base) && - "must be something we 'know' is a base pointer"); - if (!State.isConflict()) - continue; - - ReverseMap[Base] = BDV; - if (auto *BaseI = dyn_cast<Instruction>(Base)) { - NewInsts.insert(BaseI); - Worklist.insert(BaseI); - } - } - auto ReplaceBaseInstWith = [&](Value *BDV, Instruction *BaseI, - Value *Replacement) { - // Add users which are new instructions (excluding self references) - for (User *U : BaseI->users()) - if (auto *UI = dyn_cast<Instruction>(U)) - if (NewInsts.count(UI) && UI != BaseI) - Worklist.insert(UI); - // Then do the actual replacement - NewInsts.erase(BaseI); - ReverseMap.erase(BaseI); - BaseI->replaceAllUsesWith(Replacement); - assert(States.count(BDV)); - assert(States[BDV].isConflict() && States[BDV].getBase() == BaseI); - States[BDV] = BDVState(BDVState::Conflict, Replacement); - BaseI->eraseFromParent(); - }; - const DataLayout &DL = cast<Instruction>(def)->getModule()->getDataLayout(); - while (!Worklist.empty()) { - Instruction *BaseI = Worklist.pop_back_val(); - assert(NewInsts.count(BaseI)); - Value *Bdv = ReverseMap[BaseI]; - if (auto *BdvI = dyn_cast<Instruction>(Bdv)) - if (BaseI->isIdenticalTo(BdvI)) { - DEBUG(dbgs() << "Identical Base: " << *BaseI << "\n"); - ReplaceBaseInstWith(Bdv, BaseI, Bdv); - continue; - } - if (Value *V = SimplifyInstruction(BaseI, DL)) { - DEBUG(dbgs() << "Base " << *BaseI << " simplified to " << *V << "\n"); - ReplaceBaseInstWith(Bdv, BaseI, V); - continue; - } - } - // Cache all of our results so we can cheaply reuse them // NOTE: This is actually two caches: one of the base defining value // relation and one of the base pointer relation! FIXME @@ -1094,6 +1031,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache) { auto *BDV = Pair.first; Value *base = Pair.second.getBase(); assert(BDV && base); + assert(!isKnownBaseResult(BDV) && "why did it get added?"); std::string fromstr = cache.count(BDV) ? cache[BDV]->getName() : "none"; DEBUG(dbgs() << "Updating base value cache" @@ -1102,6 +1040,8 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache) { << " to: " << base->getName() << "\n"); if (cache.count(BDV)) { + assert(isKnownBaseResult(base) && + "must be something we 'know' is a base pointer"); // Once we transition from the BDV relation being store in the cache to // the base relation being stored, it must be stable assert((!isKnownBaseResult(cache[BDV]) || cache[BDV] == base) && |