mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Promote partial-loads after stores.
Swift SVN r14217
This commit is contained in:
@@ -144,6 +144,25 @@ bool performLoadStoreOptimizations(SILBasicBlock *BB, AliasAnalysis *AA) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Promote partial loads.
|
||||
// Check that we are loading a struct element:
|
||||
if (auto *SEAI = dyn_cast<StructElementAddrInst>(LI->getOperand())) {
|
||||
// And that the previous store stores into that struct.
|
||||
if (PrevStore && PrevStore->getDest() == SEAI->getOperand()) {
|
||||
// And that the stored value is a struct construction instruction:
|
||||
if (auto *SI = dyn_cast<StructInst>(PrevStore->getSrc())) {
|
||||
DEBUG(llvm::dbgs() << " Forwarding element store from: " <<
|
||||
*PrevStore);
|
||||
unsigned FieldNo = SEAI->getFieldNo();
|
||||
SILValue(LI, 0).replaceAllUsesWith(SI->getOperand(FieldNo));
|
||||
recursivelyDeleteTriviallyDeadInstructions(LI, true);
|
||||
Changed = true;
|
||||
NumForwardedLoads++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search the previous loads and replace the current load with one of the
|
||||
// previous loads.
|
||||
for (auto PrevLI : Loads) {
|
||||
|
||||
@@ -169,3 +169,21 @@ bb0(%0 : $*Agg1):
|
||||
return %5 : $Builtin.Int32
|
||||
}
|
||||
|
||||
struct Wrapper {
|
||||
var value : Int
|
||||
}
|
||||
//CHECK-LABEL: promote_partial_load
|
||||
//CHECK: alloc_stack
|
||||
//CHECK-NOT: load
|
||||
//CHECK: return %0
|
||||
sil @promote_partial_load : $@thin (Int) -> Int {
|
||||
bb0(%0 : $Int):
|
||||
%1 = alloc_stack $Wrapper
|
||||
%2 = struct $Wrapper (%0 : $Int)
|
||||
store %2 to %1#1 : $*Wrapper
|
||||
%3 = struct_element_addr %1#1 : $*Wrapper, #value
|
||||
%4 = load %3 : $*Int
|
||||
dealloc_stack %1#0 : $*@local_storage Wrapper
|
||||
return %4 : $Int
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user