@@ -1300,50 +1300,27 @@ CastOptimizer::optimizeCheckedCastBranchInst(CheckedCastBranchInst *Inst) {
1300
1300
// %1 = metatype $A.Type
1301
1301
// checked_cast_br %1, ....
1302
1302
if (auto *FoundIERI = dyn_cast<InitExistentialRefInst>(Op)) {
1303
- auto *ASRI = dyn_cast<AllocRefInst>( FoundIERI->getOperand () );
1304
- if (!ASRI )
1303
+ SILValue op = FoundIERI->getOperand ();
1304
+ if (!isa<AllocRefInst>(op) )
1305
1305
return nullptr ;
1306
- // Should be in the same BB.
1307
- if (ASRI->getParent () != EMI->getParent ())
1308
- return nullptr ;
1309
- // Check if this alloc_stack is only initialized once by means of
1310
- // a single init_existential_ref.
1311
- bool isLegal = true ;
1312
- for (auto Use : getNonDebugUses (ASRI)) {
1313
- auto *User = Use->getUser ();
1314
- if (isa<ExistentialMetatypeInst>(User) || isa<StrongReleaseInst>(User))
1315
- continue ;
1316
- if (auto *IERI = dyn_cast<InitExistentialRefInst>(User)) {
1317
- if (IERI == FoundIERI) {
1318
- continue ;
1319
- }
1320
- }
1321
- isLegal = false ;
1322
- break ;
1323
- }
1324
1306
1325
- if (isLegal && FoundIERI) {
1326
- // Should be in the same BB.
1327
- if (FoundIERI->getParent () != EMI->getParent ())
1328
- return nullptr ;
1329
- // Get the type used to initialize the existential.
1330
- auto ConcreteTy = FoundIERI->getFormalConcreteType ();
1331
- // We don't know enough at compile time about existential
1332
- // and generic type parameters.
1333
- if (ConcreteTy.isAnyExistentialType () ||
1334
- ConcreteTy->is <ArchetypeType>())
1335
- return nullptr ;
1336
- // Get the SIL metatype of this type.
1337
- auto EMT = EMI->getType ().castTo <AnyMetatypeType>();
1338
- auto *MetaTy = MetatypeType::get (ConcreteTy, EMT->getRepresentation ());
1339
- auto CanMetaTy = CanTypeWrapper<MetatypeType>(MetaTy);
1340
- auto SILMetaTy = SILType::getPrimitiveObjectType (CanMetaTy);
1341
- SILBuilderWithScope B (Inst, builderContext);
1342
- auto *MI = B.createMetatype (FoundIERI->getLoc (), SILMetaTy);
1343
- auto *NewI = replaceCastHelper (B, dynamicCast, MI);
1344
- eraseInstAction (Inst);
1345
- return NewI;
1346
- }
1307
+ // Get the type used to initialize the existential.
1308
+ auto ConcreteTy = FoundIERI->getFormalConcreteType ();
1309
+ // We don't know enough at compile time about existential
1310
+ // and generic type parameters.
1311
+ if (ConcreteTy.isAnyExistentialType () ||
1312
+ ConcreteTy->is <ArchetypeType>())
1313
+ return nullptr ;
1314
+ // Get the SIL metatype of this type.
1315
+ auto EMT = EMI->getType ().castTo <AnyMetatypeType>();
1316
+ auto *MetaTy = MetatypeType::get (ConcreteTy, EMT->getRepresentation ());
1317
+ auto CanMetaTy = CanTypeWrapper<MetatypeType>(MetaTy);
1318
+ auto SILMetaTy = SILType::getPrimitiveObjectType (CanMetaTy);
1319
+ SILBuilderWithScope B (Inst, builderContext);
1320
+ auto *MI = B.createMetatype (FoundIERI->getLoc (), SILMetaTy);
1321
+ auto *NewI = replaceCastHelper (B, dynamicCast, MI);
1322
+ eraseInstAction (Inst);
1323
+ return NewI;
1347
1324
}
1348
1325
}
1349
1326
0 commit comments