1 ; Test that accesses of the stack remain within the range defined by R1,
2 ; i.e. that loads and stores only access the allocated stack. This does not
3 ; have to be the case when red zone is present.
5 ; Make sure that there is no red zone, i.e. ppc32 and SVR4 ABI.
6 ; RUN: llc -mtriple=powerpc--freebsd-elf < %s | FileCheck %s
8 ; There are two ways that the stack pointer can be adjusted in the prologue:
9 ; - by adding an immediate value:
11 ; - by adding another register:
14 ; The restoring of the stack pointer can be done:
15 ; - by adding an immediate value to it:
17 ; - by copying the value from another register:
21 ; Nothing (no special features).
23 ; CHECK-LABEL: test_n:
24 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
25 ; CHECK: stwu 1, -[[SIZE:[0-9]+]](1)
26 ; CHECK: addi 1, 1, [[SIZE]]
27 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
28 define i32 @test_n() local_unnamed_addr #0 {
30 %t0 = tail call i32 bitcast (i32 (...)* @bar0 to i32 ()*)() #0
34 ; Aligned object on the stack.
36 ; CHECK-LABEL: test_a:
37 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
38 ; CHECK: stwux 1, 1, {{[0-9]+}}
39 ; CHECK: mr 1, {{[0-9]+}}
40 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
42 define i32 @test_a() local_unnamed_addr #0 {
44 %t0 = alloca i32, align 128
45 %t1 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
49 ; Dynamic allocation on the stack.
51 ; CHECK-LABEL: test_d:
52 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
53 ; CHECK: stwu 1, -[[SIZE:[0-9]+]](1)
54 ; CHECK: mr 1, {{[0-9]+}}
55 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
56 define i32 @test_d(i32 %p0) local_unnamed_addr #0 {
57 %t0 = alloca i32, i32 %p0, align 4
58 %t1 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
62 ; Large stack (exceeds size of D-field).
63 ; CHECK-LABEL: test_s:
64 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
65 ; CHECK: stwux 1, 1, {{[0-9]+}}
66 ; CHECK: mr 1, {{[0-9]+}}
67 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
68 define i32 @test_s(i32 %p0) local_unnamed_addr #0 {
70 %t0 = alloca [16384 x i32]
71 %t1 = getelementptr [16384 x i32], [16384 x i32]* %t0, i32 0, i32 0
72 %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
78 ; CHECK-LABEL: test_ad:
79 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
80 ; CHECK: stwux 1, 1, {{[0-9]+}}
81 ; CHECK: mr 1, {{[0-9]+}}
82 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
83 define i32 @test_ad(i32 %p0) local_unnamed_addr #0 {
84 %t0 = alloca i32, align 128
85 %t1 = alloca i32, i32 %p0, align 4
86 %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
87 %t3 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
88 %t4 = add i32 %t2, %t3
92 ; CHECK-LABEL: test_as:
93 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
94 ; CHECK: stwux 1, 1, {{[0-9]+}}
95 ; CHECK: mr 1, {{[0-9]+}}
96 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
97 define i32 @test_as() local_unnamed_addr #0 {
98 %t0 = alloca i32, align 128
99 %t1 = alloca [16384 x i32]
100 %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
101 %t3 = getelementptr [16384 x i32], [16384 x i32]* %t1, i32 0, i32 0
102 %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t3) #0
103 %t5 = add i32 %t2, %t4
107 ; CHECK-LABEL: test_ds:
108 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
109 ; CHECK: stwux 1, 1, {{[0-9]+}}
110 ; CHECK: mr 1, {{[0-9]+}}
111 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
112 define i32 @test_ds(i32 %p0) local_unnamed_addr #0 {
113 %t0 = alloca i32, i32 %p0, align 4
114 %t1 = alloca [16384 x i32]
115 %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
116 %t3 = getelementptr [16384 x i32], [16384 x i32]* %t1, i32 0, i32 0
117 %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t3) #0
118 %t5 = add i32 %t2, %t4
122 ; CHECK-LABEL: test_ads:
123 ; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
124 ; CHECK: stwux 1, 1, {{[0-9]+}}
125 ; CHECK: mr 1, {{[0-9]+}}
126 ; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
127 define i32 @test_ads(i32 %p0) local_unnamed_addr #0 {
128 %t0 = alloca i32, align 128
129 %t1 = alloca i32, i32 %p0, align 4
130 %t2 = alloca [16384 x i32]
132 %t3 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
133 %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
134 %t5 = add i32 %t3, %t4
136 %t6 = getelementptr [16384 x i32], [16384 x i32]* %t2, i32 0, i32 0
137 %t7 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t6) #0
138 %t8 = add i32 %t5, %t7
143 declare i32 @bar0(...) local_unnamed_addr #0
144 declare i32 @bar1(...) local_unnamed_addr #0
146 attributes #0 = { nounwind }