-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LICM: hoist calls to global_init functions
Global initializers are executed only once. Therefore it's possible to hoist such an initializer call to a loop pre-header - in case there are no conflicting side-effects in the loop before the call. Also, the call must post-dominate the loop pre-header. Otherwise it would be executed speculatively.
- Loading branch information
Showing
5 changed files
with
324 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift -O %s -o %t/a.out | ||
// RUN: %target-run %t/a.out | %FileCheck %s | ||
|
||
// REQUIRES: executable_test | ||
|
||
struct Teststruct { | ||
static let s = Teststruct() | ||
|
||
@inline(never) | ||
init() { | ||
let set = Set<String>() | ||
for _ in set { | ||
// Check that the global initializer is not hoisted out of this loop, | ||
// resulting in a dispatch_once re-retrance crash. | ||
_ = Teststruct.s | ||
} | ||
} | ||
} | ||
|
||
// CHECK: Teststruct | ||
print(Teststruct.s) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.