Files
swift-mirror/test/SILOptimizer/simplify_cfg_select_enum.sil
Andrew Trick 69a884565a Fix ownership of select_enum instruction
This instruction was given forwarding ownership in the original OSSA
implementation. That will obviously lead to memory leaks. Remove
ownership from this instruction and verify that it is never used for
non-trivial types.
2023-10-08 01:34:48 -07:00

61 lines
1.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_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
}