Skip to content

Commit 5e16e75

Browse files
authored
Merge pull request #36056 from meg-gupta/rlefixes
Fix ownershipKind of the phi's that the SILSSAUpdater creates for RLE
2 parents 34223bc + 7445c5d commit 5e16e75

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ void SILPassManager::addFunctionToWorklist(SILFunction *F,
754754

755755
int NewLevel = 1;
756756
if (DerivedFrom) {
757+
if (!functionSelectionEmpty() && isFunctionSelectedForPrinting(F)) {
758+
llvm::dbgs() << F->getName() << " was derived from "
759+
<< DerivedFrom->getName() << "\n";
760+
}
757761
// When SILVerifyAll is enabled, individual functions are verified after
758762
// function passes are run upon them. This means that any functions created
759763
// by a function pass will not be verified after the pass runs. Thus

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)