Files
swift-mirror/test/SILOptimizer/simplify_cfg_args_crash.sil
Meghana Gupta 5bfa560b35 Update SimplifyCFG's replacement of phi with its incoming value
Previously we replaced phi with its incoming values when all incoming values were the same.
If the phi had itself as incoming value, it wasn't optimized. This PR handles such cases.
2024-04-03 10:46:05 -07:00

81 lines
1.6 KiB
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -simplify-bb-args -sroa-bb-args | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
import SwiftShims
enum E {
case A
case B
}
// Check that we don't crash in simplifyToSelectValue (rdar://problem/20037686)
// CHECK-LABEL: @test
sil public @test : $@convention(thin) (Builtin.Int64, @inout E) -> () {
bb0(%0 : $Builtin.Int64, %x : $*E):
%1 = integer_literal $Builtin.Int64, 0
%2 = builtin "cmp_eq_Int64"(%0 : $Builtin.Int64, %1 : $Builtin.Int64) : $Builtin.Int1
cond_br %2, bb3, bb1
bb1:
%4 = enum $E, #E.A!enumelt
br bb2(%4 : $E)
bb2(%6 : $E):
store %6 to %x : $*E
br bb3
bb3:
%8 = tuple ()
return %8 : $()
}
// Verify that we do not crash in argument splitting (rdar://problem/25008398).
class C {
@_hasStorage let x: Builtin.Int32
init()
}
struct Pair {
@_hasStorage let first: C
@_hasStorage let second: C
}
// CHECK-LABEL: @simplify_args_crash
sil @simplify_args_crash : $@convention(thin) (Pair) -> () {
bb0(%1 : $Pair):
// CHECK: bb0
// CHECK-NEXT: br bb1
br bb1(%1 : $Pair)
bb1(%2 : $Pair):
br bb1(%2 : $Pair)
}
// CHECK-LABEL: sil [ossa] @redundant_phi_unreachable : $@convention(thin) () -> () {
// CHECK: bb1({{.*}}):
// CHECK-LABEL: } // end sil function 'redundant_phi_unreachable'
sil [ossa] @redundant_phi_unreachable : $@convention(thin) () -> () {
bb0:
%1 = integer_literal $Builtin.Int32, 37
br bb3
bb1(%3 : $Builtin.Int32):
cond_br undef, bb2, bb4
bb2:
br bb1(%3 : $Builtin.Int32)
bb4:
br bb3
bb3:
%r = tuple()
return %r : $()
}