Skip to content

Commit ddcce66

Browse files
committed
[pmo] Translate pred mem opt test for ownership and eliminate some unneeded Phis getting inserted by the SSA updater.
We already do the SSA updater optimization if we have an available value in the same block. If we do not have such an available value, we insert the Phis despite all of the available values being the same. The small change here just fixes that issue.
1 parent 820eb61 commit ddcce66

File tree

2 files changed

+1013
-0
lines changed

2 files changed

+1013
-0
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
583583
SILSSAUpdater updater(B.getModule());
584584
updater.Initialize(loadTy);
585585

586+
Optional<SILValue> singularValue;
586587
for (auto *insertPt : insertPts) {
587588
// Use the scope and location of the store at the insertion point.
588589
SILBuilderWithScope builder(insertPt, &insertedInsts);
@@ -594,10 +595,21 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
594595
eltVal = builder.emitCopyValueOperation(loc, eltVal);
595596
}
596597

598+
if (!singularValue.hasValue()) {
599+
singularValue = eltVal;
600+
} else if (*singularValue != eltVal) {
601+
singularValue = SILValue();
602+
}
603+
597604
// And then put the value into the SSA updater.
598605
updater.AddAvailableValue(insertPt->getParent(), eltVal);
599606
}
600607

608+
// If we only are tracking a singular value, we do not need to construct
609+
// SSA. Just return that value.
610+
if (auto val = singularValue.getValueOr(SILValue()))
611+
return val;
612+
601613
// Finally, grab the value from the SSA updater.
602614
SILValue result = updater.GetValueInMiddleOfBlock(B.getInsertionBB());
603615
assert(result.getOwnershipKind().isCompatibleWith(ValueOwnershipKind::Owned));
@@ -702,6 +714,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
702714
SILSSAUpdater updater(B.getModule());
703715
updater.Initialize(loadTy);
704716

717+
Optional<SILValue> singularValue;
705718
for (auto *i : insertPts) {
706719
// Use the scope and location of the store at the insertion point.
707720
SILBuilderWithScope builder(i, &insertedInsts);
@@ -711,9 +724,20 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
711724
!builder.hasOwnership() ||
712725
eltVal.getOwnershipKind().isCompatibleWith(ValueOwnershipKind::Owned));
713726

727+
if (!singularValue.hasValue()) {
728+
singularValue = eltVal;
729+
} else if (*singularValue != eltVal) {
730+
singularValue = SILValue();
731+
}
732+
714733
updater.AddAvailableValue(i->getParent(), eltVal);
715734
}
716735

736+
// If we only are tracking a singular value, we do not need to construct
737+
// SSA. Just return that value.
738+
if (auto val = singularValue.getValueOr(SILValue()))
739+
return val;
740+
717741
// Finally, grab the value from the SSA updater.
718742
SILValue eltVal = updater.GetValueInMiddleOfBlock(B.getInsertionBB());
719743
assert(!B.hasOwnership() ||

0 commit comments

Comments
 (0)