Skip to content

Commit fccecbe

Browse files
committed
MandatoryPerformanceOptimizations: remove dead metatype instructions after specialization
Generic specialization drops metatype arguments and therefore exposes opportunities to remove dead metatype instructions. Instead of removing dead metatype instructions before specialization, try to remove them after specialization.
1 parent 5d5dbd9 commit fccecbe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ private func optimize(function: Function, _ context: FunctionPassContext) {
5858
switch instruction {
5959
case let apply as FullApplySite:
6060
inlineAndDevirtualize(apply: apply, context, simplifyCtxt)
61-
case let mt as MetatypeInst:
62-
if mt.isTriviallyDeadIgnoringDebugUses {
63-
simplifyCtxt.erase(instructionIncludingDebugUses: mt)
64-
}
6561
default:
6662
break
6763
}
6864
}
6965

7066
_ = context.specializeApplies(in: function, isMandatory: true)
7167

68+
removeUnusedMetatypeInstructions(in: function, context)
69+
7270
// If this is a just specialized function, try to optimize copy_addr, etc.
7371
if context.optimizeMemoryAccesses(in: function) {
7472
_ = context.eliminateDeadAllocations(in: function)
@@ -103,6 +101,15 @@ private func inlineAndDevirtualize(apply: FullApplySite, _ context: FunctionPass
103101
}
104102
}
105103

104+
private func removeUnusedMetatypeInstructions(in function: Function, _ context: FunctionPassContext) {
105+
for inst in function.instructions {
106+
if let mt = inst as? MetatypeInst,
107+
mt.isTriviallyDeadIgnoringDebugUses {
108+
context.erase(instructionIncludingDebugUses: mt)
109+
}
110+
}
111+
}
112+
106113
private func shouldInline(apply: FullApplySite, callee: Function) -> Bool {
107114
if callee.isTransparent {
108115
return true

0 commit comments

Comments
 (0)