Skip to content

Commit 1848203

Browse files
authored
Merge pull request #82184 from eeckstein/fix-specializer-6.2
[6.2] GenericSpecializer: remove some kind of instructions if their operands become trivial after specialization
2 parents 85347b2 + 0bdd827 commit 1848203

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

include/swift/SIL/TypeSubstCloner.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
284284
super::visitCopyValueInst(Copy);
285285
}
286286

287+
void visitExplicitCopyValueInst(ExplicitCopyValueInst *Copy) {
288+
// If the substituted type is trivial, ignore the copy.
289+
SILType copyTy = getOpType(Copy->getType());
290+
if (copyTy.isTrivial(*Copy->getFunction())) {
291+
recordFoldedValue(SILValue(Copy), getOpValue(Copy->getOperand()));
292+
return;
293+
}
294+
super::visitExplicitCopyValueInst(Copy);
295+
}
296+
287297
void visitDestroyValueInst(DestroyValueInst *Destroy) {
288298
// If the substituted type is trivial, ignore the destroy.
289299
SILType destroyTy = getOpType(Destroy->getOperand()->getType());
@@ -293,6 +303,24 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
293303
super::visitDestroyValueInst(Destroy);
294304
}
295305

306+
void visitEndLifetimeInst(EndLifetimeInst *endLifetime) {
307+
// If the substituted type is trivial, ignore the end_lifetime.
308+
SILType ty = getOpType(endLifetime->getOperand()->getType());
309+
if (ty.isTrivial(*endLifetime->getFunction())) {
310+
return;
311+
}
312+
super::visitEndLifetimeInst(endLifetime);
313+
}
314+
315+
void visitExtendLifetimeInst(ExtendLifetimeInst *extendLifetime) {
316+
// If the substituted type is trivial, ignore the extend_lifetime.
317+
SILType ty = getOpType(extendLifetime->getOperand()->getType());
318+
if (ty.isTrivial(*extendLifetime->getFunction())) {
319+
return;
320+
}
321+
super::visitExtendLifetimeInst(extendLifetime);
322+
}
323+
296324
void visitDifferentiableFunctionExtractInst(
297325
DifferentiableFunctionExtractInst *dfei) {
298326
// If the extractee is the original function, do regular cloning.

test/SILOptimizer/specialize_opaque.sil

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import Builtin
1212
// CHECK: %{{.*}} = apply [[F]](%0, %1) : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> ()
1313
// CHECK-NOT: copy_value
1414
// CHECK-NOT: destroy_value
15+
// CHECK-NOT: extend_lifetime
16+
// CHECK-NOT: end_lifetime
1517
// CHECK: return %{{.*}} : $()
1618
// CHECK-LABEL: } // end sil function '$s3fooBi64__Tg5'
1719
sil hidden [ossa] @foo : $@convention(thin) <T> (@in T, @in T) -> () {
1820
bb0(%0 : @owned $T, %1 : @owned $T):
1921
%f = function_ref @foo : $@convention(thin) <τ_0_0> (@in τ_0_0, @in τ_0_0) -> ()
2022
%cp0 = copy_value %0 : $T
2123
%cp1 = copy_value %1 : $T
24+
%cp3 = explicit_copy_value %1 : $T
2225
%call = apply %f<T>(%cp0, %cp1) : $@convention(thin) <τ_0_0> (@in τ_0_0, @in τ_0_0) -> ()
2326
destroy_value %1 : $T
24-
destroy_value %0 : $T
27+
end_lifetime %0 : $T
28+
extend_lifetime %cp3 : $T
2529
%10 = tuple ()
2630
return %10 : $()
2731
}

0 commit comments

Comments
 (0)