@@ -583,6 +583,7 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
583
583
SILSSAUpdater updater (B.getModule ());
584
584
updater.Initialize (loadTy);
585
585
586
+ Optional<SILValue> singularValue;
586
587
for (auto *insertPt : insertPts) {
587
588
// Use the scope and location of the store at the insertion point.
588
589
SILBuilderWithScope builder (insertPt, &insertedInsts);
@@ -594,10 +595,21 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
594
595
eltVal = builder.emitCopyValueOperation (loc, eltVal);
595
596
}
596
597
598
+ if (!singularValue.hasValue ()) {
599
+ singularValue = eltVal;
600
+ } else if (*singularValue != eltVal) {
601
+ singularValue = SILValue ();
602
+ }
603
+
597
604
// And then put the value into the SSA updater.
598
605
updater.AddAvailableValue (insertPt->getParent (), eltVal);
599
606
}
600
607
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
+
601
613
// Finally, grab the value from the SSA updater.
602
614
SILValue result = updater.GetValueInMiddleOfBlock (B.getInsertionBB ());
603
615
assert (result.getOwnershipKind ().isCompatibleWith (ValueOwnershipKind::Owned));
@@ -702,6 +714,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
702
714
SILSSAUpdater updater (B.getModule ());
703
715
updater.Initialize (loadTy);
704
716
717
+ Optional<SILValue> singularValue;
705
718
for (auto *i : insertPts) {
706
719
// Use the scope and location of the store at the insertion point.
707
720
SILBuilderWithScope builder (i, &insertedInsts);
@@ -711,9 +724,20 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
711
724
!builder.hasOwnership () ||
712
725
eltVal.getOwnershipKind ().isCompatibleWith (ValueOwnershipKind::Owned));
713
726
727
+ if (!singularValue.hasValue ()) {
728
+ singularValue = eltVal;
729
+ } else if (*singularValue != eltVal) {
730
+ singularValue = SILValue ();
731
+ }
732
+
714
733
updater.AddAvailableValue (i->getParent (), eltVal);
715
734
}
716
735
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
+
717
741
// Finally, grab the value from the SSA updater.
718
742
SILValue eltVal = updater.GetValueInMiddleOfBlock (B.getInsertionBB ());
719
743
assert (!B.hasOwnership () ||
0 commit comments