Skip to content

Commit cb421d7

Browse files
committed
Add comments to SwiftCompilerSources for shouldExpand()
1 parent 2503384 commit cb421d7

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ let deadStoreElimination = FunctionPass(name: "dead-store-elimination") {
7575
}
7676

7777
private func tryEliminate(store: StoreInst, complexityBudget: inout Int, _ context: FunctionPassContext) {
78+
// Check if the type can be expanded without a significant increase to code size.
7879
if !store.hasValidOwnershipForDeadStoreElimination || !store.source.type.shouldExpand(context) {
7980
return
8081
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/RedundantLoadElimination.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ private func eliminateRedundantLoads(in function: Function, ignoreArrays: Bool,
9797
{
9898
continue
9999
}
100+
// Check if the type can be expanded without a significant increase to
101+
// code size.
100102
if !load.type.shouldExpand(context) {
101103
continue
102104
}

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,11 @@ extension CheckedCastAddrBranchInst {
811811
}
812812

813813
extension Type {
814+
/// True if a type can be expanded without a significant increase to code
815+
/// size.
816+
///
817+
/// False if expanding a type is invalid. For example, expanding a
818+
/// struct-with-deinit drops the deinit.
814819
func shouldExpand(_ context: some Context) -> Bool {
815820
if !context.options.useAggressiveReg2MemForCodeSize {
816821
return true

0 commit comments

Comments
 (0)