Skip to content

Commit 19a7978

Browse files
committed
[cast-opt] Eliminate some unneeded type checks in favor of just asserting the instructions we handle.
This code today only handles the following two instructions: 1. checked_cast_addr_br 2. unconditional_checked_cast_addr We were asserting that the source/dest of these values were addresses... but they are obviously are!
1 parent b87e203 commit 19a7978

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ getObjCToSwiftBridgingFunction(SILOptFunctionBuilder &funcBuilder,
7272
/// _ObjectiveCBridgeable.
7373
SILInstruction *
7474
CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
75+
auto kind = dynamicCast.getKind();
76+
(void)kind;
77+
assert(((kind == SILDynamicCastKind::CheckedCastAddrBranchInst) ||
78+
(kind == SILDynamicCastKind::UnconditionalCheckedCastAddrInst)) &&
79+
"Unsupported dynamic cast kind");
80+
7581
CanType target = dynamicCast.getTargetType();
7682
auto &mod = dynamicCast.getModule();
7783

@@ -108,9 +114,6 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
108114
SILValue SrcOp;
109115
SILInstruction *NewI = nullptr;
110116

111-
assert(Src->getType().isAddress() && "Source should have an address type");
112-
assert(Dest->getType().isAddress() && "Source should have an address type");
113-
114117
// If this is a conditional cast:
115118
// We need a new fail BB in order to add a dealloc_stack to it
116119
SILBasicBlock *ConvFailBB = nullptr;
@@ -121,10 +124,6 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
121124
Builder.setInsertionPoint(CurrInsPoint);
122125
}
123126

124-
// We know this is always true since SILBridgedTy is an object and Src is an
125-
// address.
126-
assert(SILBridgedTy != Src->getType());
127-
128127
// Check if we can simplify a cast into:
129128
// - ObjCTy to _ObjectiveCBridgeable._ObjectiveCType.
130129
// - then convert _ObjectiveCBridgeable._ObjectiveCType to

0 commit comments

Comments
 (0)