1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -gnone -emit-ir %s | %FileCheck %s
import Builtin
enum SinglePayloadSingleEmpty {
case EmptyCase
case DataCase(Builtin.Word)
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @select_enum_SinglePayloadSingleEmpty(ptr noalias nocapture dereferenceable({{.*}}) %0)
sil @select_enum_SinglePayloadSingleEmpty : $@convention(thin) (@in SinglePayloadSingleEmpty) -> () {
bb0(%0 : $*SinglePayloadSingleEmpty):
%1 = load %0 : $*SinglePayloadSingleEmpty
// CHECK: [[PAYLOAD1:%[0-9]+]] = load [[WORD_TY:(i32|i64)]], ptr
// CHECK: [[TAG1:%[0-9]+]] = load i1, ptr
%2 = integer_literal $Builtin.Int32, 2
%3 = integer_literal $Builtin.Int32, 3
// CHECK: select i1 [[TAG1]], i32 2, i32 3
%4 = select_enum %1 : $SinglePayloadSingleEmpty, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2, case #SinglePayloadSingleEmpty.DataCase!enumelt: %3 : $Builtin.Int32
// CHECK: [[V3:%[0-9]+]] = xor i1 [[TAG1]], true
// CHECK-NEXT: select i1 [[V3]], i32 3, i32 2
%5 = select_enum %1 : $SinglePayloadSingleEmpty, case #SinglePayloadSingleEmpty.DataCase!enumelt: %3, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2 : $Builtin.Int32
// CHECK: [[PAYLOAD0:%[0-9]+]] = load [[WORD_TY:(i32|i64)]], ptr
// CHECK: [[TAG0:%[0-9]+]] = load i1, ptr
// CHECK: select i1 [[TAG0]], i32 2, i32 3
%6 = select_enum_addr %0 : $*SinglePayloadSingleEmpty, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2, case #SinglePayloadSingleEmpty.DataCase!enumelt: %3 : $Builtin.Int32
// CHECK-NEXT: select i1 [[TAG1]], i32 2, i32 3
%7 = select_enum %1 : $SinglePayloadSingleEmpty, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2, default %3 : $Builtin.Int32
return undef : $()
}
enum TwoCasesNoPayload { case X, Y }
enum MyOptional<T> {
case some(T), none
}
sil @select_enum_TwoCasesNoPayload :$ @convention(thin) (@in TwoCasesNoPayload, @in MyOptional<TwoCasesNoPayload>) -> () {
bb0(%0 : $*TwoCasesNoPayload, %10 : $*MyOptional<TwoCasesNoPayload>):
// CHECK: [[PAYLOAD1:%[0-9]+]] = load i1, ptr
%1 = load %0 : $*TwoCasesNoPayload
%2 = integer_literal $Builtin.Int32, 2
%3 = integer_literal $Builtin.Int32, 42
// CHECK-NEXT: [[V2:%[0-9]+]] = icmp eq i1 [[PAYLOAD1]], false
// CHECK-NEXT: select i1 [[V2]], i32 2, i32 42
%4 = select_enum %1 : $TwoCasesNoPayload, case #TwoCasesNoPayload.X!enumelt: %2, case #TwoCasesNoPayload.Y!enumelt: %3 : $Builtin.Int32
// CHECK-NEXT: [[V2:%[0-9]+]] = icmp eq i1 [[PAYLOAD1]], true
// CHECK-NEXT: select i1 [[V2]], i32 42, i32 2
%5 = select_enum %1 : $TwoCasesNoPayload, case #TwoCasesNoPayload.Y!enumelt: %3, default %2 : $Builtin.Int32
// CHECK: [[PAYLOAD2:%[0-9]+]] = load i8, ptr
%11 = load %10 : $*MyOptional<TwoCasesNoPayload>
// CHECK-NEXT: [[V1:%[0-9]+]] = icmp eq i8 [[PAYLOAD2]], 2
// CHECK-NEXT: [[V2:%[0-9]+]] = xor i1 [[V1]], true
// CHECK: = select i1 [[V2]], i32 2, i32 42
%14 = select_enum %11 : $MyOptional<TwoCasesNoPayload>, case #MyOptional.some!enumelt: %2, case #MyOptional.none!enumelt: %3 : $Builtin.Int32
// CHECK-NEXT: [[V1:%[0-9]+]] = icmp eq i8 [[PAYLOAD2]], 2
// CHECK: = select i1 [[V1]], i32 42, i32 2
%15 = select_enum %11 : $MyOptional<TwoCasesNoPayload>, case #MyOptional.none!enumelt: %3, default %2 : $Builtin.Int32
return undef : $()
}
enum NoPayloadSingleton {
case One
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i1 @testOptionalOfNoPayloadSingleton(i8 %0)
sil @testOptionalOfNoPayloadSingleton : $@convention(thin) (MyOptional<NoPayloadSingleton>) -> Builtin.Int1 {
bb0(%0 : $MyOptional<NoPayloadSingleton>):
// CHECK: [[NATIVECCTRUNC:%.*]] = trunc i8 %0 to i1
// CHECK: [[NOT:%.*]] = xor i1 [[NATIVECCTRUNC]], true
// CHECK: ret i1 [[NOT]]
%4 = integer_literal $Builtin.Int1, -1 // users: %6, %7
%5 = integer_literal $Builtin.Int1, 0 // user: %6
%6 = select_enum %0 : $MyOptional<NoPayloadSingleton>, case #MyOptional.none!enumelt: %4, case #MyOptional.some!enumelt: %5 : $Builtin.Int1 // user: %7
%7 = builtin "xor_Int1"(%6 : $Builtin.Int1, %4 : $Builtin.Int1) : $Builtin.Int1 // user: %8
return %7 : $Builtin.Int1
}
|