1 ; RUN: llc -mtriple=hexagon-unknown--elf -hexagon-initial-cfg-cleanup=false < %s | FileCheck %s
2 ; RUN: llc -mtriple=hexagon-unknown--elf -hexagon-initial-cfg-cleanup=false -mattr=+noreturn-stack-elim < %s | FileCheck %s --check-prefix=CHECK-FLAG
4 ; Test the noreturn stack elimination feature. We've added a new flag/feature
5 ; that attempts to eliminate the local stack for noreturn nounwind functions.
6 ; The optimization eliminates the need to save callee saved registers, and
7 ; eliminates the allocframe, when no local stack space is needed.
9 %struct.A = type { i32, i32 }
11 ; Test the case when noreturn-stack-elim determins that both callee saved
12 ; register do not need to be saved, and the allocframe can be eliminated.
15 ; CHECK: memd(r29+#-16) = r17:16
18 ; CHECK-FLAG-LABEL: test1
19 ; CHECK-FLAG-NOT: memd(r29+#-16) = r17:16
20 ; CHECK-FLAG-NOT: allocframe
22 define dso_local void @test1(i32 %a, %struct.A* %b) local_unnamed_addr #0 {
24 %n = getelementptr inbounds %struct.A, %struct.A* %b, i32 0, i32 0
25 store i32 %a, i32* %n, align 4
26 tail call void @f1() #3
27 tail call void @nrf1(%struct.A* %b) #4
31 ; Test that noreturn-stack-elim doesn't eliminate the local stack, when
32 ; a function needs to allocate a local variable.
37 ; CHECK-FLAG-LABEL: test2
38 ; CHECK-FLAG: allocframe
40 define dso_local void @test2() local_unnamed_addr #0 {
42 %a = alloca i32, align 4
43 %0 = bitcast i32* %a to i8*
44 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4
45 call void @f3(i32* nonnull %a) #4
49 ; Test that noreturn-stack-elim can elimnate the allocframe when no locals
50 ; are allocated on the stack.
55 ; CHECK-FLAG-LABEL: test3
56 ; CHECK-FLAG-NOT: allocframe
58 define dso_local void @test3(i32 %a) local_unnamed_addr #0 {
60 %add = add nsw i32 %a, 5
61 call void @f2(i32 %add)
65 ; Test that nothing is optimized when an alloca is needed for local stack.
70 ; CHECK-FLAG-LABEL: test4
71 ; CHECK-FLAG: allocframe
73 define dso_local void @test4(i32 %n) local_unnamed_addr #0 {
75 %vla = alloca i32, i32 %n, align 8
76 call void @f3(i32* nonnull %vla) #4
81 declare dso_local void @f1() local_unnamed_addr
82 declare dso_local void @f2(i32) local_unnamed_addr
83 declare dso_local void @f3(i32*) local_unnamed_addr
85 declare dso_local void @nrf1(%struct.A*) local_unnamed_addr #2
87 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #5
89 attributes #0 = { noreturn nounwind }
90 attributes #2 = { noreturn }
91 attributes #3 = { nounwind }
92 attributes #4 = { noreturn nounwind }
93 attributes #5 = { argmemonly nounwind }