Skip to content

Commit d91759d

Browse files
committed
SILCombine: remove the dead alloc_ref peephole optimization
It's not needed because dead alloc_refs are removed by the DeadObjectElimination pass
1 parent 83754fa commit d91759d

File tree

5 files changed

+0
-196
lines changed

5 files changed

+0
-196
lines changed

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ class SILCombiner :
253253
SILInstruction *visitIndexAddrInst(IndexAddrInst *IA);
254254
bool optimizeStackAllocatedEnum(AllocStackInst *AS);
255255
SILInstruction *visitAllocStackInst(AllocStackInst *AS);
256-
SILInstruction *visitAllocRefInst(AllocRefInst *AR);
257256
SILInstruction *visitSwitchEnumAddrInst(SwitchEnumAddrInst *SEAI);
258257
SILInstruction *visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI);
259258
SILInstruction *visitPointerToAddressInst(PointerToAddressInst *PTAI);

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -745,32 +745,6 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
745745
return eraseInstFromFunction(*AS);
746746
}
747747

748-
SILInstruction *SILCombiner::visitAllocRefInst(AllocRefInst *AR) {
749-
// Check if the only uses are deallocating stack or deallocating.
750-
SmallPtrSet<SILInstruction *, 16> ToDelete;
751-
bool HasNonRemovableUses = false;
752-
for (auto UI = AR->use_begin(), UE = AR->use_end(); UI != UE;) {
753-
auto *Op = *UI;
754-
++UI;
755-
auto *User = Op->getUser();
756-
if (!isa<DeallocRefInst>(User) && !isa<SetDeallocatingInst>(User) &&
757-
!isa<FixLifetimeInst>(User) && !isa<DeallocStackRefInst>(User)) {
758-
HasNonRemovableUses = true;
759-
break;
760-
}
761-
ToDelete.insert(User);
762-
}
763-
764-
if (HasNonRemovableUses)
765-
return nullptr;
766-
767-
// Remove the instruction and all its uses.
768-
for (auto *I : ToDelete)
769-
eraseInstFromFunction(*I);
770-
eraseInstFromFunction(*AR);
771-
return nullptr;
772-
}
773-
774748
/// Returns the base address if \p val is an index_addr with constant index.
775749
static SILValue isConstIndexAddr(SILValue val, unsigned &index) {
776750
auto *IA = dyn_cast<IndexAddrInst>(val);

test/SILOptimizer/sil_combine.sil

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,20 +2617,6 @@ bb0(%0 : $*B):
26172617
return %2 : $()
26182618
}
26192619

2620-
// CHECK-LABEL: sil @delete_dead_alloc_ref
2621-
// CHECK: bb0
2622-
// CHECK-NEXT: tuple
2623-
// CHECK-NEXT: return
2624-
sil @delete_dead_alloc_ref : $() -> () {
2625-
bb0:
2626-
%1 = alloc_ref $B
2627-
set_deallocating %1 : $B
2628-
fix_lifetime %1 : $B
2629-
dealloc_ref %1 : $B
2630-
%2 = tuple()
2631-
return %2 : $()
2632-
}
2633-
26342620
// CHECK-LABEL: sil @delete_dead_alloc_stack2
26352621
// CHECK: bb0
26362622
// CHECK-NEXT: destroy_addr %0
@@ -3521,31 +3507,6 @@ bb0:
35213507
}
35223508

35233509

