Remove store instructions that store a loaded value that is known to be unmodified.

After this change swap in RC4 contains only 2 stores (of the swapped values).



Swift SVN r15386
This commit is contained in:
Nadav Rotem
2014-03-23 08:03:58 +00:00
parent 37abdddb8e
commit 4d9598fad1
2 changed files with 28 additions and 0 deletions

View File

@@ -114,6 +114,21 @@ bool performLoadStoreOptimizations(SILBasicBlock *BB, AliasAnalysis *AA) {
// This is a StoreInst. Let's see if we can remove the previous stores.
if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
// If we are storing a value that is available in the load list then we
// know that no one clobbered that address and the current store is
// redundant and we can remove it.
if (LoadInst *LdSrc = dyn_cast<LoadInst>(SI->getSrc().getDef())) {
// Check that the loaded value is live and that the destination address
// is the same as the loaded address.
if (Loads.count(LdSrc) && LdSrc->getOperand() == SI->getDest()) {
Changed = true;
recursivelyDeleteTriviallyDeadInstructions(SI, true);
NumDeadStores++;
continue;
}
}
// Invalidate any load that we can not prove does not read from the stores
// destination.
invalidateAliasingLoads(Inst, Loads, AA);