Skip to content

Commit 794964a

Browse files
committed
MandatoryRedundantLoadElimination: remove redundant loads from global variables
This is important in the initializer functions of globals. It can enabled static initialization of globals in more cases.
1 parent 1100108 commit 794964a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/RedundantLoadElimination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private extension LoadingInstruction {
210210
return false
211211
}
212212
switch address.accessBase {
213-
case .box, .stack:
213+
case .box, .stack, .global:
214214
break
215215
default:
216216
return false

test/SILOptimizer/mandatory-redundant-load-elim.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,3 +1922,17 @@ bb0(%0 : $MyInt, %1 : @guaranteed $Foo, %2 : @guaranteed $Baz):
19221922
dealloc_stack %3 : $*MyInt
19231923
return %38 : $MyInt
19241924
} // end sil function '$s27capture_promotion_ownership05test_a1_B0SiycyFSiycfU_Tf2iii_n'
1925+
1926+
sil_global @gi : $Int
1927+
1928+
// CHECK: sil [ossa] @test_global :
1929+
// CHECK-NOT: load
1930+
// CHECK: return %0
1931+
// CHECK: } // end sil function 'test_global'
1932+
sil [ossa] @test_global : $@convention(thin) (Int) -> Int {
1933+
bb0(%0 : $Int):
1934+
%1 = global_addr @gi : $*Int
1935+
store %0 to [trivial] %1
1936+
%3 = load [trivial] %1
1937+
return %3
1938+
}

0 commit comments

Comments
 (0)