3524-
// CHECK-LABEL: sil @remove_unused_alloc_ref
3525-
// CHECK-NEXT: bb0
3526-
// CHECK-NEXT: %0 = tuple ()
3527-
// CHECK-NEXT: return %0 : $()
3528-
sil @remove_unused_alloc_ref : $@convention(thin) () -> () {
3529-
bb0:
3530-
%1 = alloc_ref $B
3531-
dealloc_ref %1 : $B
3532-
%3 = tuple ()
3533-
return %3 : $()
3534-
}
3535-
3536-
// CHECK-LABEL: sil @remove_unused_alloc_ref_stack
3537-
// CHECK-NEXT: bb0
3538-
// CHECK-NEXT: %0 = tuple ()
3539-
// CHECK-NEXT: return %0 : $()
3540-
sil @remove_unused_alloc_ref_stack : $@convention(thin) () -> () {
3541-
bb0:
3542-
%1 = alloc_ref [stack] $B
3543-
set_deallocating %1 : $B
3544-
dealloc_stack_ref %1 : $B
3545-
%3 = tuple ()
3546-
return %3 : $()
3547-
}
3548-
35493510
// Int1_const == x -> x == Int1_const
35503511
// CHECK-LABEL: sil @canonicalize_bool_eq_checks
35513512
sil @canonicalize_bool_eq_checks : $@convention(thin) (Builtin.Int1) -> Builtin.Int1 {

test/SILOptimizer/sil_combine_misc_opts.sil

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -61,94 +61,6 @@ bb0(%0 : $Klass):
6161
return %9999 : $()
6262
}
6363

64-
// Unused alloc-ref elim
65-
66-
// CHECK-LABEL: sil @remove_unused_alloc_ref :
67-
// CHECK-NOT: alloc_ref
68-
// CHECK-NOT: dealloc_ref
69-
// CHECK: } // end sil function 'remove_unused_alloc_ref'
70-
sil @remove_unused_alloc_ref : $@convention(thin) () -> () {
71-
bb0:
72-
%1 = alloc_ref $Klass
73-
dealloc_ref %1 : $Klass
74-
%3 = tuple ()
75-
return %3 : $()
76-
}
77-
78-
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_ossa :
79-
// CHECK-NOT: alloc_ref
80-
// CHECK-NOT: dealloc_ref
81-
// CHECK: } // end sil function 'remove_unused_alloc_ref_ossa'
82-
sil [ossa] @remove_unused_alloc_ref_ossa : $@convention(thin) () -> () {
83-
bb0:
84-
%1 = alloc_ref $Klass
85-
dealloc_ref %1 : $Klass
86-
%3 = tuple ()
87-
return %3 : $()
88-
}
89-
90-
// CHECK-LABEL: sil @remove_unused_alloc_ref_stack :
91-
// CHECK-NOT: alloc_ref
92-
// CHECK-NOT: set_deallocating
93-
// CHECK-NOT: dealloc_ref
94-
// CHECK: } // end sil function 'remove_unused_alloc_ref_stack'
95-
sil @remove_unused_alloc_ref_stack : $@convention(thin) () -> () {
96-
bb0:
97-
%1 = alloc_ref [stack] $Klass
98-
set_deallocating %1 : $Klass
99-
dealloc_stack_ref %1 : $Klass
100-
%3 = tuple ()
101-
return %3 : $()
102-
}
103-
104-
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_stack_ossa :
105-
// CHECK-NOT: alloc_ref
106-
// CHECK-NOT: set_deallocating
107-
// CHECK-NOT: dealloc_ref
108-
// CHECK: } // end sil function 'remove_unused_alloc_ref_stack_ossa'
109-
sil [ossa] @remove_unused_alloc_ref_stack_ossa : $@convention(thin) () -> () {
110-
bb0:
111-
%1 = alloc_ref [stack] $Klass
112-
set_deallocating %1 : $Klass
113-
dealloc_ref %1 : $Klass
114-
dealloc_stack_ref %1 : $Klass
115-
%3 = tuple ()
116-
return %3 : $()
117-
}
118-
119-
// CHECK-LABEL: sil @remove_unused_alloc_ref_fixlifetime :
120-
// CHECK-NOT: alloc_ref
121-
// CHECK-NOT: set_deallocating
122-
// CHECK-NOT: dealloc_ref
123-
// CHECK-NOT: fix_lifetime
124-
// CHECK: } // end sil function 'remove_unused_alloc_ref_fixlifetime'
125-
sil @remove_unused_alloc_ref_fixlifetime : $@convention(thin) () -> () {
126-
bb0:
127-
%1 = alloc_ref [stack] $Klass
128-
set_deallocating %1 : $Klass
129-
fix_lifetime %1 : $Klass
130-
dealloc_stack_ref %1 : $Klass
131-
%3 = tuple ()
132-
return %3 : $()
133-
}
134-
135-
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_fixlifetime_ossa :
136-
// CHECK-NOT: alloc_ref
137-
// CHECK-NOT: set_deallocating
138-
// CHECK-NOT: dealloc_ref
139-
// CHECK-NOT: fix_lifetime
140-
// CHECK: } // end sil function 'remove_unused_alloc_ref_fixlifetime_ossa'
141-
sil [ossa] @remove_unused_alloc_ref_fixlifetime_ossa : $@convention(thin) () -> () {
142-
bb0:
143-
%1 = alloc_ref [stack] $Klass
144-
set_deallocating %1 : $Klass
145-
fix_lifetime %1 : $Klass
146-
dealloc_ref %1 : $Klass
147-
dealloc_stack_ref %1 : $Klass
148-
%3 = tuple ()
149-
return %3 : $()
150-
}
151-
15264
// We should have a single load [copy] here.
15365
//
15466
// CHECK-LABEL: sil [ossa] @remove_loadcopy_with_only_destroy_users : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () {

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,21 +3194,6 @@ bb0(%0 : $*B):
31943194
return %2 : $()
31953195
}
31963196

