Skip to content

Commit 013d08d

Browse files
committed
Add a bailout location # threshold in DSE.
In StdlibUnitTest, there is this function that has too many (2450) LSLocations and the data flow in DSE takes too long to converge. StdlibUnittest.TestSuite.(addForwardRangeReplaceableCollectionTests <A, B where A: Swift.RangeReplaceableCollectionType, B: Swift.RangeReplaceableCollectionType, A.SubSequence: Swift.CollectionType, B.Generator.Element: Swift.Equatable, A.SubSequence == A.SubSequence.SubSequence, A.Generator.Element == A.SubSequence.Generator.Element> (Swift.String, makeCollection : ([A.Generator.Element]) -> A, wrapValue : (StdlibUnittest.OpaqueValue<Swift.Int>) -> A.Generator.Element, extractValue : (A.Generator.Element) -> StdlibUnittest.OpaqueValue<Swift.Int>, makeCollectionOfEquatable : ([B.Generator.Element]) -> B, wrapValueIntoEquatable : (StdlibUnittest.MinimalEquatableValue) -> B.Generator.Element, extractValueFromEquatable : (B.Generator.Element) -> StdlibUnittest.MinimalEquatableValue, checksAdded : StdlibUnittest.Box<Swift.Set<Swift.String>>, resiliencyChecks : StdlibUnittest.CollectionMisuseResiliencyChecks, outOfBoundsIndexOffset : Swift.Int) -> ()).(closure #18) This function alone takes ~20% of the total amount of time spent in DSE in StdlibUnitTest. And DSE does not eliminate any dead store in the function either. I added this threshold to abort on functions that have too many LSLocations. I see no difference in # of dead store eliminated in the Stdlib.
1 parent 75cb941 commit 013d08d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/SILOptimizer/Transforms/DeadStoreElimination.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static bool isDeadStoreInertInstruction(SILInstruction *Inst) {
150150

151151
namespace {
152152

153+
// If there are too many locations in the function, we bail out.
154+
constexpr unsigned MaxLSLocationLimit = 2048;
155+
153156
/// If a large store is broken down to too many smaller stores, bail out.
154157
/// Currently, we only do partial dead store if we can form a single contiguous
155158
/// non-dead store.
@@ -1037,6 +1040,10 @@ bool DSEContext::run() {
10371040
// this function.
10381041
LSLocation::enumerateLSLocations(*F, LocationVault, LocToBitIndex, TE);
10391042

1043+
// Data flow may take too long to converge.
1044+
if (LocationVault.size() > MaxLSLocationLimit)
1045+
return false;
1046+
10401047
// For all basic blocks in the function, initialize a BB state.
10411048
//
10421049
// DenseMap has a minimum size of 64, while many functions do not have more

0 commit comments

Comments
 (0)