Skip to content

Commit e9428d3

Browse files
authored
Merge pull request #11300 from swiftix/optimizer-improvements
[sil-combine] Minor improvement to the peephole for removal of alloc_ref instructions that are only allocated and then deallocated
2 parents 71743d6 + f802fe4 commit e9428d3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ SILInstruction *SILCombiner::visitAllocRefInst(AllocRefInst *AR) {
447447
auto *Op = *UI;
448448
++UI;
449449
auto *User = Op->getUser();
450-
if (!isa<DeallocRefInst>(User) && !isa<SetDeallocatingInst>(User)) {
450+
if (!isa<DeallocRefInst>(User) && !isa<SetDeallocatingInst>(User) &&
451+
!isa<FixLifetimeInst>(User)) {
451452
HasNonRemovableUses = true;
452453
break;
453454
}

test/SILOptimizer/sil_combine.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,20 @@ bb0(%0 : $*B):
24132413
return %2 : $()
24142414
}
24152415

2416+
// CHECK-LABEL: sil @delete_dead_alloc_ref
2417+
// CHECK: bb0
2418+
// CHECK-NEXT: tuple
2419+
// CHECK-NEXT: return
2420+
sil @delete_dead_alloc_ref : $() -> () {
2421+
bb0:
2422+
%1 = alloc_ref $B
2423+
set_deallocating %1 : $B
2424+
fix_lifetime %1 : $B
2425+
dealloc_ref %1 : $B
2426+
%2 = tuple()
2427+
return %2 : $()
2428+
}
2429+
24162430
// CHECK-LABEL: sil @delete_dead_alloc_stack2
24172431
// CHECK: bb0
24182432
// CHECK-NEXT: destroy_addr %0

0 commit comments

Comments
 (0)