Skip to content

Commit 37c0eb2

Browse files
committed
Manually check if types are the same when checking for change and update
tests
1 parent 65e8d37 commit 37c0eb2

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,6 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
872872
NewArgs.push_back(Apply.getArgument(ArgIdx));
873873
}
874874

875-
// Keep track of weather we made any updates at all. Otherwise, we will
876-
// have an infinite loop.
877-
bool madeUpdate = false;
878-
879875
// Transform the parameter arguments.
880876
SmallVector<ConcreteArgumentCopy, 4> concreteArgCopies;
881877
for (unsigned EndIdx = Apply.getNumArguments(); ArgIdx < EndIdx; ++ArgIdx) {
@@ -903,7 +899,6 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
903899
if (argSub) {
904900
concreteArgCopies.push_back(*argSub);
905901
NewArgs.push_back(argSub->tempArg);
906-
madeUpdate = true;
907902
} else {
908903
NewArgs.push_back(CEI.ConcreteValue);
909904
}
@@ -929,7 +924,8 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
929924
});
930925
}
931926

932-
bool canUpdateArgs = [&]() {
927+
bool canUpdateArgs, madeUpdate;
928+
std::tie(canUpdateArgs, madeUpdate) = [&]() {
933929
auto substTy =
934930
Apply.getCallee()
935931
->getType()
@@ -939,12 +935,16 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
939935
SILFunctionConventions conv(substTy,
940936
SILModuleConventions(Apply.getModule()));
941937
bool canUpdate = true;
938+
// Keep track of weather we made any updates at all. Otherwise, we will
939+
// have an infinite loop.
940+
bool madeUpdate = false;
942941
for (unsigned index = 0; index < conv.getNumSILArguments(); ++index) {
943942
canUpdate &= conv.getSILArgumentType(index) == NewArgs[index]->getType();
943+
madeUpdate |= NewArgs[index]->getType() != Apply.getArgument(index)->getType();
944944
}
945-
return canUpdate;
945+
return std::make_tuple(canUpdate, madeUpdate);
946946
}();
947-
947+
948948
if (!canUpdateArgs || !madeUpdate) {
949949
// Remove any new instructions created while attempting to optimize this
950950
// apply. Since the apply was never rewritten, if they aren't removed here,

test/SILOptimizer/devirtualize_protocol_composition_two_stores.sil

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,51 @@ public class A {
1212
}
1313

1414
public protocol P {
15-
func foo() -> Int
15+
func foo() -> Int64
1616
}
1717

1818
public class B : A, P {
19-
public func foo() -> Int
19+
public func foo() -> Int64
2020
@objc deinit
2121
override init()
2222
}
2323

2424
public class C : A, P {
25-
public func foo() -> Int
25+
public func foo() -> Int64
2626
@objc deinit
2727
override init()
2828
}
2929

30-
func imp(x: A & P, y: A & P) -> Int
30+
func imp(x: A & P, y: A & P) -> Int64
3131

32-
public func test(x: B, y: C) -> Int
32+
public func test(x: B, y: C) -> Int64
3333

3434
// protocol witness for P.foo() in conformance B
35-
sil shared [transparent] [serialized] [thunk] @Pfoo : $@convention(witness_method: P) (@in_guaranteed B) -> Int {
35+
sil shared [transparent] [serialized] [thunk] @Pfoo : $@convention(witness_method: P) (@in_guaranteed B) -> Int64 {
3636
// %0 // user: %1
3737
bb0(%0 : $*B):
3838
%1 = load %0 : $*B // users: %2, %3
39-
%2 = class_method %1 : $B, #B.foo!1 : (B) -> () -> Int, $@convention(method) (@guaranteed B) -> Int // user: %3
40-
%3 = apply %2(%1) : $@convention(method) (@guaranteed B) -> Int // user: %4
41-
return %3 : $Int // id: %4
39+
%2 = class_method %1 : $B, #B.foo!1 : (B) -> () -> Int64, $@convention(method) (@guaranteed B) -> Int64 // user: %3
40+
%3 = apply %2(%1) : $@convention(method) (@guaranteed B) -> Int64 // user: %4
41+
return %3 : $Int64 // id: %4
4242
} // end sil function 'Pfoo'
4343

4444
// B.foo()
45-
sil [noinline] @foo : $@convention(method) (@guaranteed B) -> Int {
45+
sil [noinline] @foo : $@convention(method) (@guaranteed B) -> Int64 {
4646
// %0 // user: %1
4747
bb0(%0 : $B):
4848
debug_value %0 : $B, let, name "self", argno 1 // id: %1
4949
%2 = integer_literal $Builtin.Int64, 1 // user: %3
50-
%3 = struct $Int (%2 : $Builtin.Int64) // user: %4
51-
return %3 : $Int // id: %4
50+
%3 = struct $Int64 (%2 : $Builtin.Int64) // user: %4
51+
return %3 : $Int64 // id: %4
5252
} // end sil function 'foo'
5353

5454

5555
// This function calls @impl. The optimizer generates a specialization of impl
5656
// based on the arguments passed to it here. Even though this function isn't
5757
// directly checked, it is essentail for the optimization.
5858
// test(x:y:)
59-
sil @test :$@convention(thin) (@guaranteed B, @guaranteed C) -> Int {
59+
sil @test :$@convention(thin) (@guaranteed B, @guaranteed C) -> Int64 {
6060
// %0 // users: %5, %4, %2
6161
// %1 // users: %7, %6, %3
6262
bb0(%0 : $B, %1 : $C):
@@ -67,11 +67,11 @@ bb0(%0 : $B, %1 : $C):
6767
strong_retain %1 : $C // id: %6
6868
%7 = init_existential_ref %1 : $C : $C, $A & P // users: %10, %9
6969
// function_ref imp(x:y:)
70-
%8 = function_ref @impl : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int // user: %9
71-
%9 = apply %8(%5, %7) : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int // user: %12
70+
%8 = function_ref @impl : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int64 // user: %9
71+
%9 = apply %8(%5, %7) : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int64 // user: %12
7272
strong_release %7 : $A & P // id: %10
7373
strong_release %5 : $A & P // id: %11
74-
return %9 : $Int // id: %12
74+
return %9 : $Int64 // id: %12
7575
} // end sil function 'test'
7676

7777
// We're looking of an optimized spcialization of @impl, not @impl itself.
@@ -83,7 +83,7 @@ bb0(%0 : $B, %1 : $C):
8383
// This function will be passed arguments of type B and C for arguments
8484
// %0 and %1 respectively. We want to make sure that we call B's foo method
8585
// and not C's foo method.
86-
sil hidden [noinline] @impl : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int {
86+
sil hidden [noinline] @impl : $@convention(thin) (@guaranteed A & P, @guaranteed A & P) -> Int64 {
8787
bb0(%0 : $A & P, %1 : $A & P):
8888
%2 = open_existential_ref %0 : $A & P to $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P
8989
%3 = unchecked_ref_cast %1 : $A & P to $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P
@@ -94,28 +94,28 @@ bb0(%0 : $A & P, %1 : $A & P):
9494
// We want to make sure that we picked up on the FIRST store and not the second one.
9595
// class C's foo method is named "bar" whereas class B's foo method is named "foo".
9696
// We want to make sure that we call a function named "foo" not "bar".
97-
// CHECK: [[FN:%[0-9]+]] = function_ref @${{.*}}foo{{.*}} : $@convention(thin) () -> Int
98-
%7 = witness_method $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P, #P.foo!1 : <Self where Self : P> (Self) -> () -> Int, %2 : $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int
97+
// CHECK: [[FN:%[0-9]+]] = function_ref @${{.*}}foo{{.*}} : $@convention(thin) () -> Int64
98+
%7 = witness_method $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P, #P.foo!1 : <Self where Self : P> (Self) -> () -> Int64, %2 : $@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
9999
// CHECK: apply [[FN]]
100-
%8 = apply %7<@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P>(%5) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int
100+
%8 = apply %7<@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P>(%5) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
101101

102102
store %3 to %5 : $*@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P
103103
dealloc_stack %5 : $*@opened("A1F1B526-1463-11EA-932F-ACBC329C418B") A & P
104-
return %8 : $Int
104+
return %8 : $Int64
105105
// CHECK-LABEL: end sil function {{.*}}impl{{.*}}
106106
} // end sil function 'impl'
107107

108108
// C.foo()
109-
sil @bar : $@convention(method) (@guaranteed C) -> Int
109+
sil @bar : $@convention(method) (@guaranteed C) -> Int64
110110

111111
sil_vtable [serialized] B {
112-
#B.foo!1: (B) -> () -> Int : @foo // B.foo()
112+
#B.foo!1: (B) -> () -> Int64 : @foo // B.foo()
113113
}
114114

115115
sil_vtable [serialized] C {
116-
#C.foo!1: (C) -> () -> Int : @bar
116+
#C.foo!1: (C) -> () -> Int64 : @bar
117117
}
118118

119119
sil_witness_table [serialized] B: P module run {
120-
method #P.foo!1: <Self where Self : P> (Self) -> () -> Int : @Pfoo // protocol witness for P.foo() in conformance B
120+
method #P.foo!1: <Self where Self : P> (Self) -> () -> Int64 : @Pfoo // protocol witness for P.foo() in conformance B
121121
}

0 commit comments

Comments
 (0)