Files
swift-mirror/test/SILOptimizer/alias-crash.sil
Erik Eckstein 4d20423e00 Optimizer: re-implement the RedundantLoadElimination pass in Swift
The new implementation has several benefits compared to the old C++ implementation:

* It is significantly simpler. It optimizes each load separately instead of all at once with bit-field based dataflow.
* It's using alias analysis more accurately which enables more loads to be optimized
* It avoids inserting additional copies in OSSA

The algorithm is a data flow analysis which starts at the original load and searches for preceding stores or loads by following the control flow in backward direction.
The preceding stores and loads provide the "available values" with which the original load can be replaced.
2023-07-21 07:19:56 +02:00

42 lines
1.2 KiB
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -redundant-load-elimination | %FileCheck %s
sil_stage canonical
import Builtin
struct MyStruct {
var value: Builtin.FPIEEE64
}
enum MyEnum {
case some(MyStruct)
case none
}
// Check if alias analysis can handle unchecked_take_enum_data_addr correctly
// and does not crash with a stack overflow.
// CHECK-LABEL: sil @testit
// CHECK: load
// CHECK: load
// CHECK: return
sil @testit : $@convention(method) (MyEnum) -> Builtin.FPIEEE64 {
bb0(%0 : $MyEnum):
%x1 = alloc_stack $MyEnum
store %0 to %x1 : $*MyEnum
%x7 = unchecked_take_enum_data_addr %x1 : $*MyEnum, #MyEnum.some!enumelt
%x8 = struct_element_addr %x7 : $*MyStruct, #MyStruct.value
%x11 = alloc_stack $MyEnum
store %0 to %x11 : $*MyEnum
%x19 = unchecked_take_enum_data_addr %x11 : $*MyEnum, #MyEnum.some!enumelt
%x20 = struct_element_addr %x19 : $*MyStruct, #MyStruct.value
%x24 = load %x20 : $*Builtin.FPIEEE64
%x27 = load %x8 : $*Builtin.FPIEEE64
%x28 = builtin "fsub_FPIEEE64"(%x27 : $Builtin.FPIEEE64, %x24 : $Builtin.FPIEEE64) : $Builtin.FPIEEE64
dealloc_stack %x11 : $*MyEnum
dealloc_stack %x1 : $*MyEnum
return %x28 : $Builtin.FPIEEE64
}