1; RUN: llc -mtriple=armv6m-linux-gnueabi -verify-machineinstrs -o - %s -disable-constant-hoisting | FileCheck %s
2
3%struct_type = type { [10000 x i32], i32, i32 }
4
5define void @test1(%struct_type** %s, i32 %n) {
6; CHECK-LABEL: test1
7entry:
8  %struct = load %struct_type*, %struct_type** %s
9  br label %while_cond
10
11while_cond:
12  %phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
13  %gep0 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 1
14  %gep1 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 2
15  %cmp = icmp slt i32 %phi, %n
16  br i1 %cmp, label %while_body, label %while_end
17
18while_body:
19; CHECK:      str      r{{[0-9]+}}, [r{{[0-9]+}}]
20; CHECK-NEXT: str      r{{[0-9]+}}, [r{{[0-9]+}}, #4]
21  %i = add i32 %phi, 1
22  store i32 %i, i32* %gep0
23  store i32 %phi, i32* %gep1
24  br label %while_cond
25
26while_end:
27  ret void
28; CHECK: .LCPI0_0:
29; CHECK-NEXT: .long   40000
30; CHECK-NOT: LCPI0
31}
32
33define void @test2(%struct_type* %struct, i32 %n) {
34; CHECK-LABEL: test2
35entry:
36  %cmp = icmp eq %struct_type* %struct, null
37  br i1 %cmp, label %while_end, label %while_cond
38
39while_cond:
40  %phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
41  %gep0 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 1
42  %gep1 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 2
43  %cmp1 = icmp slt i32 %phi, %n
44  br i1 %cmp1, label %while_body, label %while_end
45
46while_body:
47; CHECK:      str      r{{[0-9]+}}, [r{{[0-9]+}}]
48; CHECK-NEXT: str      r{{[0-9]+}}, [r{{[0-9]+}}, #4]
49  %i = add i32 %phi, 1
50  store i32 %i, i32* %gep0
51  store i32 %phi, i32* %gep1
52  br label %while_cond
53
54while_end:
55  ret void
56; CHECK: .LCPI1_0:
57; CHECK-NEXT: .long   40000
58; CHECK-NOT: LCPI1
59}
60
61define void @test3(%struct_type* %s1, %struct_type* %s2, i1 %cond, i32 %n) {
62; CHECK-LABEL: test3
63entry:
64  br i1 %cond, label %if_true, label %if_end
65
66if_true:
67  br label %if_end
68
69if_end:
70  %struct = phi %struct_type* [ %s1, %entry ], [ %s2, %if_true ]
71  %cmp = icmp eq %struct_type* %struct, null
72  br i1 %cmp, label %while_end, label %while_cond
73
74while_cond:
75  %phi = phi i32 [ 0, %if_end ], [ %i, %while_body ]
76  %gep0 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 1
77  %gep1 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 2
78  %cmp1 = icmp slt i32 %phi, %n
79  br i1 %cmp1, label %while_body, label %while_end
80
81while_body:
82; CHECK:      str      r{{[0-9]+}}, [r{{[0-9]+}}]
83; CHECK-NEXT: str      r{{[0-9]+}}, [r{{[0-9]+}}, #4]
84  %i = add i32 %phi, 1
85  store i32 %i, i32* %gep0
86  store i32 %phi, i32* %gep1
87  br label %while_cond
88
89while_end:
90  ret void
91; CHECK: .LCPI2_0:
92; CHECK-NEXT: .long   40000
93; CHECK-NOT: LCPI2
94}
95
96declare %struct_type* @foo()
97
98define void @test4(i32 %n) personality i32 (...)* @__FrameHandler {
99; CHECK-LABEL: test4
100entry:
101  %struct = invoke %struct_type* @foo() to label %while_cond unwind label %cleanup
102
103while_cond:
104  %phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
105  %gep0 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 1
106  %gep1 = getelementptr %struct_type, %struct_type* %struct, i64 0, i32 2
107  %cmp = icmp slt i32 %phi, %n
108  br i1 %cmp, label %while_body, label %while_end
109
110while_body:
111; CHECK:      str      r{{[0-9]+}}, [r{{[0-9]+}}]
112; CHECK-NEXT: str      r{{[0-9]+}}, [r{{[0-9]+}}, #4]
113  %i = add i32 %phi, 1
114  store i32 %i, i32* %gep0
115  store i32 %phi, i32* %gep1
116  br label %while_cond
117
118while_end:
119  ret void
120
121cleanup:
122  landingpad { i8*, i32 } cleanup
123  unreachable
124; CHECK: .LCPI3_0:
125; CHECK-NEXT: .long   40000
126; CHECK-NOT: LCPI3
127}
128
129declare i32 @__FrameHandler(...)
130
131define void @test5([65536 x i32]** %s, i32 %n) {
132; CHECK-LABEL: test5
133entry:
134  %struct = load [65536 x i32]*, [65536 x i32]** %s
135  br label %while_cond
136
137while_cond:
138  %phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
139  %gep0 = getelementptr [65536 x i32], [65536 x i32]* %struct, i64 0, i32 20000
140  %gep1 = getelementptr [65536 x i32], [65536 x i32]* %struct, i64 0, i32 20001
141  %cmp = icmp slt i32 %phi, %n
142  br i1 %cmp, label %while_body, label %while_end
143
144while_body:
145; CHECK:      str      r{{[0-9]+}}, [r{{[0-9]+}}]
146; CHECK-NEXT: str      r{{[0-9]+}}, [r{{[0-9]+}}, #4]
147  %i = add i32 %phi, 1
148  store i32 %i, i32* %gep0
149  store i32 %phi, i32* %gep1
150  br label %while_cond
151
152while_end:
153  ret void
154; CHECK: .LCPI4_0:
155; CHECK-NEXT: .long   80000
156; CHECK-NOT: LCPI4
157}
158