@@ -135,8 +135,9 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
135135 if (auto *TTI = dyn_cast<ThinToThickFunctionInst>(funcOper))
136136 funcOper = TTI->getOperand ();
137137
138- auto *FRI = dyn_cast<FunctionRefInst>(funcOper);
139- if (!FRI)
138+ if (!isa<FunctionRefInst>(funcOper) &&
139+ // Optimizing partial_apply will then enable the partial_apply -> apply peephole.
140+ !isa<PartialApplyInst>(funcOper))
140141 return nullptr ;
141142
142143 // Grab our relevant callee types...
@@ -151,8 +152,8 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
151152 // relevant types from the ConvertFunction function type and AI.
152153 Builder.setCurrentDebugScope (AI.getDebugScope ());
153154 OperandValueArrayRef Ops = AI.getArguments ();
154- SILFunctionConventions substConventions (SubstCalleeTy, FRI ->getModule ());
155- SILFunctionConventions convertConventions (ConvertCalleeTy, FRI ->getModule ());
155+ SILFunctionConventions substConventions (SubstCalleeTy, CFI ->getModule ());
156+ SILFunctionConventions convertConventions (ConvertCalleeTy, CFI ->getModule ());
156157 auto context = AI.getFunction ()->getTypeExpansionContext ();
157158 auto oldOpRetTypes = substConventions.getIndirectSILResultTypes (context);
158159 auto newOpRetTypes = convertConventions.getIndirectSILResultTypes (context);
@@ -229,7 +230,7 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
229230 Builder.createBranch (AI.getLoc (), TAI->getNormalBB (), branchArgs);
230231 }
231232
232- return Builder.createTryApply (AI.getLoc (), FRI , SubstitutionMap (), Args,
233+ return Builder.createTryApply (AI.getLoc (), funcOper , SubstitutionMap (), Args,
233234 normalBB, TAI->getErrorBB (),
234235 TAI->getApplyOptions ());
235236 }
@@ -239,9 +240,9 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
239240 // otherwise, we would be creating malformed SIL).
240241 ApplyOptions Options = AI.getApplyOptions ();
241242 Options -= ApplyFlags::DoesNotThrow;
242- if (FRI-> getFunctionType ()->hasErrorResult ())
243+ if (funcOper-> getType (). castTo <SILFunctionType> ()->hasErrorResult ())
243244 Options |= ApplyFlags::DoesNotThrow;
244- ApplyInst *NAI = Builder.createApply (AI.getLoc (), FRI , SubstitutionMap (),
245+ ApplyInst *NAI = Builder.createApply (AI.getLoc (), funcOper , SubstitutionMap (),
245246 Args, Options);
246247 SILInstruction *result = NAI;
247248
@@ -1455,7 +1456,11 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
14551456 if (isa<PartialApplyInst>(AI->getCallee ()))
14561457 return nullptr ;
14571458
1458- if (auto *CFI = dyn_cast<ConvertFunctionInst>(AI->getCallee ()))
1459+ SILValue callee = AI->getCallee ();
1460+ if (auto *cee = dyn_cast<ConvertEscapeToNoEscapeInst>(callee)) {
1461+ callee = cee->getOperand ();
1462+ }
1463+ if (auto *CFI = dyn_cast<ConvertFunctionInst>(callee))
14591464 return optimizeApplyOfConvertFunctionInst (AI, CFI);
14601465
14611466 if (tryOptimizeKeypath (AI))
0 commit comments