Skip to content

Commit 7c46a4d

Browse files
committed
LICM: don't let cond_fail prevent hoisting initializations of global variables
And fix the corresponding test file
1 parent 0d35c42 commit 7c46a4d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ static bool mayConflictWithGlobalInit(AliasAnalysis *AA,
231231
if (auto *LI = dyn_cast<LoadInst>(sideEffectInst)) {
232232
return AA->mayWriteToMemory(globalInitCall, LI->getOperand());
233233
}
234+
if (isa<CondFailInst>(sideEffectInst))
235+
return false;
234236
return true;
235237
}
236238

test/SILOptimizer/inline_addressor.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ var totalsum = nonTrivialInit(true)
99
// 1) hoisted out of the loop (by GlobalOpt) and
1010
// 2) inlined
1111

12-
//CHECK-LABEL: sil {{.*}}testit
13-
//CHECK: {{^bb0}}
14-
//CHECK: WZ
15-
//CHECK-NOT: {{^bb0}}
16-
//CHECK: {{^bb1}}
17-
//CHECK-NOT: WZ
18-
//CHECK-NOT: totalsum
19-
//CHECK-NOT: inputval
12+
// CHECK-LABEL: sil hidden @$s16inline_addressor6testityySiF :
13+
// CHECK: {{^bb0(.*):}}
14+
// CHECK-DAG: function_ref @$s16inline_addressor8totalsum_WZ :
15+
// CHECK-DAG: builtin "once"
16+
// CHECK-DAG: function_ref @$s16inline_addressor8inputval_WZ :
17+
// CHECK-DAG: builtin "once"
18+
// CHECK: {{^bb1:}}
19+
// CHECK-NOT: "once"
20+
// CHECK-NOT: apply
21+
// CHECK: } // end sil function '$s16inline_addressor6testityySiF'
2022
func testit(_ x: Int) {
2123
for _ in 0...10000000 {
2224
totalsum += inputval

0 commit comments

Comments
 (0)