Files
swift-mirror/test/SILOptimizer/simplify_cfg_select_enum.sil
Nate Chandler e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00

95 lines
2.5 KiB
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -jumpthread-simplify-cfg | %FileCheck %s
// Two select_enum instructions must not be considered as the same "condition",
// even if they have the same enum operand.
// This test checks that SimplifyCFG does not remove a dominated terminator with
// such a condition.
sil_stage canonical
import Builtin
import Swift
enum E {
case A
case B
case C
}
class Base { }
class Derived1 : Base { }
class Derived2 : Base { }
// CHECK-LABEL: sil @test_checked_cast_br
// CHECK: select_enum
// CHECK: checked_cast_br
// CHECK: integer_literal $Builtin.Int64, 1
// CHECK: select_enum
// CHECK: checked_cast_br
// CHECK: integer_literal $Builtin.Int64, 2
// CHECK: integer_literal $Builtin.Int64, 3
// CHECK: return
sil @test_checked_cast_br : $@convention(thin) (E, @owned Base, @owned Base, @owned Base, @owned Base) -> Builtin.Int64 {
bb0(%0 : $E, %1 : $Base, %2 : $Base, %3 : $Base, %4 : $Base):
%s1 = select_enum %0 : $E, case #E.A!enumelt: %1, default %2 : $Base
checked_cast_br Base in %s1 : $Base to Derived1, bb1, bb2
bb1(%a1 : $Derived1):
%i1 = integer_literal $Builtin.Int64, 1
br bb5(%i1 : $Builtin.Int64)
bb2:
%s2 = select_enum %0 : $E, case #E.B!enumelt: %3, default %4 : $Base
checked_cast_br Base in %s2 : $Base to Derived1, bb3, bb4
bb3(%a2 : $Derived1):
%i2 = integer_literal $Builtin.Int64, 2
br bb5(%i2 : $Builtin.Int64)
bb4:
%i3 = integer_literal $Builtin.Int64, 3
br bb5(%i3 : $Builtin.Int64)
bb5(%a3 : $Builtin.Int64):
return %a3 : $Builtin.Int64
}
// CHECK-LABEL: sil @test_cond_br
// CHECK: select_enum
// CHECK: cond_br
// CHECK: integer_literal $Builtin.Int64, 1
// CHECK: select_enum
// CHECK: cond_br
// CHECK: integer_literal $Builtin.Int64, 2
// CHECK: integer_literal $Builtin.Int64, 3
// CHECK: return
sil @test_cond_br : $@convention(thin) (E, @owned Base, @owned Base, @owned Base, @owned Base) -> Builtin.Int64 {
bb0(%0 : $E, %1 : $Base, %2 : $Base, %3 : $Base, %4 : $Base):
%t1 = integer_literal $Builtin.Int1, -1
%f1 = integer_literal $Builtin.Int1, 0
%s1 = select_enum %0 : $E, case #E.A!enumelt: %t1, default %f1 : $Builtin.Int1
cond_br %s1, bb1, bb2
bb1:
%i1 = integer_literal $Builtin.Int64, 1
br bb5(%i1 : $Builtin.Int64)
bb2:
%s2 = select_enum %0 : $E, case #E.B!enumelt: %t1, default %f1 : $Builtin.Int1
cond_br %s2, bb3, bb4
bb3:
%i2 = integer_literal $Builtin.Int64, 2
br bb5(%i2 : $Builtin.Int64)
bb4:
%i3 = integer_literal $Builtin.Int64, 3
br bb5(%i3 : $Builtin.Int64)
bb5(%a3 : $Builtin.Int64):
return %a3 : $Builtin.Int64
}