| // RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -gnone -emit-ir %s | %FileCheck %s |
| |
| import Builtin |
| |
| enum SinglePayloadSingleEmpty { |
| case EmptyCase |
| case DataCase(Builtin.Word) |
| } |
| |
| // CHECK-LABEL: define{{( protected)?}} swiftcc void @select_enum_SinglePayloadSingleEmpty(%T11select_enum013SinglePayloadC5EmptyO* noalias nocapture dereferenceable({{.*}})) |
| sil @select_enum_SinglePayloadSingleEmpty : $@convention(thin) (@in SinglePayloadSingleEmpty) -> () { |
| bb0(%0 : $*SinglePayloadSingleEmpty): |
| %1 = load %0 : $*SinglePayloadSingleEmpty |
| // CHECK: [[PAYLOAD1:%[0-9]+]] = load [[WORD_TY:(i32|i64)]], [[WORD_TY:(i32|i64)]]* |
| // CHECK: [[TAG1:%[0-9]+]] = load i1, i1* |
| |
| %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.1: %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.1: %3, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2 : $Builtin.Int32 |
| |
| // CHECK: [[PAYLOAD0:%[0-9]+]] = load [[WORD_TY]], [[WORD_TY]]* |
| // CHECK: [[TAG0:%[0-9]+]] = load i1, i1* |
| |
| // CHECK: select i1 [[TAG0]], i32 2, i32 3 |
| %6 = select_enum_addr %0 : $*SinglePayloadSingleEmpty, case #SinglePayloadSingleEmpty.EmptyCase!enumelt: %2, case #SinglePayloadSingleEmpty.DataCase!enumelt.1: %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, i1* |
| %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, i8* |
| %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.1: %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{{( protected)?}} swiftcc i1 @testOptionalOfNoPayloadSingleton(i8) |
| 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.1: %5 : $Builtin.Int1 // user: %7 |
| %7 = builtin "xor_Int1"(%6 : $Builtin.Int1, %4 : $Builtin.Int1) : $Builtin.Int1 // user: %8 |
| return %7 : $Builtin.Int1 |
| } |