Skip to content

Commit 05ffb67

Browse files
authored
Merge pull request #74847 from meg-gupta/openpackelemcp
[6.0] Fix isTriviallyDuplicatable to handle open_pack_element
2 parents d3f7362 + 95abf2e commit 05ffb67

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
@@ -1414,8 +1414,10 @@ bool SILInstruction::isTriviallyDuplicatable() const {
14141414

14151415
if (isa<OpenExistentialAddrInst>(this) || isa<OpenExistentialRefInst>(this) ||
14161416
isa<OpenExistentialMetatypeInst>(this) ||
1417-
isa<OpenExistentialValueInst>(this) || isa<OpenExistentialBoxInst>(this) ||
1418-
isa<OpenExistentialBoxValueInst>(this)) {
1417+
isa<OpenExistentialValueInst>(this) ||
1418+
isa<OpenExistentialBoxInst>(this) ||
1419+
isa<OpenExistentialBoxValueInst>(this) ||
1420+
isa<OpenPackElementInst>(this)) {
14191421
// Don't know how to duplicate these properly yet. Inst.clone() per
14201422
// instruction does not work. Because the follow-up instructions need to
14211423
// 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
@@ -279,9 +279,9 @@ bool swift::canDuplicateLoopInstruction(SILLoop *L, SILInstruction *I) {
279279

280280
// We can't have a phi of two openexistential instructions of different UUID.
281281
if (isa<OpenExistentialAddrInst>(I) || isa<OpenExistentialRefInst>(I) ||
282-
isa<OpenExistentialMetatypeInst>(I) ||
283-
isa<OpenExistentialValueInst>(I) || isa<OpenExistentialBoxInst>(I) ||
284-
isa<OpenExistentialBoxValueInst>(I)) {
282+
isa<OpenExistentialMetatypeInst>(I) || isa<OpenExistentialValueInst>(I) ||
283+
isa<OpenExistentialBoxInst>(I) || isa<OpenExistentialBoxValueInst>(I) ||
284+
isa<OpenPackElementInst>(I)) {
285285
SingleValueInstruction *OI = cast<SingleValueInstruction>(I);
286286
for (auto *UI : OI->getUses())
287287
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)