Skip to content

Commit 857a6c3

Browse files
authored
Merge pull request #72116 from eeckstein/fix-cse-apply
CSE: fix checking convention of tuple apply results
2 parents 8569b6e + ad3178a commit 857a6c3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,8 @@ bool CSE::canHandle(SILInstruction *Inst) {
11361136
if (!AI->getFunction()->hasOwnership()) {
11371137
// In non-OSSA we don't balance CSE'd apply results which return an
11381138
// owned value.
1139-
if (auto ri = AI->getSingleResult()) {
1140-
if (ri.value().getConvention() != ResultConvention::Unowned)
1139+
for (const SILResultInfo &ri : AI->getSubstCalleeType()->getResults()) {
1140+
if (ri.getConvention() != ResultConvention::Unowned)
11411141
return false;
11421142
}
11431143
}

test/SILOptimizer/cse_apply.sil

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bb0(%0 : $Int64):
126126
return %14 : $Int64
127127
}
128128

129-
//CHECK-LABEL: sil @dont_cse_retain_only_apply
129+
//CHECK-LABEL: sil @dont_cse_retain_only_apply :
130130
//CHECK: %{{[0-9]+}} = apply
131131
//CHECK: %{{[0-9]+}} = apply
132132
//CHECK: return
@@ -141,3 +141,45 @@ bb0:
141141
return %r : $()
142142
}
143143

144+
sil @get_tuple : $@convention(thin) () -> (@owned XX, Int) {
145+
[global: ]
146+
}
147+
148+
//CHECK-LABEL: sil @dont_cse_retain_only_apply2 :
149+
//CHECK: %{{[0-9]+}} = apply %0
150+
//CHECK: %{{[0-9]+}} = apply %0
151+
//CHECK: } // end sil function 'dont_cse_retain_only_apply2'
152+
sil @dont_cse_retain_only_apply2 : $@convention(thin) () -> () {
153+
bb0:
154+
%0 = function_ref @get_tuple : $@convention(thin) () -> (@owned XX, Int)
155+
%1 = apply %0() : $@convention(thin) () -> (@owned XX, Int)
156+
%2 = tuple_extract %1 : $(XX, Int), 0
157+
release_value %2 : $XX
158+
%4 = apply %0() : $@convention(thin) () -> (@owned XX, Int)
159+
%5 = tuple_extract %4 : $(XX, Int), 0
160+
release_value %5 : $XX
161+
%6 = tuple ()
162+
return %6 : $()
163+
}
164+
165+
sil @get_trivial_tuple : $@convention(thin) () -> (Int, Int) {
166+
[global: ]
167+
}
168+
169+
//CHECK-LABEL: sil @cse_apply_with_trivial_result :
170+
//CHECK: [[R:%.*]] = apply %0
171+
//CHECK-NEXT: [[I:%.*]] = tuple_extract [[R]] : $(Int, Int), 0
172+
//CHECK-NEXT: [[T:%.*]] = tuple ([[I]] : $Int, [[I]] : $Int)
173+
//CHECK-NEXT: return [[T]]
174+
//CHECK: } // end sil function 'cse_apply_with_trivial_result'
175+
sil @cse_apply_with_trivial_result : $@convention(thin) () -> (Int, Int) {
176+
bb0:
177+
%0 = function_ref @get_trivial_tuple : $@convention(thin) () -> (Int, Int)
178+
%1 = apply %0() : $@convention(thin) () -> (Int, Int)
179+
%2 = tuple_extract %1 : $(Int, Int), 0
180+
%4 = apply %0() : $@convention(thin) () -> (Int, Int)
181+
%5 = tuple_extract %4 : $(Int, Int), 0
182+
%6 = tuple (%2 : $Int, %5 : $Int)
183+
return %6 : $(Int, Int)
184+
}
185+

0 commit comments

Comments
 (0)