Skip to content

Commit 947910d

Browse files
authored
Merge pull request #76241 from eeckstein/fix-runtime-effect
Fix a false performance error when using generic, but loadable types
2 parents 7831ff7 + 8b955d9 commit 947910d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,14 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
727727

728728
case SILInstructionKind::AllocStackInst:
729729
case SILInstructionKind::AllocVectorInst:
730-
case SILInstructionKind::ProjectBoxInst:
731-
if (cast<SingleValueInstruction>(inst)->getType().hasArchetype()) {
732-
impactType = cast<SingleValueInstruction>(inst)->getType();
730+
case SILInstructionKind::ProjectBoxInst: {
731+
SILType allocType = cast<SingleValueInstruction>(inst)->getType();
732+
if (allocType.hasArchetype() && !allocType.isLoadable(*inst->getFunction())) {
733+
impactType = allocType;
733734
return RuntimeEffect::MetaData;
734735
}
735736
return RuntimeEffect::NoEffect;
736-
737+
}
737738
case SILInstructionKind::AllocGlobalInst: {
738739
SILType glTy = cast<AllocGlobalInst>(inst)->getReferencedGlobal()->
739740
getLoweredType();

test/SILOptimizer/performance-annotations.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ func testLargeTuple() {
501501
_ = GenericStruct<SixInt8s>()
502502
}
503503

504+
struct Ptr<T> {
505+
public var p: UnsafeMutablePointer<T>
506+
507+
@_noAllocation
508+
init(p: UnsafeMutablePointer<T>) {
509+
self.p = p
510+
}
511+
}
512+
504513
struct NonCopyableStruct: ~Copyable {
505514
func foo() {}
506515
}

0 commit comments

Comments
 (0)