From 900d61a3a61adfa8ce5fce09c3f3189d63c79c81 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Wed, 27 Mar 2024 10:49:48 -0700 Subject: [PATCH 1/2] [6.0] Add missed case to AssignAddressToDef. (#72617) Fixes #71744 Cherry-picked from a63078f279e76a64ae92f338c1875c3d372c540b rdar://135227988 --- lib/IRGen/LoadableByAddress.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From 4d3b6c877d307dd55a8d0ae63b4e7f3982240b13 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 4 Sep 2024 10:29:27 -0700 Subject: [PATCH 2/2] Test for PR #72617 --- test/IRGen/loadable_by_address_reg2mem.sil | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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 : $() +}