Skip to content

Commit 24f1b7a

Browse files
delete dead stack slots (#104)
deletes slots that have lifetime markers and the lifetime ranges are empty.
1 parent 33374c4 commit 24f1b7a

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,8 +1249,15 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) {
12491249

12501250
// Do not bother looking at empty intervals.
12511251
for (unsigned I = 0; I < NumSlots; ++I) {
1252-
if (Intervals[SortedSlots[I]]->empty())
1252+
int Slot = SortedSlots[I];
1253+
if (Intervals[Slot]->empty()) {
1254+
if (InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot)) {
1255+
RemovedSlots += 1;
1256+
ReducedSize += MFI->getObjectSize(Slot);
1257+
MFI->RemoveStackObject(Slot);
1258+
}
12531259
SortedSlots[I] = -1;
1260+
}
12541261
}
12551262

12561263
// This is a simple greedy algorithm for merging allocas. First, sort the

llvm/test/CodeGen/PowerPC/aix32-cc-abi-vaarg.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ entry:
347347

348348
; 32BIT-LABEL: stack:
349349
; 32BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 4, alignment: 4,
350-
; 32BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 4, alignment: 4,
351350
; 32BIT-DAG: - { id: 2, name: '', type: default, offset: 0, size: 8, alignment: 8,
352351
; 32BIT-DAG: - { id: 3, name: '', type: default, offset: 0, size: 8, alignment: 8,
353352

llvm/test/CodeGen/PowerPC/aix64-cc-abi-vaarg.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@
138138
; 64BIT-LABEL: fixedStack:
139139
; 64BIT-DAG: - { id: 0, type: default, offset: 112, size: 8, alignment: 16, stack-id: default,
140140

141-
; 64BIT-LABEL: stack:
142-
; 64BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 8, alignment: 8,
143-
; 64BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 8, alignment: 8,
141+
; 64BIT-LABEL: stack: []
144142

145143
; 64BIT-LABEL: body: |
146144
; 64BIT-DAG: liveins: $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10
@@ -305,9 +303,7 @@
305303
; 64BIT-LABEL: fixedStack:
306304
; 64BIT-DAG: - { id: 0, type: default, offset: 152, size: 8
307305

308-
; 64BIT-LABEL: stack:
309-
; 64BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 8
310-
; 64BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 8
306+
; 64BIT-LABEL: stack: []
311307

312308
; 64BIT-LABEL: body: |
313309
; 64BIT-DAG: liveins: $f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10, $f11, $f12, $f13
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s -check-prefix=RV32I
4+
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5+
; RUN: | FileCheck %s -check-prefix=RV64I
6+
7+
; Remove the lifetime-marked alloca, but not the unmarked one.
8+
define dso_local signext i32 @f1() nounwind {
9+
; RV32I-LABEL: f1:
10+
; RV32I: # %bb.0:
11+
; RV32I-NEXT: addi sp, sp, -32
12+
; RV32I-NEXT: li a0, 0
13+
; RV32I-NEXT: addi sp, sp, 32
14+
; RV32I-NEXT: ret
15+
;
16+
; RV64I-LABEL: f1:
17+
; RV64I: # %bb.0:
18+
; RV64I-NEXT: addi sp, sp, -32
19+
; RV64I-NEXT: li a0, 0
20+
; RV64I-NEXT: addi sp, sp, 32
21+
; RV64I-NEXT: ret
22+
%1 = alloca [32 x i8], align 4
23+
%2 = alloca [32 x i8], align 4
24+
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
25+
call void @llvm.lifetime.start.p0i8(i64 32, i8* nonnull %3)
26+
call void @llvm.lifetime.end.p0i8(i64 32, i8* nonnull %3)
27+
ret i32 0
28+
}
29+
30+
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
31+
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
32+

0 commit comments

Comments
 (0)