Skip to content

Commit

Permalink
Merge pull request #23631 from aschwaighofer/irgen_single_payload_no_…
Browse files Browse the repository at this point in the history
…extra_inhabitant_fix

IRGen: Test all of the payload bits if there are not extra inhabitants
  • Loading branch information
aschwaighofer authored Mar 29, 2019
2 parents aec5756 + 3906135 commit ebef3c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,11 +1879,15 @@ namespace {
// more no-payload case than extra inhabitants in the payload. This could
// be slightly generalized to cases where there's multiple tag bits and
// exactly one no-payload case in the highest used tag value.
unsigned extraInhabitantCount = getFixedExtraInhabitantCount(IGF.IGM);
if (!tagBits ||
ElementsWithNoPayload.size() != getFixedExtraInhabitantCount(IGF.IGM)+1)
payloadResult = payload.emitCompare(IGF,
ti.getFixedExtraInhabitantMask(IGF.IGM),
payloadTag);
ElementsWithNoPayload.size() != extraInhabitantCount + 1) {
payloadResult = payload.emitCompare(
IGF,
extraInhabitantCount == 0 ? APInt::getAllOnesValue(PayloadBitCount)
: ti.getFixedExtraInhabitantMask(IGF.IGM),
payloadTag);
}

// If any tag bits are present, they must match.
llvm::Value *tagResult = nullptr;
Expand Down
18 changes: 18 additions & 0 deletions test/IRGen/enum.sil
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@ enum SinglePayloadNoXI2 {
case u
}

// CHECK-32: define{{( dllexport)?}}{{( protected)?}} swiftcc i1 @select_enum([[WORD:i32]], i8)
// CHECK-64: define{{( dllexport)?}}{{( protected)?}} swiftcc i1 @select_enum([[WORD:i64]], i8)
// CHECK: entry:
// CHECK: [[TAG:%.*]] = trunc i8 %1 to i1
// CHECK: [[PAYLOAD:%.*]] = icmp eq [[WORD]] %0, 1
// CHECK: [[MATCHES:%.*]] = and i1 [[TAG]], [[PAYLOAD]]
// CHECK: [[RES:%.*]] = select i1 [[MATCHES]], i1 false, i1 true
// CHECK: ret i1 [[RES]]
// CHECK: }

sil @select_enum : $@convention(method) (SinglePayloadNoXI2) -> Builtin.Int1 {
bb0(%0 : $SinglePayloadNoXI2):
%2 = integer_literal $Builtin.Int1, 0
%3 = integer_literal $Builtin.Int1, -1
%4 = select_enum %0 : $SinglePayloadNoXI2, case #SinglePayloadNoXI2.z!enumelt: %2, default %3 : $Builtin.Int1
return %4 : $Builtin.Int1
}

// CHECK-64: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_no_xi_switch([[WORD:i64]], i8) {{.*}} {
// CHECK-32: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_no_xi_switch([[WORD:i32]], i8) {{.*}} {
sil @single_payload_no_xi_switch : $@convention(thin) (SinglePayloadNoXI2) -> () {
Expand Down

0 comments on commit ebef3c5

Please sign in to comment.