@@ -244,6 +244,18 @@ findDominatingNonPayloadedEdge(SILBasicBlock *IncomingEdgeBB,
244
244
return false ;
245
245
}
246
246
247
+ static SILValue allIncomingValuesEqual (
248
+ llvm::SmallVectorImpl<std::pair<SILBasicBlock *,
249
+ SILValue >> &IncomingValues) {
250
+ SILValue First = stripRCIdentityPreservingInsts (IncomingValues[0 ].second );
251
+ if (std::all_of (std::next (IncomingValues.begin ()), IncomingValues.end (),
252
+ [&First](std::pair<SILBasicBlock *, SILValue> P) -> bool {
253
+ return stripRCIdentityPreservingInsts (P.second ) == First;
254
+ }))
255
+ return First;
256
+ return SILValue ();
257
+ }
258
+
247
259
// / Return the underlying SILValue after stripping off SILArguments that cannot
248
260
// / affect RC identity.
249
261
// /
@@ -301,11 +313,16 @@ SILValue RCIdentityFunctionInfo::stripRCIdentityPreservingArgs(SILValue V,
301
313
302
314
unsigned IVListSize = IncomingValues.size ();
303
315
304
- // If we only have one incoming value, just return the identity root of that
305
- // incoming value. There can be no loop problems.
306
- if (IVListSize == 1 ) {
307
- return IncomingValues[0 ].second ;
308
- }
316
+ assert (IVListSize != 1 && " Should have been handled in "
317
+ " stripRCIdentityPreservingInsts" );
318
+
319
+ // Ok, we have multiple predecessors. See if all of them are the same
320
+ // value. If so, just return that value.
321
+ //
322
+ // This returns a SILValue to save a little bit of compile time since we
323
+ // already compute that value here.
324
+ if (SILValue V = allIncomingValuesEqual (IncomingValues))
325
+ return V;
309
326
310
327
// Ok, we have multiple predecessors. First find the first non-payloaded enum.
311
328
llvm::SmallVector<SILBasicBlock *, 8 > NoPayloadEnumBBs;
0 commit comments