Skip to content

[DNM] disable assign/partial store as a test. #21918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,11 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {

// Coming out of SILGen, we assume that raw stores are initializations,
// unless they have trivial type (which we classify as InitOrAssign).
PMOUseKind Kind;
if (InStructSubElement)
Kind = PMOUseKind::PartialStore;
else if (PointeeType.isTrivial(User->getModule()))
Kind = PMOUseKind::InitOrAssign;
else
Kind = PMOUseKind::Initialization;

auto Kind = ([&]() -> PMOUseKind {
if (PointeeType.isTrivial(User->getModule()))
return PMOUseKind::InitOrAssign;
return PMOUseKind::Initialization;
})();
Uses.emplace_back(User, Kind);
continue;
}
Expand All @@ -270,9 +267,7 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {
if (auto *SI = dyn_cast<Store##Name##Inst>(User)) { \
if (UI->getOperandNumber() == 1) { \
PMOUseKind Kind; \
if (InStructSubElement) \
Kind = PMOUseKind::PartialStore; \
else if (SI->isInitializationOfDest()) \
if (SI->isInitializationOfDest()) \
Kind = PMOUseKind::Initialization; \
else \
Kind = PMOUseKind::Assign; \
Expand All @@ -294,16 +289,17 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {
// the destination, then this is an unknown assignment. Note that we'll
// revisit this instruction and add it to Uses twice if it is both a load
// and store to the same aggregate.
PMOUseKind Kind;
if (UI->getOperandNumber() == 0)
Kind = PMOUseKind::Load;
else if (InStructSubElement)
Kind = PMOUseKind::PartialStore;
else if (CAI->isInitializationOfDest())
Kind = PMOUseKind::Initialization;
else
Kind = PMOUseKind::Assign;

//
// Inline constructor.
auto Kind = ([&]() -> PMOUseKind {
if (UI->getOperandNumber() == CopyAddrInst::Src)
return PMOUseKind::Load;
if (PointeeType.isTrivial(CAI->getModule()))
return PMOUseKind::InitOrAssign;
if (CAI->isInitializationOfDest())
return PMOUseKind::Initialization;
return PMOUseKind::Assign;
})();
Uses.emplace_back(User, Kind);
continue;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ enum PMOUseKind {
/// value.
Assign,

/// The instruction is a store to a member of a larger struct value.
PartialStore,

/// An indirect 'inout' parameter of an Apply instruction.
InOutUse,

Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ void AvailableValueDataflowContext::explodeCopyAddr(CopyAddrInst *CAI) {
assert((LoadUse.isValid() || StoreUse.isValid()) &&
"we should have a load or a store, possibly both");
assert(StoreUse.isInvalid() || StoreUse.Kind == Assign ||
StoreUse.Kind == PartialStore || StoreUse.Kind == Initialization);
StoreUse.Kind == Initialization || StoreUse.Kind == InitOrAssign);

// Now that we've emitted a bunch of instructions, including a load and store
// but also including other stuff, update the internal state of
Expand Down Expand Up @@ -1286,7 +1286,7 @@ bool AllocOptimize::tryToRemoveDeadAllocation() {

switch (u.Kind) {
case PMOUseKind::Assign:
case PMOUseKind::PartialStore:
return false;
case PMOUseKind::InitOrAssign:
break; // These don't prevent removal.
case PMOUseKind::Initialization:
Expand Down
23 changes: 15 additions & 8 deletions test/SILOptimizer/predictable_memopt.sil
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ bb0(%0 : $Int):
// Verify that promotion has promoted the tuple load away, and we know that
// %0 is being returned through scalar instructions in SSA form.
//
// CHECK-LABEL: sil @tuple_reg_promotion
// CHECK-LABEL: sil @tuple_reg_promotion :
// CHECK: bb0(%0 : $Int):
// CHECK-NEXT: [[TUPLE:%[0-9]+]] = tuple ({{.*}} : $Int, {{.*}} : $Int)
// CHECK-NEXT: [[TUPLE_ELT:%[0-9]+]] = tuple_extract [[TUPLE]] : $(Int, Int), 0
// CHECK-NEXT: return [[TUPLE_ELT]] : $Int
// CHECK-NEXT: } // end sil function 'tuple_reg_promotion'
sil @tuple_reg_promotion : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int):
%1 = alloc_box $<τ_0_0> { var τ_0_0 } <(Int, Int)>
Expand Down Expand Up @@ -290,10 +291,14 @@ bb0(%0 : $Int32):
// CHECK-NEXT: return [[IL]]
return %25 : $Builtin.Int32
}
// CHECK: } // end sil function 'promote_alloc_stack'

// CHECK-LABEL: sil @copy_addr_to_load
// CHECK-LABEL: sil @copy_addr_to_load : $@convention(thin) (Int) -> Int {
// CHECK: bb0(%0 : $Int):
// CHECK-NEXT: return %0
// CHECK-NEXT: } // end sil function 'copy_addr_to_load'
sil @copy_addr_to_load : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int): // CHECK: bb0(%0 : $Int):
bb0(%0 : $Int):
%1 = alloc_stack $Int
store %0 to %1 : $*Int
%2 = alloc_stack $Int
Expand All @@ -304,14 +309,16 @@ bb0(%0 : $Int): // CHECK: bb0(%0 : $Int):

dealloc_stack %2 : $*Int
dealloc_stack %1 : $*Int
// CHECK-NEXT: return %0
return %3 : $Int
}

// rdar://15170149
// CHECK-LABEL: sil @store_to_copyaddr
sil @store_to_copyaddr : $(Bool) -> Bool {
bb0(%0 : $Bool): // CHECK: bb0(%0 :
// CHECK-LABEL: sil @store_to_copyaddr : $@convention(thin) (Bool) -> Bool {
// CHECK: bb0([[ARG:%.*]] :
// CHECK-NEXT: return [[ARG]]
// CHECK-NEXT: } // end sil function 'store_to_copyaddr'
sil @store_to_copyaddr : $@convention(thin) (Bool) -> Bool {
bb0(%0 : $Bool):
%1 = alloc_stack $Bool
store %0 to %1 : $*Bool
%3 = alloc_stack $Bool
Expand All @@ -321,7 +328,7 @@ bb0(%0 : $Bool): // CHECK: bb0(%0 :
%12 = load %1 : $*Bool
dealloc_stack %3 : $*Bool
dealloc_stack %1 : $*Bool
return %12 : $Bool // CHECK-NEXT: return %0
return %12 : $Bool
}

// CHECK-LABEL: sil @cross_block_load_promotion
Expand Down