Skip to content

Add SILCombine+SimplifyCFG passes between the ClosureSpecializer (and… #2020

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
Apr 1, 2016
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
5 changes: 5 additions & 0 deletions lib/SILOptimizer/PassManager/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ void swift::runSILOptimizationPasses(SILModule &Module) {
// Speculate virtual call targets.
PM.addSpeculativeDevirtualization();

// There should be at least one SILCombine+SimplifyCFG between the
// ClosureSpecializer, etc. and the last inliner. Cleaning up after these
// passes can expose more inlining opportunities.
AddSimplifyCFGSILCombine(PM);

// We do this late since it is a pass like the inline caches that we only want
// to run once very late. Make sure to run at least one round of the ARC
// optimizer after this.
Expand Down
23 changes: 23 additions & 0 deletions test/SILOptimizer/closure_spec_and_inline.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-swift-frontend -parse-as-library -O -module-name=test %s -emit-sil | FileCheck %s

func closure(a: Int, b: Int) -> Bool {
return a < b
}

// Check that closure() is inlined into call_closure after call_closure is
// specialized for it.

// CHECK-LABEL: sil shared [noinline] @_TTSf1n_n_cl27_TF4test7closureFTSi1bSi_Sb___TF4test12call_closureFTSiSiFTSiSi_Sb_Sb
// CHECK-NOT: apply
// CHECK: builtin "cmp_slt_Int64"
// CHECK-NOT: apply
// CHECK: return
@inline(never)
func call_closure(a: Int, _ b: Int, _ f: (Int , Int) -> Bool) -> Bool {
return f(a, b)
}

public func testit() -> Bool {
return call_closure(0, 1, closure)
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swiftc_driver -module-name devirt_single_module_in_multiple_files -O %s %S/Inputs/BaseProblem.swift %S/Inputs/Problems.swift -parse-as-library -emit-sil 2>&1 | FileCheck %s
// RUN: %target-swiftc_driver -module-name devirt_single_module_in_multiple_files -O %s %S/Inputs/BaseProblem.swift %S/Inputs/Problems.swift -parse-as-library -Xllvm -sil-disable-pass="Performance Inliner" -emit-sil 2>&1 | FileCheck %s

public func test() {
let e = Evaluator()
Expand Down