Fix optimization of checked_cast_addr_br to checked_cast_br

This commit is contained in:
Meghana Gupta
2025-07-22 11:20:41 -07:00
parent 2e8f74f011
commit b90cd31d66
5 changed files with 96 additions and 7 deletions

View File

@@ -1064,8 +1064,7 @@ CastOptimizer::simplifyCheckedCastBranchInst(CheckedCastBranchInst *Inst) {
// The unconditional_cast can be skipped, if the result of a cast
// is not used afterwards.
if (!ResultNotUsed) {
if (!dynamicCast.canSILUseScalarCheckedCastInstructions())
return nullptr;
ASSERT(dynamicCast.canSILUseScalarCheckedCastInstructions());
CastedValue =
emitSuccessfulScalarUnconditionalCast(Builder, Loc, dynamicCast);
@@ -1160,9 +1159,9 @@ SILInstruction *CastOptimizer::optimizeCheckedCastAddrBranchInst(
if (MI) {
if (SuccessBB->getSinglePredecessorBlock() &&
canSILUseScalarCheckedCastInstructions(
Inst->getModule(), MI->getType().getASTType(),
Inst->getTargetFormalType())) {
canOptimizeToScalarCheckedCastInstructions(
Inst->getFunction(), MI->getType().getASTType(),
Inst->getTargetFormalType(), Inst->getConsumptionKind())) {
SILBuilderWithScope B(Inst, builderContext);
auto NewI = B.createCheckedCastBranch(
Loc, false /*isExact*/,