diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-11-30 00:01:19 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-11-30 00:01:19 +0000 | 
| commit | d4f1090948d0ba49f1ddc93ff80e9f3d75b6fd4e (patch) | |
| tree | e43eec4123b1894eba648b7747e552f2034dadba /llvm/lib/Transforms | |
| parent | 318ce7cb3f7539a36d41a030f8998322afbc6f1c (diff) | |
| download | bcm5719-llvm-d4f1090948d0ba49f1ddc93ff80e9f3d75b6fd4e.tar.gz bcm5719-llvm-d4f1090948d0ba49f1ddc93ff80e9f3d75b6fd4e.zip | |
two changes to DSE that shouldn't affect anything:
1. Don't bother trying to optimize:
lifetime.end(ptr)
store(ptr)
as it is undefined, and therefore shouldn't exist.
2. Move the 'storing a loaded pointer' xform up, simplifying
  the may-aliased store code.
llvm-svn: 120359
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 86 | 
1 files changed, 28 insertions, 58 deletions
| diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 4540ccce8c6..e1d89cb9109 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -204,10 +204,10 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {      // If we find a store or a free, get its memory dependence.      if (!doesClobberMemory(Inst) && !isFreeCall(Inst))        continue; -     +      MemDepResult InstDep = MD.getDependency(Inst); -    // Ignore non-local stores. +    // Ignore non-local store liveness.      // FIXME: cross-block DSE would be fun. :)      if (InstDep.isNonLocal()) continue; @@ -216,7 +216,30 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {        MadeChange |= handleFreeWithNonTrivialDependency(F, Inst, InstDep);        continue;      } -     + +    // If we're storing the same value back to a pointer that we just +    // loaded from, then the store can be removed. +    if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { +      if (LoadInst *DepLoad = dyn_cast<LoadInst>(InstDep.getInst())) { +        if (SI->getPointerOperand() == DepLoad->getPointerOperand() && +            SI->getOperand(0) == DepLoad) { +          // DeleteDeadInstruction can delete the current instruction.  Save BBI +          // in case we need it. +          WeakVH NextInst(BBI); +           +          DeleteDeadInstruction(SI); +           +          if (NextInst == 0)  // Next instruction deleted. +            BBI = BB.begin(); +          else if (BBI != BB.begin())  // Revisit this instruction if possible. +            --BBI; +          ++NumFastStores; +          MadeChange = true; +          continue; +        } +      } +    } +           if (!InstDep.isDef()) {        // If this is a may-aliased store that is clobbering the store value, we        // can keep searching past it for another must-aliased pointer that stores @@ -234,20 +257,13 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {            InstDep = MD.getPointerDependencyFrom(Loc, false, InstDep.getInst(),                                                  &BB);        } -         -      // If not a definite must-alias store dependency, ignore it.  If this is a -      // load from the same pointer, we don't want to transform load+store into -      // a noop. -      if (!InstDep.isDef() || !isa<StoreInst>(InstDep.getInst())) -        continue;      }      // If this is a store-store dependence, then the previous store is dead so      // long as this store is at least as big as it. -    if (doesClobberMemory(InstDep.getInst())) { +    if (InstDep.isDef() && doesClobberMemory(InstDep.getInst())) {        Instruction *DepStore = InstDep.getInst(); -      if (isStoreAtLeastAsWideAs(Inst, DepStore, TD) && -          isElidable(DepStore)) { +      if (isStoreAtLeastAsWideAs(Inst, DepStore, TD) && isElidable(DepStore)) {          // Delete the store and now-dead instructions that feed it.          DeleteDeadInstruction(DepStore);          ++NumFastStores; @@ -261,52 +277,6 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {          continue;        }      } -     -    if (!isElidable(Inst)) -      continue; -     -    // If we're storing the same value back to a pointer that we just -    // loaded from, then the store can be removed. -    if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { -      if (LoadInst *DepLoad = dyn_cast<LoadInst>(InstDep.getInst())) { -        if (SI->getPointerOperand() == DepLoad->getPointerOperand() && -            SI->getOperand(0) == DepLoad) { -          // DeleteDeadInstruction can delete the current instruction.  Save BBI -          // in case we need it. -          WeakVH NextInst(BBI); -           -          DeleteDeadInstruction(SI); -           -          if (NextInst == 0)  // Next instruction deleted. -            BBI = BB.begin(); -          else if (BBI != BB.begin())  // Revisit this instruction if possible. -            --BBI; -          ++NumFastStores; -          MadeChange = true; -          continue; -        } -      } -    } -     -    // If this is a lifetime end marker, we can throw away the store. -    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(InstDep.getInst())) { -      if (II->getIntrinsicID() == Intrinsic::lifetime_end) { -        // Delete the store and now-dead instructions that feed it. -        // DeleteDeadInstruction can delete the current instruction.  Save BBI -        // in case we need it. -        WeakVH NextInst(BBI); -         -        DeleteDeadInstruction(Inst); -         -        if (NextInst == 0)  // Next instruction deleted. -          BBI = BB.begin(); -        else if (BBI != BB.begin())  // Revisit this instruction if possible. -          --BBI; -        ++NumFastStores; -        MadeChange = true; -        continue; -      } -    }    }    // If this block ends in a return, unwind, or unreachable, all allocas are | 

