diff --git a/lib/IRGen/LoadableByAddress.cpp b/lib/IRGen/LoadableByAddress.cpp index f7c24f0ff230a..f9eda93f7b0a9 100644 --- a/lib/IRGen/LoadableByAddress.cpp +++ b/lib/IRGen/LoadableByAddress.cpp @@ -3798,6 +3798,15 @@ class AssignAddressToDef : SILInstructionVisitor { assignment.mapValueToAddress(origValue, newAddr); assignment.markForDeletion(bc); } + + void visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *bc) { + auto builder = assignment.getBuilder(bc->getIterator()); + auto opdAddr = assignment.getAddressForValue(bc->getOperand()); + auto newAddr = builder.createUncheckedAddrCast( + bc->getLoc(), opdAddr, bc->getType().getAddressType()); + assignment.mapValueToAddress(origValue, newAddr); + assignment.markForDeletion(bc); + } }; } // namespace diff --git a/test/IRGen/loadable_by_address_reg2mem.sil b/test/IRGen/loadable_by_address_reg2mem.sil index de19884a2af96..cc7e35f1ebcd3 100644 --- a/test/IRGen/loadable_by_address_reg2mem.sil +++ b/test/IRGen/loadable_by_address_reg2mem.sil @@ -24,6 +24,25 @@ struct X { var x16: Int } +struct X2 { + var x1 : Int + var x2 : Int + var x3 : Int + var x4: Int + var x5: Int + var x6: Int + var x7: Int + var x8: Int + var x9: Int + var x10: Int + var x11: Int + var x12: Int + var x13: Int + var x14: Int + var x15: Int + var x16: Int +} + struct Y { var y1 : X var y2: X @@ -269,3 +288,21 @@ bb0(%0 : $*C1, %1 : $*Small): %t = tuple () return %t : $() } + +// CHECK: sil @test13 +// CHECK: [[ADDR:%.*]] = unchecked_addr_cast %1 : $*X to $*Y +// CHECK: copy_addr [take] [[ADDR]] to [init] %2 : $*Y +// CHECK: } // end sil function 'test13' +sil @test13 : $@convention(thin) (@in X) -> () { +bb0(%0 : $*X): + %1 = alloc_stack $Y + %2 = alloc_stack $X + copy_addr [take] %0 to [init] %2 : $*X + %4 = load %2 : $*X + %7 = unchecked_bitwise_cast %4 : $X to $Y + store %7 to %1: $*Y + %13 = tuple () + dealloc_stack %2 : $*X + dealloc_stack %1 : $*Y + return %13 : $() +}