1; RUN: llc < %s -mtriple=ve | FileCheck %s
2; RUN: llc < %s -mtriple=ve -relocation-model=pic | \
3; RUN:     FileCheck %s -check-prefix=PIC
4
5%struct.__jmp_buf_tag = type { [25 x i64], i64, [16 x i64] }
6
7@buf = common global [1 x %struct.__jmp_buf_tag] zeroinitializer, align 8
8
9; Function Attrs: noinline nounwind optnone
10define signext i32 @t_setjmp() {
11; CHECK-LABEL: t_setjmp:
12; CHECK:       .LBB{{[0-9]+}}_5:
13; CHECK-NEXT:    st %s18, 48(, %s9) # 8-byte Folded Spill
14; CHECK-NEXT:    st %s19, 56(, %s9) # 8-byte Folded Spill
15; CHECK-NEXT:    st %s20, 64(, %s9) # 8-byte Folded Spill
16; CHECK-NEXT:    st %s21, 72(, %s9) # 8-byte Folded Spill
17; CHECK-NEXT:    st %s22, 80(, %s9) # 8-byte Folded Spill
18; CHECK-NEXT:    st %s23, 88(, %s9) # 8-byte Folded Spill
19; CHECK-NEXT:    st %s24, 96(, %s9) # 8-byte Folded Spill
20; CHECK-NEXT:    st %s25, 104(, %s9) # 8-byte Folded Spill
21; CHECK-NEXT:    st %s26, 112(, %s9) # 8-byte Folded Spill
22; CHECK-NEXT:    st %s27, 120(, %s9) # 8-byte Folded Spill
23; CHECK-NEXT:    st %s28, 128(, %s9) # 8-byte Folded Spill
24; CHECK-NEXT:    st %s29, 136(, %s9) # 8-byte Folded Spill
25; CHECK-NEXT:    st %s30, 144(, %s9) # 8-byte Folded Spill
26; CHECK-NEXT:    st %s31, 152(, %s9) # 8-byte Folded Spill
27; CHECK-NEXT:    st %s32, 160(, %s9) # 8-byte Folded Spill
28; CHECK-NEXT:    st %s33, 168(, %s9) # 8-byte Folded Spill
29; CHECK-NEXT:    lea %s0, buf@lo
30; CHECK-NEXT:    and %s0, %s0, (32)0
31; CHECK-NEXT:    lea.sl %s0, buf@hi(, %s0)
32; CHECK-NEXT:    st %s9, (, %s0)
33; CHECK-NEXT:    st %s11, 16(, %s0)
34; CHECK-NEXT:    lea %s1, .LBB{{[0-9]+}}_3@lo
35; CHECK-NEXT:    and %s1, %s1, (32)0
36; CHECK-NEXT:    lea.sl %s1, .LBB{{[0-9]+}}_3@hi(, %s1)
37; CHECK-NEXT:    st %s1, 8(, %s0)
38; CHECK-NEXT:    # EH_SJlJ_SETUP .LBB{{[0-9]+}}_3
39; CHECK-NEXT:  # %bb.1:
40; CHECK-NEXT:    lea %s0, 0
41; CHECK-NEXT:    br.l.t .LBB{{[0-9]+}}_2
42; CHECK-NEXT:  .LBB{{[0-9]+}}_3: # Block address taken
43; CHECK-NEXT:    lea %s0, 1
44; CHECK-NEXT:  .LBB{{[0-9]+}}_2:
45; CHECK-NEXT:    adds.w.sx %s0, %s0, (0)1
46; CHECK-NEXT:    ld %s33, 168(, %s9) # 8-byte Folded Reload
47; CHECK-NEXT:    ld %s32, 160(, %s9) # 8-byte Folded Reload
48; CHECK-NEXT:    ld %s31, 152(, %s9) # 8-byte Folded Reload
49; CHECK-NEXT:    ld %s30, 144(, %s9) # 8-byte Folded Reload
50; CHECK-NEXT:    ld %s29, 136(, %s9) # 8-byte Folded Reload
51; CHECK-NEXT:    ld %s28, 128(, %s9) # 8-byte Folded Reload
52; CHECK-NEXT:    ld %s27, 120(, %s9) # 8-byte Folded Reload
53; CHECK-NEXT:    ld %s26, 112(, %s9) # 8-byte Folded Reload
54; CHECK-NEXT:    ld %s25, 104(, %s9) # 8-byte Folded Reload
55; CHECK-NEXT:    ld %s24, 96(, %s9) # 8-byte Folded Reload
56; CHECK-NEXT:    ld %s23, 88(, %s9) # 8-byte Folded Reload
57; CHECK-NEXT:    ld %s22, 80(, %s9) # 8-byte Folded Reload
58; CHECK-NEXT:    ld %s21, 72(, %s9) # 8-byte Folded Reload
59; CHECK-NEXT:    ld %s20, 64(, %s9) # 8-byte Folded Reload
60; CHECK-NEXT:    ld %s19, 56(, %s9) # 8-byte Folded Reload
61; CHECK-NEXT:    ld %s18, 48(, %s9) # 8-byte Folded Reload
62; CHECK-NEXT:    or %s11, 0, %s9
63;
64; PIC-LABEL: t_setjmp:
65; PIC:       # %bb.0:
66; PIC-NEXT:    st %s9, (, %s11)
67; PIC-NEXT:    st %s10, 8(, %s11)
68; PIC-NEXT:    st %s15, 24(, %s11)
69; PIC-NEXT:    st %s16, 32(, %s11)
70; PIC-NEXT:    or %s9, 0, %s11
71; PIC-NEXT:    lea %s11, -176(, %s11)
72; PIC-NEXT:    brge.l %s11, %s8, .LBB0_5
73; PIC-NEXT:  # %bb.4:
74; PIC-NEXT:    ld %s61, 24(, %s14)
75; PIC-NEXT:    or %s62, 0, %s0
76; PIC-NEXT:    lea %s63, 315
77; PIC-NEXT:    shm.l %s63, (%s61)
78; PIC-NEXT:    shm.l %s8, 8(%s61)
79; PIC-NEXT:    shm.l %s11, 16(%s61)
80; PIC-NEXT:    monc
81; PIC-NEXT:    or %s0, 0, %s62
82; PIC-NEXT:  .LBB0_5:
83; PIC-NEXT:    st %s18, 48(, %s9) # 8-byte Folded Spill
84; PIC-NEXT:    st %s19, 56(, %s9) # 8-byte Folded Spill
85; PIC-NEXT:    st %s20, 64(, %s9) # 8-byte Folded Spill
86; PIC-NEXT:    st %s21, 72(, %s9) # 8-byte Folded Spill
87; PIC-NEXT:    st %s22, 80(, %s9) # 8-byte Folded Spill
88; PIC-NEXT:    st %s23, 88(, %s9) # 8-byte Folded Spill
89; PIC-NEXT:    st %s24, 96(, %s9) # 8-byte Folded Spill
90; PIC-NEXT:    st %s25, 104(, %s9) # 8-byte Folded Spill
91; PIC-NEXT:    st %s26, 112(, %s9) # 8-byte Folded Spill
92; PIC-NEXT:    st %s27, 120(, %s9) # 8-byte Folded Spill
93; PIC-NEXT:    st %s28, 128(, %s9) # 8-byte Folded Spill
94; PIC-NEXT:    st %s29, 136(, %s9) # 8-byte Folded Spill
95; PIC-NEXT:    st %s30, 144(, %s9) # 8-byte Folded Spill
96; PIC-NEXT:    st %s31, 152(, %s9) # 8-byte Folded Spill
97; PIC-NEXT:    st %s32, 160(, %s9) # 8-byte Folded Spill
98; PIC-NEXT:    st %s33, 168(, %s9) # 8-byte Folded Spill
99; PIC-NEXT:    lea %s15, _GLOBAL_OFFSET_TABLE_@pc_lo(-24)
100; PIC-NEXT:    and %s15, %s15, (32)0
101; PIC-NEXT:    sic %s16
102; PIC-NEXT:    lea.sl %s15, _GLOBAL_OFFSET_TABLE_@pc_hi(%s16, %s15)
103; PIC-NEXT:    lea %s0, buf@got_lo
104; PIC-NEXT:    and %s0, %s0, (32)0
105; PIC-NEXT:    lea.sl %s0, buf@got_hi(, %s0)
106; PIC-NEXT:    ld %s0, (%s0, %s15)
107; PIC-NEXT:    st %s9, (, %s0)
108; PIC-NEXT:    st %s11, 16(, %s0)
109; PIC-NEXT:    lea %s1, .LBB0_3@gotoff_lo
110; PIC-NEXT:    and %s1, %s1, (32)0
111; PIC-NEXT:    lea.sl %s1, .LBB0_3@gotoff_hi(%s1, %s15)
112; PIC-NEXT:    st %s1, 8(, %s0)
113; PIC-NEXT:    # EH_SJlJ_SETUP .LBB0_3
114; PIC-NEXT:  # %bb.1:
115; PIC-NEXT:    lea %s0, 0
116; PIC-NEXT:    br.l.t .LBB0_2
117; PIC-NEXT:  .LBB0_3: # Block address taken
118; PIC-NEXT:    lea %s0, 1
119; PIC-NEXT:  .LBB0_2:
120; PIC-NEXT:    adds.w.sx %s0, %s0, (0)1
121; PIC-NEXT:    ld %s33, 168(, %s9) # 8-byte Folded Reload
122; PIC-NEXT:    ld %s32, 160(, %s9) # 8-byte Folded Reload
123; PIC-NEXT:    ld %s31, 152(, %s9) # 8-byte Folded Reload
124; PIC-NEXT:    ld %s30, 144(, %s9) # 8-byte Folded Reload
125; PIC-NEXT:    ld %s29, 136(, %s9) # 8-byte Folded Reload
126; PIC-NEXT:    ld %s28, 128(, %s9) # 8-byte Folded Reload
127; PIC-NEXT:    ld %s27, 120(, %s9) # 8-byte Folded Reload
128; PIC-NEXT:    ld %s26, 112(, %s9) # 8-byte Folded Reload
129; PIC-NEXT:    ld %s25, 104(, %s9) # 8-byte Folded Reload
130; PIC-NEXT:    ld %s24, 96(, %s9) # 8-byte Folded Reload
131; PIC-NEXT:    ld %s23, 88(, %s9) # 8-byte Folded Reload
132; PIC-NEXT:    ld %s22, 80(, %s9) # 8-byte Folded Reload
133; PIC-NEXT:    ld %s21, 72(, %s9) # 8-byte Folded Reload
134; PIC-NEXT:    ld %s20, 64(, %s9) # 8-byte Folded Reload
135; PIC-NEXT:    ld %s19, 56(, %s9) # 8-byte Folded Reload
136; PIC-NEXT:    ld %s18, 48(, %s9) # 8-byte Folded Reload
137; PIC-NEXT:    or %s11, 0, %s9
138; PIC-NEXT:    ld %s16, 32(, %s11)
139; PIC-NEXT:    ld %s15, 24(, %s11)
140; PIC-NEXT:    ld %s10, 8(, %s11)
141; PIC-NEXT:    ld %s9, (, %s11)
142; PIC-NEXT:    b.l.t (, %s10)
143  %1 = call i8* @llvm.frameaddress(i32 0)
144  store i8* %1, i8** bitcast ([1 x %struct.__jmp_buf_tag]* @buf to i8**), align 8
145  %2 = call i8* @llvm.stacksave()
146  store i8* %2, i8** getelementptr inbounds (i8*, i8** bitcast ([1 x %struct.__jmp_buf_tag]* @buf to i8**), i64 2), align 8
147  %3 = call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([1 x %struct.__jmp_buf_tag]* @buf to i8*))
148  ret i32 %3
149}
150
151; Function Attrs: nounwind readnone
152declare i8* @llvm.frameaddress(i32)
153
154; Function Attrs: nounwind
155declare i8* @llvm.stacksave()
156
157; Function Attrs: nounwind
158declare i32 @llvm.eh.sjlj.setjmp(i8*)
159
160; Function Attrs: noinline nounwind optnone
161define void @t_longjmp() {
162; CHECK-LABEL: t_longjmp:
163; CHECK:       .LBB{{[0-9]+}}_2:
164; CHECK-NEXT:    lea %s0, buf@lo
165; CHECK-NEXT:    and %s0, %s0, (32)0
166; CHECK-NEXT:    lea.sl %s0, buf@hi(, %s0)
167; CHECK-NEXT:    ld %s9, (, %s0)
168; CHECK-NEXT:    ld %s1, 8(, %s0)
169; CHECK-NEXT:    or %s10, 0, %s0
170; CHECK-NEXT:    ld %s11, 16(, %s0)
171; CHECK-NEXT:    b.l.t (, %s1)
172;
173; PIC-LABEL: t_longjmp:
174; PIC:       # %bb.0:
175; PIC-NEXT:    st %s9, (, %s11)
176; PIC-NEXT:    st %s10, 8(, %s11)
177; PIC-NEXT:    st %s15, 24(, %s11)
178; PIC-NEXT:    st %s16, 32(, %s11)
179; PIC-NEXT:    or %s9, 0, %s11
180; PIC-NEXT:    lea %s11, -176(, %s11)
181; PIC-NEXT:    brge.l.t %s11, %s8, .LBB1_2
182; PIC-NEXT:  # %bb.1:
183; PIC-NEXT:    ld %s61, 24(, %s14)
184; PIC-NEXT:    or %s62, 0, %s0
185; PIC-NEXT:    lea %s63, 315
186; PIC-NEXT:    shm.l %s63, (%s61)
187; PIC-NEXT:    shm.l %s8, 8(%s61)
188; PIC-NEXT:    shm.l %s11, 16(%s61)
189; PIC-NEXT:    monc
190; PIC-NEXT:    or %s0, 0, %s62
191; PIC-NEXT:  .LBB1_2:
192; PIC-NEXT:    lea %s15, _GLOBAL_OFFSET_TABLE_@pc_lo(-24)
193; PIC-NEXT:    and %s15, %s15, (32)0
194; PIC-NEXT:    sic %s16
195; PIC-NEXT:    lea.sl %s15, _GLOBAL_OFFSET_TABLE_@pc_hi(%s16, %s15)
196; PIC-NEXT:    lea %s0, buf@got_lo
197; PIC-NEXT:    and %s0, %s0, (32)0
198; PIC-NEXT:    lea.sl %s0, buf@got_hi(, %s0)
199; PIC-NEXT:    ld %s0, (%s0, %s15)
200; PIC-NEXT:    ld %s9, (, %s0)
201; PIC-NEXT:    ld %s1, 8(, %s0)
202; PIC-NEXT:    or %s10, 0, %s0
203; PIC-NEXT:    ld %s11, 16(, %s0)
204; PIC-NEXT:    b.l.t (, %s1)
205  call void @llvm.eh.sjlj.longjmp(i8* bitcast ([1 x %struct.__jmp_buf_tag]* @buf to i8*))
206  unreachable
207                                                  ; No predecessors!
208  ret void
209}
210
211; Function Attrs: noreturn nounwind
212declare void @llvm.eh.sjlj.longjmp(i8*)
213
214