Skip to content

Commit 8edfd9c

Browse files
authored
Merge pull request #84662 from eeckstein/fix-dead-alloc-elimination
DeadAllocElimination: fix a bug when promoting mark_dependence instructions
2 parents 89052a7 + 214be2d commit 8edfd9c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,7 @@ SILValue OptimizeDeadAlloc::promoteMarkDepBase(
23392339
}
23402340
LLVM_DEBUG(llvm::dbgs() << " To value: " << dependentValue);
23412341
md->replaceAllUsesWith(dependentValue);
2342-
deleter.deleteIfDead(md);
2342+
deleter.forceDelete(md);
23432343
return dependentValue;
23442344
}
23452345

test/SILOptimizer/mandatory_performance_optimizations.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import Builtin
99
import Swift
1010
import SwiftShims
1111

12+
struct NonTrivialStruct {
13+
var s: String
14+
}
15+
1216
sil_global [let] @g1 : $Int32
1317
sil_global [let] @g2 : $Int32
1418

@@ -203,6 +207,27 @@ bb3:
203207
return %1 : $Int32
204208
}
205209

210+
sil @createNonTrivialStruct : $@convention(thin) (Int) -> @owned NonTrivialStruct
211+
212+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] [ossa] @test_dead_alloc_elimination_with_mark_dependence :
213+
// CHECK-NOT: alloc_stack
214+
// CHECK: } // end sil function 'test_dead_alloc_elimination_with_mark_dependence'
215+
sil [ossa] [no_allocation] @test_dead_alloc_elimination_with_mark_dependence : $@convention(thin) (Int) -> () {
216+
bb0(%0 : $Int):
217+
%1 = alloc_stack [lexical] $Int
218+
store %0 to [trivial] %1
219+
%4 = load [trivial] %1
220+
%5 = function_ref @createNonTrivialStruct : $@convention(thin) (Int) -> @owned NonTrivialStruct
221+
%6 = apply %5(%4) : $@convention(thin) (Int) -> @owned NonTrivialStruct
222+
%7 = mark_dependence [nonescaping] %6 on %1
223+
%9 = mark_dependence [nonescaping] %7 on %1
224+
%10 = destructure_struct %9
225+
destroy_value %10
226+
%12 = tuple ()
227+
dealloc_stack %1
228+
return %12
229+
}
230+
206231
// CHECK-LABEL: sil [no_locks] [perf_constraint] [ossa] @remove_metatype_arg :
207232
// CHECK: [[F:%.*]] = function_ref @$s12metatype_argTf4ndn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
208233
// CHECK: [[A:%.*]] = apply [[F]](%0, %1) : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject

0 commit comments

Comments
 (0)