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.
This commit is contained in:
Erik Eckstein
2025-10-17 09:16:53 +02:00
parent 110010856f
commit 794964adba
2 changed files with 15 additions and 1 deletions

View File

@@ -210,7 +210,7 @@ private extension LoadingInstruction {
return false
}
switch address.accessBase {
case .box, .stack:
case .box, .stack, .global:
break
default:
return false

View File

@@ -1922,3 +1922,17 @@ bb0(%0 : $MyInt, %1 : @guaranteed $Foo, %2 : @guaranteed $Baz):
dealloc_stack %3 : $*MyInt
return %38 : $MyInt
} // end sil function '$s27capture_promotion_ownership05test_a1_B0SiycyFSiycfU_Tf2iii_n'
sil_global @gi : $Int
// CHECK: sil [ossa] @test_global :
// CHECK-NOT: load
// CHECK: return %0
// CHECK: } // end sil function 'test_global'
sil [ossa] @test_global : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int):
%1 = global_addr @gi : $*Int
store %0 to [trivial] %1
%3 = load [trivial] %1
return %3
}