Skip to content

Commit ac70ba7

Browse files
authored
Merge pull request #40881 from eeckstein/fix-mandatory-specializer
MandatoryGenericSpecializer: fix two crashes
2 parents 18407d8 + 736470a commit ac70ba7

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,9 @@ bool swift::optimizeMemoryAccesses(SILFunction &fn) {
28882888
}
28892889

28902890
bool swift::eliminateDeadAllocations(SILFunction &fn) {
2891+
if (!fn.hasOwnership())
2892+
return false;
2893+
28912894
bool changed = false;
28922895
DeadEndBlocks deadEndBlocks(&fn);
28932896

lib/SILOptimizer/Transforms/GenericSpecializer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ optimizeInst(SILInstruction *inst, SILOptFunctionBuilder &funcBuilder,
253253
if (!callee || callee->isTransparent() == IsNotTransparent)
254254
return true;
255255

256+
if (callee->isExternalDeclaration())
257+
getModule()->loadFunction(callee);
258+
259+
if (callee->isExternalDeclaration())
260+
return true;
261+
256262
// If the de-virtualized callee is a transparent function, inline it.
257263
SILInliner::inlineFullApply(newFAS, SILInliner::InlineKind::MandatoryInline,
258264
funcBuilder, deleter);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-sil-opt -mandatory-generic-specializer %s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
// CHECK-LABEL: sil [no_allocation] @deserialize_and_inline_after_devirtualize
10+
// CHECK-NOT: apply
11+
// CHECK: } // end sil function 'deserialize_and_inline_after_devirtualize'
12+
sil [no_allocation] @deserialize_and_inline_after_devirtualize : $@convention(thin) (@in Int) -> () {
13+
bb0(%0 : $*Int):
14+
%1 = metatype $@thick Int.Type
15+
%2 = witness_method $Int, #Comparable."<" : <Self where Self : Comparable> (Self.Type) -> (Self, Self) -> Bool : $@convention(witness_method: Comparable) <τ_0_0 where τ_0_0 : Comparable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> Bool
16+
%3 = apply %2<Int>(%0, %0, %1) : $@convention(witness_method: Comparable) <τ_0_0 where τ_0_0 : Comparable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> Bool
17+
%4 = tuple()
18+
return %4 : $()
19+
}
20+
21+
// CHECK-LABEL: sil [no_allocation] @dont_do_dead_alloc_eimination_on_non_ossa
22+
// CHECK: alloc_stack
23+
// CHECK-NOT: load
24+
// CHECK: } // end sil function 'dont_do_dead_alloc_eimination_on_non_ossa'
25+
sil [no_allocation] @dont_do_dead_alloc_eimination_on_non_ossa : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 {
26+
bb0(%0 : $Builtin.Int32):
27+
%1 = alloc_stack $Builtin.Int32
28+
store %0 to %1 : $*Builtin.Int32
29+
%2 = load %1 : $*Builtin.Int32
30+
dealloc_stack %1 : $*Builtin.Int32
31+
return %2 : $Builtin.Int32
32+
}
33+
34+
sil shared_external [transparent] [serialized] [thunk] [canonical] @$sSiSLsSL1loiySbx_xtFZTW : $@convention(witness_method: Comparable) (@in_guaranteed Int, @in_guaranteed Int, @thick Int.Type) -> Bool
35+
36+
sil_witness_table public_external [serialized] Int: Comparable module Swift {
37+
base_protocol Equatable: Int: Equatable module Swift
38+
method #Comparable."<": <Self where Self : Comparable> (Self.Type) -> (Self, Self) -> Bool : @$sSiSLsSL1loiySbx_xtFZTW
39+
}
40+

tools/sil-opt/SILOpt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ int main(int argc, char **argv) {
588588
SILOpts.OptRecordFile = RemarksFilename;
589589
SILOpts.OptRecordPasses = RemarksPasses;
590590
SILOpts.checkSILModuleLeaks = true;
591+
SILOpts.EnablePerformanceAnnotations = true;
591592

592593
SILOpts.VerifyExclusivity = VerifyExclusivity;
593594
if (EnforceExclusivity.getNumOccurrences() != 0) {

0 commit comments

Comments
 (0)