mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user