Skip to content

Commit e5d87f7

Browse files
committed
[SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start out as checked_cast_brs and be lowered to checked_cast_addr_brs, since the latter has the source formal type, IRGen relies on being able to access it, and there's no way in general to obtain the source formal type from the source lowered type.
1 parent b3cd553 commit e5d87f7

File tree

101 files changed

+431
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+431
-410
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyRefCasts.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ private extension UnaryInstruction {
3636
/// ```
3737
/// %2 = upcast %1 : $Derived to $Base
3838
/// %3 = init_existential_ref %2 : $Base : $Base, $AnyObject
39-
/// checked_cast_br %3 : $AnyObject to Derived, bb1, bb2
39+
/// checked_cast_br AnyObject in %3 : $AnyObject to Derived, bb1, bb2
4040
/// ```
4141
///
4242
/// This makes it more likely that the cast can be constant folded because the source
4343
/// operand's type is more accurate. In the example above, the cast reduces to
4444
/// ```
45-
/// checked_cast_br %1 : $Derived to Derived, bb1, bb2
45+
/// checked_cast_br Derived in %1 : $Derived to Derived, bb1, bb2
4646
/// ```
4747
/// which can be trivially folded to always-succeeds.
4848
///
@@ -97,13 +97,13 @@ private extension UnaryInstruction {
9797
/// For example:
9898
/// ```
9999
/// %inst = upcast %sourceValue : $Derived to $Base
100-
/// checked_cast_br %inst : $Base to Derived, success_block, failure_block
100+
/// checked_cast_br Base in %inst : $Base to Derived, success_block, failure_block
101101
/// ...
102102
/// failure_block(%oldArg : $Base):
103103
/// ```
104104
/// is converted to:
105105
/// ```
106-
/// checked_cast_br %sourceValue : $Derived to Derived, success_block, failure_block
106+
/// checked_cast_br Derived in %sourceValue : $Derived to Derived, success_block, failure_block
107107
/// ...
108108
/// failure_block(%newArg : $Derived):
109109
/// %3 = upcast %newArg : $Derived to $Base

docs/SIL.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ derived from the ARC object. As an example, consider the following Swift/SIL::
20822082

20832083
// Consume '%1'. This means '%1' can no longer be used after this point. We
20842084
// rebind '%1' in the destination blocks (bbYes, bbNo).
2085-
checked_cast_br %1 : $Klass to $OtherKlass, bbYes, bbNo
2085+
checked_cast_br Klass in %1 : $Klass to $OtherKlass, bbYes, bbNo
20862086

20872087
bbYes(%2 : @owned $OtherKlass): // On success, the checked_cast_br forwards
20882088
// '%1' into '%2' after casting to OtherKlass.
@@ -8097,9 +8097,9 @@ checked_cast_br
80978097
sil-identifier ',' sil-identifier
80988098
sil-checked-cast-exact ::= '[' 'exact' ']'
80998099

8100-
checked_cast_br %0 : $A to $B, bb1, bb2
8101-
checked_cast_br %0 : $*A to $*B, bb1, bb2
8102-
checked_cast_br [exact] %0 : $A to $A, bb1, bb2
8100+
checked_cast_br A in %0 : $A to $B, bb1, bb2
8101+
checked_cast_br *A in %0 : $*A to $*B, bb1, bb2
8102+
checked_cast_br [exact] A in %0 : $A to $A, bb1, bb2
81038103
// $A and $B must be both object types or both address types
81048104
// bb1 must take a single argument of type $B or $*B
81058105
// bb2 must take no arguments

include/swift/SIL/SILBuilder.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,17 +2575,18 @@ class SILBuilder {
25752575
}
25762576

25772577
CheckedCastBranchInst *
2578-
createCheckedCastBranch(SILLocation Loc, bool isExact, SILValue op,
2579-
SILType destLoweredTy, CanType destFormalTy,
2580-
SILBasicBlock *successBB,
2578+
createCheckedCastBranch(SILLocation Loc, bool isExact, SILValue op,
2579+
CanType srcFormalTy, SILType destLoweredTy,
2580+
CanType destFormalTy, SILBasicBlock *successBB,
25812581
SILBasicBlock *failureBB,
25822582
ProfileCounter Target1Count = ProfileCounter(),
25832583
ProfileCounter Target2Count = ProfileCounter());
25842584

25852585
CheckedCastBranchInst *
2586-
createCheckedCastBranch(SILLocation Loc, bool isExact, SILValue op,
2587-
SILType destLoweredTy, CanType destFormalTy,
2588-
SILBasicBlock *successBB, SILBasicBlock *failureBB,
2586+
createCheckedCastBranch(SILLocation Loc, bool isExact, SILValue op,
2587+
CanType srcFormalTy, SILType destLoweredTy,
2588+
CanType destFormalTy, SILBasicBlock *successBB,
2589+
SILBasicBlock *failureBB,
25892590
ValueOwnershipKind forwardingOwnershipKind,
25902591
ProfileCounter Target1Count = ProfileCounter(),
25912592
ProfileCounter Target2Count = ProfileCounter());

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,7 @@ SILCloner<ImplClass>::visitCheckedCastBranchInst(CheckedCastBranchInst *Inst) {
31283128
Inst, getBuilder().createCheckedCastBranch(
31293129
getOpLocation(Inst->getLoc()), Inst->isExact(),
31303130
getOpValue(Inst->getOperand()),
3131+
getOpASTType(Inst->getSourceFormalType()),
31313132
getOpType(Inst->getTargetLoweredType()),
31323133
getOpASTType(Inst->getTargetFormalType()), OpSuccBB, OpFailBB,
31333134
Inst->getForwardingOwnershipKind(), TrueCount, FalseCount));

include/swift/SIL/SILInstruction.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10024,12 +10024,13 @@ class CheckedCastBranchInst final
1002410024
CastBranchInstBase<OwnershipForwardingTermInst>> {
1002510025
friend SILBuilder;
1002610026

10027+
CanType SrcFormalTy;
1002710028
SILType DestLoweredTy;
1002810029
CanType DestFormalTy;
1002910030
bool IsExact;
1003010031

1003110032
CheckedCastBranchInst(SILDebugLocation DebugLoc, bool IsExact,
10032-
SILValue Operand,
10033+
SILValue Operand, CanType SrcFormalTy,
1003310034
ArrayRef<SILValue> TypeDependentOperands,
1003410035
SILType DestLoweredTy, CanType DestFormalTy,
1003510036
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB,
@@ -10041,21 +10042,21 @@ class CheckedCastBranchInst final
1004110042
DebugLoc, Operand, TypeDependentOperands, SuccessBB, FailureBB,
1004210043
Target1Count, Target2Count, forwardingOwnershipKind,
1004310044
preservesOwnership),
10044-
DestLoweredTy(DestLoweredTy), DestFormalTy(DestFormalTy),
10045-
IsExact(IsExact) {}
10045+
SrcFormalTy(SrcFormalTy), DestLoweredTy(DestLoweredTy),
10046+
DestFormalTy(DestFormalTy), IsExact(IsExact) {}
1004610047

1004710048
static CheckedCastBranchInst *
1004810049
create(SILDebugLocation DebugLoc, bool IsExact, SILValue Operand,
10049-
SILType DestLoweredTy, CanType DestFormalTy, SILBasicBlock *SuccessBB,
10050-
SILBasicBlock *FailureBB, SILFunction &F,
10050+
CanType SrcFormalTy, SILType DestLoweredTy, CanType DestFormalTy,
10051+
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB, SILFunction &F,
1005110052
ProfileCounter Target1Count, ProfileCounter Target2Count,
1005210053
ValueOwnershipKind forwardingOwnershipKind);
1005310054

1005410055
public:
1005510056
bool isExact() const { return IsExact; }
1005610057

1005710058
SILType getSourceLoweredType() const { return getOperand()->getType(); }
10058-
CanType getSourceFormalType() const { return getSourceLoweredType().getASTType(); }
10059+
CanType getSourceFormalType() const { return SrcFormalTy; }
1005910060

1006010061
SILType getTargetLoweredType() const { return DestLoweredTy; }
1006110062
CanType getTargetFormalType() const { return DestFormalTy; }

lib/IRGen/GenCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ FailableCastResult irgen::emitClassIdenticalCast(IRGenFunction &IGF,
125125
// of the metatype value to the subclass's static metatype instance.
126126
//
127127
// %1 = value_metatype $Super.Type, %0 : $A
128-
// checked_cast_br [exact] %1 : $Super.Type to $Sub.Type
128+
// checked_cast_br [exact] Super.Type in %1 : $Super.Type to $Sub.Type
129129
// =>
130130
// icmp eq %1, @metadata.Sub
131131
llvm::Value *objectMetadata = isMetatype ? from :

lib/SIL/IR/SILBuilder.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ void SILBuilder::emitScopedBorrowOperation(SILLocation loc, SILValue original,
675675
/// Example:
676676
///
677677
/// %mt = metatype $@thick C.Type
678-
/// checked_cast_br %mt : $@thick C.Type to AnyObject.Type, bb1, bb2,
678+
/// checked_cast_br C.Type in %mt : $@thick C.Type to AnyObject.Type, bb1, bb2,
679679
/// forwarding: @owned
680680
/// bb1(%arg : @owned AnyObject.Type):
681681
///
@@ -717,30 +717,30 @@ SwitchEnumInst *SILBuilder::createSwitchEnum(
717717
}
718718

719719
CheckedCastBranchInst *SILBuilder::createCheckedCastBranch(
720-
SILLocation Loc, bool isExact, SILValue op,
721-
SILType destLoweredTy, CanType destFormalTy,
722-
SILBasicBlock *successBB, SILBasicBlock *failureBB,
723-
ProfileCounter target1Count, ProfileCounter target2Count) {
720+
SILLocation Loc, bool isExact, SILValue op, CanType srcFormalTy,
721+
SILType destLoweredTy, CanType destFormalTy, SILBasicBlock *successBB,
722+
SILBasicBlock *failureBB, ProfileCounter target1Count,
723+
ProfileCounter target2Count) {
724724
auto forwardingOwnership =
725725
deriveForwardingOwnership(op, destLoweredTy, getFunction());
726-
return createCheckedCastBranch(Loc, isExact, op, destLoweredTy, destFormalTy,
727-
successBB, failureBB, forwardingOwnership,
728-
target1Count, target2Count);
726+
return createCheckedCastBranch(
727+
Loc, isExact, op, srcFormalTy, destLoweredTy, destFormalTy, successBB,
728+
failureBB, forwardingOwnership, target1Count, target2Count);
729729
}
730730

731731
CheckedCastBranchInst *SILBuilder::createCheckedCastBranch(
732-
SILLocation Loc, bool isExact, SILValue op, SILType destLoweredTy,
733-
CanType destFormalTy, SILBasicBlock *successBB, SILBasicBlock *failureBB,
734-
ValueOwnershipKind forwardingOwnershipKind, ProfileCounter target1Count,
735-
ProfileCounter target2Count) {
732+
SILLocation Loc, bool isExact, SILValue op, CanType srcFormalTy,
733+
SILType destLoweredTy, CanType destFormalTy, SILBasicBlock *successBB,
734+
SILBasicBlock *failureBB, ValueOwnershipKind forwardingOwnershipKind,
735+
ProfileCounter target1Count, ProfileCounter target2Count) {
736736
assert((!hasOwnership() || !failureBB->getNumArguments() ||
737737
failureBB->getArgument(0)->getType() == op->getType()) &&
738738
"failureBB's argument doesn't match incoming argument type");
739739

740740
return insertTerminator(CheckedCastBranchInst::create(
741-
getSILDebugLocation(Loc), isExact, op, destLoweredTy, destFormalTy,
742-
successBB, failureBB, getFunction(), target1Count, target2Count,
743-
forwardingOwnershipKind));
741+
getSILDebugLocation(Loc), isExact, op, srcFormalTy, destLoweredTy,
742+
destFormalTy, successBB, failureBB, getFunction(), target1Count,
743+
target2Count, forwardingOwnershipKind));
744744
}
745745

746746
void SILBuilderWithScope::insertAfter(SILInstruction *inst,

lib/SIL/IR/SILInstructions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,8 +2551,8 @@ UnconditionalCheckedCastInst *UnconditionalCheckedCastInst::create(
25512551

25522552
CheckedCastBranchInst *CheckedCastBranchInst::create(
25532553
SILDebugLocation DebugLoc, bool IsExact, SILValue Operand,
2554-
SILType DestLoweredTy, CanType DestFormalTy, SILBasicBlock *SuccessBB,
2555-
SILBasicBlock *FailureBB, SILFunction &F,
2554+
CanType SrcFormalTy, SILType DestLoweredTy, CanType DestFormalTy,
2555+
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB, SILFunction &F,
25562556
ProfileCounter Target1Count, ProfileCounter Target2Count,
25572557
ValueOwnershipKind forwardingOwnershipKind) {
25582558
SILModule &module = F.getModule();
@@ -2561,12 +2561,12 @@ CheckedCastBranchInst *CheckedCastBranchInst::create(
25612561
SmallVector<SILValue, 8> TypeDependentOperands;
25622562
collectTypeDependentOperands(TypeDependentOperands, F, DestFormalTy);
25632563
unsigned size =
2564-
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
2564+
totalSizeToAlloc<swift::Operand>(3 + TypeDependentOperands.size());
25652565
void *Buffer = module.allocateInst(size, alignof(CheckedCastBranchInst));
25662566
return ::new (Buffer) CheckedCastBranchInst(
2567-
DebugLoc, IsExact, Operand, TypeDependentOperands, DestLoweredTy,
2568-
DestFormalTy, SuccessBB, FailureBB, Target1Count, Target2Count,
2569-
forwardingOwnershipKind, preservesOwnership);
2567+
DebugLoc, IsExact, Operand, SrcFormalTy, TypeDependentOperands,
2568+
DestLoweredTy, DestFormalTy, SuccessBB, FailureBB, Target1Count,
2569+
Target2Count, forwardingOwnershipKind, preservesOwnership);
25702570
}
25712571

25722572
MetatypeInst *MetatypeInst::create(SILDebugLocation Loc, SILType Ty,

lib/SIL/IR/SILPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
19141914
void visitCheckedCastBranchInst(CheckedCastBranchInst *CI) {
19151915
if (CI->isExact())
19161916
*this << "[exact] ";
1917+
*this << CI->getSourceFormalType() << " in ";
19171918
*this << getIDAndType(CI->getOperand()) << " to " << CI->getTargetFormalType()
19181919
<< ", " << Ctx.getID(CI->getSuccessBB()) << ", "
19191920
<< Ctx.getID(CI->getFailureBB());

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,9 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
44894489
parseSILOptional(isExact, *this, "exact"))
44904490
return true;
44914491

4492+
if (parseASTType(SourceType) || parseVerbatim("in"))
4493+
return true;
4494+
44924495
if (parseTypedValueRef(Val, B) || parseVerbatim("to") ||
44934496
parseASTType(TargetType) || parseConditionalBranchDestinations())
44944497
return true;
@@ -4501,8 +4504,9 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
45014504

45024505
auto opaque = Lowering::AbstractionPattern::getOpaque();
45034506
ResultVal = B.createCheckedCastBranch(
4504-
InstLoc, isExact, Val, F->getLoweredType(opaque, TargetType),
4505-
TargetType, getBBForReference(SuccessBBName, SuccessBBLoc),
4507+
InstLoc, isExact, Val, SourceType,
4508+
F->getLoweredType(opaque, TargetType), TargetType,
4509+
getBBForReference(SuccessBBName, SuccessBBLoc),
45064510
getBBForReference(FailureBBName, FailureBBLoc), forwardingOwnership);
45074511
break;
45084512
}

lib/SIL/Utils/DynamicCasts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,8 @@ void swift::emitIndirectConditionalCastWithScalar(
14171417
})();
14181418

14191419
auto *ccb = B.createCheckedCastBranch(
1420-
loc, /*exact*/ false, srcValue, targetLoweredType, targetFormalType,
1421-
scalarSuccBB, scalarFailBB, TrueCount, FalseCount);
1420+
loc, /*exact*/ false, srcValue, sourceFormalType, targetLoweredType,
1421+
targetFormalType, scalarSuccBB, scalarFailBB, TrueCount, FalseCount);
14221422

14231423
// Emit the success block.
14241424
B.setInsertionPoint(scalarSuccBB); {

lib/SILGen/SILGenBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ ManagedValue SILGenBuilder::createUnconditionalCheckedCast(
600600

601601
void SILGenBuilder::createCheckedCastBranch(SILLocation loc, bool isExact,
602602
ManagedValue op,
603+
CanType sourceFormalTy,
603604
SILType destLoweredTy,
604605
CanType destFormalTy,
605606
SILBasicBlock *trueBlock,
@@ -611,9 +612,8 @@ void SILGenBuilder::createCheckedCastBranch(SILLocation loc, bool isExact,
611612
destFormalTy)) {
612613
op = op.ensurePlusOne(SGF, loc);
613614
}
614-
createCheckedCastBranch(loc, isExact, op.forward(SGF),
615-
destLoweredTy, destFormalTy,
616-
trueBlock, falseBlock,
615+
createCheckedCastBranch(loc, isExact, op.forward(SGF), sourceFormalTy,
616+
destLoweredTy, destFormalTy, trueBlock, falseBlock,
617617
Target1Count, Target2Count);
618618
}
619619

lib/SILGen/SILGenBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class SILGenBuilder : public SILBuilder {
289289
using SILBuilder::createCheckedCastBranch;
290290
void createCheckedCastBranch(SILLocation loc, bool isExact,
291291
ManagedValue op,
292+
CanType sourceFormalTy,
292293
SILType destLoweredTy,
293294
CanType destFormalTy,
294295
SILBasicBlock *trueBlock,

lib/SILGen/SILGenDynamicCast.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ namespace {
150150
operandValue = operandValue.borrow(SGF, Loc);
151151
}
152152
SGF.B.createCheckedCastBranch(Loc, /*exact*/ false, operandValue,
153-
origTargetTL.getLoweredType(), TargetType,
154-
trueBB, falseBB, TrueCount, FalseCount);
153+
SourceType, origTargetTL.getLoweredType(),
154+
TargetType, trueBB, falseBB, TrueCount,
155+
FalseCount);
155156
}
156157

157158
// Emit the success block.

lib/SILOptimizer/Differentiation/VJPCloner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ class VJPCloner::Implementation final
370370
// Create a new `checked_cast_branch` instruction.
371371
getBuilder().createCheckedCastBranch(
372372
ccbi->getLoc(), ccbi->isExact(), getOpValue(ccbi->getOperand()),
373+
getOpASTType(ccbi->getSourceFormalType()),
373374
getOpType(ccbi->getTargetLoweredType()),
374375
getOpASTType(ccbi->getTargetFormalType()),
375376
createTrampolineBasicBlock(ccbi, pbTupleVal, ccbi->getSuccessBB()),

lib/SILOptimizer/Transforms/SILCodeMotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ enum OperandRelation {
956956
///
957957
/// bb1:
958958
/// %3 = unchecked_enum_data %0 : $Optional<X>, #Optional.Some!enumelt
959-
/// checked_cast_br [exact] %3 : $X to $X, bb4, bb5 // id: %4
959+
/// checked_cast_br [exact] X in %3 : $X to $X, bb4, bb5 // id: %4
960960
///
961961
/// bb4(%10 : $X): // Preds: bb1
962962
/// strong_release %10 : $X

lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI,
162162
// class instance is identical to the SILType.
163163

164164
CCBI = Builder.createCheckedCastBranch(AI.getLoc(), /*exact*/ true,
165-
CMI->getOperand(),
165+
CMI->getOperand(),
166+
CMI->getOperand()->getType().getASTType(),
166167
SILType::getPrimitiveObjectType(SubType),
167168
SubType, Iden, Virt);
168169
It = CCBI->getIterator();

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ convertObjectToLoadableBridgeableType(SILBuilderWithScope &builder,
142142

143143
// Ok, we need to perform the full cast optimization. This means that we are
144144
// going to replace the cast terminator in inst_block with a checked_cast_br.
145-
auto *ccbi = builder.createCheckedCastBranch(loc, false, load, silBridgedTy,
145+
auto *ccbi = builder.createCheckedCastBranch(loc, false, load,
146+
dynamicCast.getBridgedSourceType(),
147+
silBridgedTy,
146148
dynamicCast.getBridgedTargetType(),
147149
castSuccessBB, castFailBB);
148150
splitEdge(ccbi, /* EdgeIdx to CastFailBB */ 1);
@@ -538,6 +540,7 @@ static SILValue computeFinalCastedValue(SILBuilderWithScope &builder,
538540
auto loc = dynamicCast.getLocation();
539541
auto convTy = newAI->getType();
540542
bool isConditional = dynamicCast.isConditional();
543+
auto sourceFormalTy = dynamicCast.getSourceFormalType();
541544
auto destLoweredTy = dynamicCast.getTargetLoweredType().getObjectType();
542545
auto destFormalTy = dynamicCast.getTargetFormalType();
543546
assert(destLoweredTy == dynamicCast.getLoweredBridgedTargetObjectType() &&
@@ -581,7 +584,7 @@ static SILValue computeFinalCastedValue(SILBuilderWithScope &builder,
581584
newAI->getFunction()->createBasicBlockAfter(newAI->getParent());
582585
condBrSuccessBB->createPhiArgument(destLoweredTy, OwnershipKind::Owned);
583586
builder.createCheckedCastBranch(loc, /* isExact*/ false, newAI,
584-
destLoweredTy, destFormalTy,
587+
sourceFormalTy, destLoweredTy, destFormalTy,
585588
condBrSuccessBB, failureBB);
586589
builder.setInsertionPoint(condBrSuccessBB, condBrSuccessBB->begin());
587590
return condBrSuccessBB->getArgument(0);
@@ -1151,6 +1154,7 @@ SILInstruction *CastOptimizer::optimizeCheckedCastAddrBranchInst(
11511154
SILBuilderWithScope B(Inst, builderContext);
11521155
auto NewI = B.createCheckedCastBranch(
11531156
Loc, false /*isExact*/, MI,
1157+
Inst->getSourceFormalType(),
11541158
Inst->getTargetLoweredType().getObjectType(),
11551159
Inst->getTargetFormalType(),
11561160
SuccessBB, FailureBB, Inst->getTrueBBCount(),
@@ -1193,6 +1197,9 @@ CastOptimizer::optimizeCheckedCastBranchInst(CheckedCastBranchInst *Inst) {
11931197
}
11941198
return B.createCheckedCastBranch(
11951199
dynamicCast.getLocation(), false /*isExact*/, mi,
1200+
// The cast is now from the the MetatypeInst, so get the source formal
1201+
// type from it.
1202+
mi->getType().getASTType(),
11961203
dynamicCast.getTargetLoweredType(),
11971204
dynamicCast.getTargetFormalType(),
11981205
dynamicCast.getSuccessBlock(),

0 commit comments

Comments
 (0)