mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
rdar://149985633 Using at least Int8 here allows LLVM to apply more optimizations, reducing code size, avoiding stack allocations and as a result often eliminating complete stack frames.
57 lines
2.1 KiB
Plaintext
57 lines
2.1 KiB
Plaintext
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s --check-prefix=CHECK-%target-ptrsize
|
|
// REQUIRES: CPU=i386 || CPU=x86_64
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
|
|
enum ManyEmptyCases {
|
|
case A
|
|
case B
|
|
case C(Builtin.Int32)
|
|
}
|
|
|
|
// CHECK-LABEL-64: define{{( protected)?}} swiftcc i1 @select_enum_A(i64)
|
|
// CHECK-64: %2 = load i32, ptr %temp-coercion.coerced
|
|
// CHECK-64: %4 = load i8, ptr %3
|
|
// CHECK-64: [[PAYLOAD:%.*]] = icmp eq i32 %2, 0
|
|
// CHECK-64: [[TAG_TRUNC:%.*]] = icmp eq i8 %4, 1
|
|
// CHECK-64: [[EXTRA:%.*]] = and i1 [[TAG_TRUNC]], [[PAYLOAD]]
|
|
// CHECK-64: ret i1 [[EXTRA]]
|
|
|
|
// CHECK-LABEL-32: define{{( protected)?}} swiftcc i1 @select_enum_A(i32, i8) {{.*}}{
|
|
// CHECK-32: entry:
|
|
// CHECK-32: %2 = trunc i8 %1 to i1
|
|
// CHECK-32: %3 = icmp eq i32 %0, 0
|
|
// CHECK-32: %4 = and i1 %2, %3
|
|
// CHECK-32: ret i1 %4
|
|
sil @select_enum_A : $@convention(thin) (ManyEmptyCases) -> Builtin.Int1 {
|
|
entry(%0 : $ManyEmptyCases):
|
|
%4 = integer_literal $Builtin.Int1, -1 // user: %6
|
|
%5 = integer_literal $Builtin.Int1, 0 // user: %6
|
|
%6 = select_enum %0 : $ManyEmptyCases, case #ManyEmptyCases.A!enumelt: %4, default %5 : $Builtin.Int1
|
|
return %6 : $Builtin.Int1
|
|
}
|
|
|
|
// CHECK-LABEL-64: define{{( protected)?}} swiftcc i1 @select_enum_B(i64)
|
|
// CHECK-64: %2 = load i32, ptr %temp-coercion.coerced
|
|
// CHECK-64: %4 = load i8, ptr %3
|
|
// CHECK-64: [[PAYLOAD:%.*]] = icmp eq i32 %2, 1
|
|
// CHECK-64: [[TAG_TRUNC:%.*]] = icmp eq i8 %4, 1
|
|
// CHECK-64: [[EXTRA:%.*]] = and i1 [[TAG_TRUNC]], [[PAYLOAD]]
|
|
// CHECK-64: ret i1 [[EXTRA]]
|
|
|
|
// CHECK-LABEL-32: define{{( protected)?}} swiftcc i1 @select_enum_A(i32, i8) {{.*}}{
|
|
// CHECK-32: entry:
|
|
// CHECK-32: %2 = trunc i8 %1 to i1
|
|
// CHECK-32: %3 = icmp eq i32 %0, 1
|
|
// CHECK-32: %4 = and i1 %2, %3
|
|
// CHECK-32: ret i1 %4
|
|
sil @select_enum_B : $@convention(thin) (ManyEmptyCases) -> Builtin.Int1 {
|
|
entry(%0 : $ManyEmptyCases):
|
|
%4 = integer_literal $Builtin.Int1, -1 // user: %6
|
|
%5 = integer_literal $Builtin.Int1, 0 // user: %6
|
|
%6 = select_enum %0 : $ManyEmptyCases, case #ManyEmptyCases.B!enumelt: %4, default %5 : $Builtin.Int1
|
|
return %6 : $Builtin.Int1
|
|
}
|