@@ -135,8 +135,9 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
135
135
if (auto *TTI = dyn_cast<ThinToThickFunctionInst>(funcOper))
136
136
funcOper = TTI->getOperand ();
137
137
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))
140
141
return nullptr ;
141
142
142
143
// Grab our relevant callee types...
@@ -151,8 +152,8 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
151
152
// relevant types from the ConvertFunction function type and AI.
152
153
Builder.setCurrentDebugScope (AI.getDebugScope ());
153
154
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 ());
156
157
auto context = AI.getFunction ()->getTypeExpansionContext ();
157
158
auto oldOpRetTypes = substConventions.getIndirectSILResultTypes (context);
158
159
auto newOpRetTypes = convertConventions.getIndirectSILResultTypes (context);
@@ -229,7 +230,7 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
229
230
Builder.createBranch (AI.getLoc (), TAI->getNormalBB (), branchArgs);
230
231
}
231
232
232
- return Builder.createTryApply (AI.getLoc (), FRI , SubstitutionMap (), Args,
233
+ return Builder.createTryApply (AI.getLoc (), funcOper , SubstitutionMap (), Args,
233
234
normalBB, TAI->getErrorBB (),
234
235
TAI->getApplyOptions ());
235
236
}
@@ -239,9 +240,9 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
239
240
// otherwise, we would be creating malformed SIL).
240
241
ApplyOptions Options = AI.getApplyOptions ();
241
242
Options -= ApplyFlags::DoesNotThrow;
242
- if (FRI-> getFunctionType ()->hasErrorResult ())
243
+ if (funcOper-> getType (). castTo <SILFunctionType> ()->hasErrorResult ())
243
244
Options |= ApplyFlags::DoesNotThrow;
244
- ApplyInst *NAI = Builder.createApply (AI.getLoc (), FRI , SubstitutionMap (),
245
+ ApplyInst *NAI = Builder.createApply (AI.getLoc (), funcOper , SubstitutionMap (),
245
246
Args, Options);
246
247
SILInstruction *result = NAI;
247
248
@@ -1455,7 +1456,11 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
1455
1456
if (isa<PartialApplyInst>(AI->getCallee ()))
1456
1457
return nullptr ;
1457
1458
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))
1459
1464
return optimizeApplyOfConvertFunctionInst (AI, CFI);
1460
1465
1461
1466
if (tryOptimizeKeypath (AI))
0 commit comments