3197-
// CHECK-LABEL: sil [ossa] @delete_dead_alloc_ref :
3198-
// CHECK: bb0
3199-
// CHECK-NEXT: tuple
3200-
// CHECK-NEXT: return
3201-
// CHECK: } // end sil function 'delete_dead_alloc_ref'
3202-
sil [ossa] @delete_dead_alloc_ref : $() -> () {
3203-
bb0:
3204-
%1 = alloc_ref $B
3205-
set_deallocating %1 : $B
3206-
fix_lifetime %1 : $B
3207-
dealloc_ref %1 : $B
3208-
%2 = tuple()
3209-
return %2 : $()
3210-
}
3211-
32123197
// CHECK-LABEL: sil [ossa] @delete_dead_alloc_stack2
32133198
// XHECK: bb0
32143199
// XHECK-NEXT: destroy_addr %0
@@ -4044,33 +4029,6 @@ bb0:
40444029
return %9 : $AnyObject
40454030
}
40464031

4047-
4048-
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref
4049-
// CHECK-NEXT: bb0
4050-
// CHECK-NEXT: %0 = tuple ()
4051-
// CHECK-NEXT: return %0 : $()
4052-
sil [ossa] @remove_unused_alloc_ref : $@convention(thin) () -> () {
4053-
bb0:
4054-
%1 = alloc_ref $B
4055-
dealloc_ref %1 : $B
4056-
%3 = tuple ()
4057-
return %3 : $()
4058-
}
4059-
4060-
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_stack
4061-
// CHECK-NEXT: bb0
4062-
// CHECK-NEXT: %0 = tuple ()
4063-
// CHECK-NEXT: return %0 : $()
4064-
sil [ossa] @remove_unused_alloc_ref_stack : $@convention(thin) () -> () {
4065-
bb0:
4066-
%1 = alloc_ref [stack] $B
4067-
set_deallocating %1 : $B
4068-
dealloc_ref %1 : $B
4069-
dealloc_stack_ref %1 : $B
4070-
%3 = tuple ()
4071-
return %3 : $()
4072-
}
4073-
40744032
// Int1_const == x -> x == Int1_const
40754033
// CHECK-LABEL: sil [ossa] @canonicalize_bool_eq_checks :
40764034
// CHECK: builtin "cmp_eq_Int1"(%0 : $Builtin.Int1, %1 :

0 commit comments

Comments
 (0)