Skip to content

Commit 12484ff

Browse files
authored
Merge pull request #74842 from meg-gupta/addopenpackedgecase
Fix isTriviallyDuplicatable to handle open_pack_element
2 parents 30b88e7 + 5282194 commit 12484ff

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,10 @@ bool SILInstruction::isTriviallyDuplicatable() const {
14181418

14191419
if (isa<OpenExistentialAddrInst>(this) || isa<OpenExistentialRefInst>(this) ||
14201420
isa<OpenExistentialMetatypeInst>(this) ||
1421-
isa<OpenExistentialValueInst>(this) || isa<OpenExistentialBoxInst>(this) ||
1422-
isa<OpenExistentialBoxValueInst>(this)) {
1421+
isa<OpenExistentialValueInst>(this) ||
1422+
isa<OpenExistentialBoxInst>(this) ||
1423+
isa<OpenExistentialBoxValueInst>(this) ||
1424+
isa<OpenPackElementInst>(this)) {
14231425
// Don't know how to duplicate these properly yet. Inst.clone() per
14241426
// instruction does not work. Because the follow-up instructions need to
14251427
// reuse the same archetype uuid which would only work if we used a

lib/SILOptimizer/Utils/LoopUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ bool swift::canDuplicateLoopInstruction(SILLoop *L, SILInstruction *I) {
280280

281281
// We can't have a phi of two openexistential instructions of different UUID.
282282
if (isa<OpenExistentialAddrInst>(I) || isa<OpenExistentialRefInst>(I) ||
283-
isa<OpenExistentialMetatypeInst>(I) ||
284-
isa<OpenExistentialValueInst>(I) || isa<OpenExistentialBoxInst>(I) ||
285-
isa<OpenExistentialBoxValueInst>(I)) {
283+
isa<OpenExistentialMetatypeInst>(I) || isa<OpenExistentialValueInst>(I) ||
284+
isa<OpenExistentialBoxInst>(I) || isa<OpenExistentialBoxValueInst>(I) ||
285+
isa<OpenPackElementInst>(I)) {
286286
SingleValueInstruction *OI = cast<SingleValueInstruction>(I);
287287
for (auto *UI : OI->getUses())
288288
if (!L->contains(UI->getUser()))

test/SILOptimizer/looprotate.sil

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,39 @@ bb3:
465465
%1 = tuple ()
466466
return %1 : $()
467467
}
468+
469+
struct Wrapper : Sendable {
470+
let id: Int
471+
}
472+
473+
// CHECK-LABEL: sil @test_open_pack_element :
474+
// CHECK: bb0{{.*}}:
475+
// CHECK-NOT: open_pack_element
476+
// CHECK: br bb2
477+
// CHECK: } // end sil function 'test_open_pack_element'
478+
sil @test_open_pack_element : $@convention(thin) (@pack_guaranteed Pack{KeyPath<Wrapper, Wrapper>}) -> () {
479+
bb0(%0 : $*Pack{KeyPath<Wrapper, Wrapper>}):
480+
%5 = alloc_stack $KeyPath<Wrapper, Wrapper>
481+
%6 = integer_literal $Builtin.Word, 0 // user: %8
482+
br bb2(%6 : $Builtin.Word)
483+
484+
bb1:
485+
dealloc_stack %5 : $*KeyPath<Wrapper, Wrapper>
486+
%35 = tuple ()
487+
return %35 : $()
488+
489+
bb2(%37 : $Builtin.Word):
490+
%38 = dynamic_pack_index %37 of $Pack{KeyPath<Wrapper, Wrapper>}
491+
%39 = open_pack_element %38 of <Topic, each Value where Topic : AnyObject, repeat each Value : Sendable> at <Wrapper, Pack{Wrapper}>, shape $each Value, uuid "94218A22-3595-11EF-8496-4EA2A866E4C5"
492+
%40 = pack_element_get %38 of %0 : $*Pack{KeyPath<Wrapper, Wrapper>} as $*KeyPath<Wrapper, @pack_element("94218A22-3595-11EF-8496-4EA2A866E4C5") each Value>
493+
%41 = unchecked_addr_cast %5 : $*KeyPath<Wrapper, Wrapper> to $*KeyPath<Wrapper, @pack_element("94218A22-3595-11EF-8496-4EA2A866E4C5") each Value>
494+
%42 = load %40 : $*KeyPath<Wrapper, @pack_element("94218A22-3595-11EF-8496-4EA2A866E4C5") each Value>
495+
store %42 to %41 : $*KeyPath<Wrapper, @pack_element("94218A22-3595-11EF-8496-4EA2A866E4C5") each Value>
496+
%7 = integer_literal $Builtin.Word, 1 // users: %45, %44
497+
%44 = builtin "add_Word"(%37 : $Builtin.Word, %7 : $Builtin.Word) : $Builtin.Word // users: %48, %45
498+
cond_br undef, bb1, bb3
499+
500+
bb3:
501+
strong_retain %42 : $KeyPath<Wrapper, @pack_element("94218A22-3595-11EF-8496-4EA2A866E4C5") each Value>
502+
br bb2(%44 : $Builtin.Word)
503+
}

0 commit comments

Comments
 (0)