Skip to content

Optimizer: add an additional DeadObjectElimination at the end of the pipeline #66698

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

Merged
merged 1 commit into from
Jun 16, 2023
Merged
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
3 changes: 3 additions & 0 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ static void addLowLevelPassPipeline(SILPassPipelinePlan &P) {
P.addObjectOutliner();
P.addDeadStoreElimination();

// dead-store-elimination can expose opportunities for dead object elimination.
P.addDeadObjectElimination();

// We've done a lot of optimizations on this function, attempt to FSO.
P.addFunctionSignatureOpts();
P.addComputeEscapeEffects();
Expand Down
47 changes: 47 additions & 0 deletions test/SILOptimizer/dead_alloc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %target-swift-frontend -O -emit-sil -parse-as-library %s | %FileCheck %s

// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
// REQUIRES: swift_in_compiler

protocol E {
func f() -> Bool
}

protocol P {
associatedtype A = Int
}

public struct X : P, E {
func f() -> Bool { return true }
}

func g<T : P>(_ x : T) -> Bool {
if let y = x as? E { return y.f() }
return false
}

// Check that this function can be completely constant folded and no alloc_stack remains.

// CHECK-LABEL: sil @$s10dead_alloc0A10AllocStackySbAA1XVF :
// CHECK: bb0({{.*}}):
// CHECK-NEXT: debug_value
// CHECK-NEXT: integer_literal
// CHECK-NEXT: struct
// CHECK-NEXT: return
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A10AllocStackySbAA1XVF'
public func deadAllocStack(_ x: X) -> Bool {
return g(x)
}

public class C<T> {
let x: String = "123"
}

// CHECK-LABEL: sil @$s10dead_alloc0A13ClassInstanceyyF :
// CHECK: bb0:
// CHECK-NEXT: tuple
// CHECK-NEXT: return
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A13ClassInstanceyyF'
public func deadClassInstance() {
let _ = C<Int>()
}
32 changes: 0 additions & 32 deletions test/SILOptimizer/dead_alloc_stack.swift

This file was deleted.