Skip to content

Commit 7445c5d

Browse files
committed
Fix ownershipKind of the phi's that the SILSSAUpdater creates for RLE
When the available values have none ownership on one side and owned on the other, we need to merge their ownershipKind for their phi argument
1 parent 83b4aeb commit 7445c5d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,12 +1328,20 @@ SILValue RLEContext::computePredecessorLocationValue(SILBasicBlock *BB,
13281328
Values.push_back({CurBB, LSValue::reduce(L, &BB->getModule(), LSValues, IPt)});
13291329
}
13301330

1331+
auto ownershipRange =
1332+
makeTransformRange(llvm::make_range(Values.begin(), Values.end()),
1333+
[](std::pair<SILBasicBlock *, SILValue> v) {
1334+
return v.second.getOwnershipKind();
1335+
});
1336+
1337+
auto mergedOwnershipKind = ValueOwnershipKind::merge(ownershipRange);
1338+
13311339
// Finally, collect all the values for the SILArgument, materialize it using
13321340
// the SSAUpdater.
13331341
Updater.initialize(
13341342
L.getType(&BB->getModule(), TypeExpansionContext(*BB->getParent()))
13351343
.getObjectType(),
1336-
Values[0].second.getOwnershipKind());
1344+
mergedOwnershipKind);
13371345

13381346
SmallVector<SILPhiArgument *, 8> insertedPhis;
13391347
Updater.setInsertedPhis(&insertedPhis);

test/SILOptimizer/redundant_load_elim_ossa_complex.sil

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct TripleKlass {
2323
var val3 : Klass
2424
}
2525

26+
public enum FakeOptional<T> {
27+
case none
28+
case some(T)
29+
}
2630
sil [ossa] @use_klass : $@convention(thin) (@owned Klass) -> ()
2731
sil [ossa] @use_nontrivialstruct : $@convention(thin) (@owned NonTrivialStruct) -> ()
2832

@@ -818,3 +822,28 @@ bb9:
818822
return %val1 : $Klass
819823
}
820824

825+
// CHECK-LABEL: @rle_ownershipkindmergetest :
826+
// CHECK-NOT: load
827+
// CHECK-LABEL: end sil function 'rle_ownershipkindmergetest'
828+
sil [ossa] @rle_ownershipkindmergetest : $@convention(thin) (@owned FakeOptional<Klass>) -> () {
829+
bb0(%0 : @owned $FakeOptional<Klass>):
830+
%3 = alloc_stack $FakeOptional<Klass>
831+
store %0 to [init] %3 : $*FakeOptional<Klass>
832+
cond_br undef, bb1, bb2
833+
834+
bb1:
835+
%4 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
836+
store %4 to [assign] %3 : $*FakeOptional<Klass>
837+
br bb3
838+
839+
bb2:
840+
br bb3
841+
842+
bb3:
843+
%49 = load [copy] %3 : $*FakeOptional<Klass>
844+
destroy_value %49 : $FakeOptional<Klass>
845+
destroy_addr %3 : $*FakeOptional<Klass>
846+
dealloc_stack %3 : $*FakeOptional<Klass>
847+
%res = tuple ()
848+
return %res : $()
849+
}

0 commit comments

Comments
 (0)