• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test the backchain attribute.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5declare i8 *@llvm.stacksave()
6declare void @llvm.stackrestore(i8 *)
7declare void @g()
8
9; nothing should happen if no stack frame is needed.
10define void @f1() "backchain" {
11; CHECK-LABEL: f1:
12; CHECK-NOT: stg
13  ret void
14}
15
16; check that backchain is saved if we call someone
17define void @f2() "backchain" {
18; CHECK-LABEL: f2:
19; CHECK: stmg %r14, %r15, 112(%r15)
20; CHECK: lgr %r1, %r15
21; CHECK: aghi %r15, -160
22; CHECK: stg %r1, 0(%r15)
23  call void @g()
24  call void @g()
25  ret void
26}
27
28; check that backchain is saved if we have an alloca
29define void @f3() "backchain" {
30; CHECK-LABEL: f3:
31; CHECK-NOT: stmg
32; CHECK: lgr %r1, %r15
33; CHECK: aghi %r15, -168
34; CHECK: stg %r1, 0(%r15)
35  %ign = alloca i8, i32 4
36  ret void
37}
38
39; check that alloca copies the backchain
40define void @f4(i32 %len) "backchain" {
41; CHECK-LABEL: f4:
42; CHECK: stmg %r11, %r15, 88(%r15)
43; CHECK: lgr %r1, %r15
44; CHECK: aghi %r15, -160
45; CHECK: stg %r1, 0(%r15)
46; CHECK: lgr %r11, %r15
47; CHECK: lg [[BC:%r[0-9]+]], 0(%r15)
48; CHECK: lgr [[NEWSP:%r[0-9]+]], %r15
49; CHECK: lgr %r15, [[NEWSP]]
50; CHECK: stg [[BC]], 0([[NEWSP]])
51  %ign = alloca i8, i32 %len
52  ret void
53}
54
55; check that llvm.stackrestore restores the backchain
56define void @f5(i32 %count1, i32 %count2) "backchain" {
57; CHECK-LABEL: f5:
58; CHECK: stmg %r11, %r15, 88(%r15)
59; CHECK: lgr %r1, %r15
60; CHECK: aghi %r15, -160
61; CHECK: stg %r1, 0(%r15)
62; CHECK: lgr %r11, %r15
63; CHECK: lgr [[SAVESP:%r[0-9]+]], %r15
64; CHECK: lg [[BC:%r[0-9]+]], 0(%r15)
65; CHECK: lgr [[NEWSP:%r[0-9]+]], %r15
66; CHECK: lgr %r15, [[NEWSP]]
67; CHECK: stg [[BC]], 0([[NEWSP]])
68; CHECK: lg [[BC2:%r[0-9]+]], 0(%r15)
69; CHECK: lgr %r15, [[SAVESP]]
70; CHECK: stg [[BC2]], 0([[SAVESP]])
71; CHECK: lg [[BC3:%r[0-9]+]], 0(%r15)
72; CHECK: lgr [[NEWSP2:%r[0-9]+]], %r15
73; CHECK: lgr %r15, [[NEWSP2]]
74; CHECK: stg [[BC3]], 0([[NEWSP2]])
75; CHECK: lmg %r11, %r15, 248(%r11)
76; CHECK: br %r14
77  %src = call i8 *@llvm.stacksave()
78  %array1 = alloca i8, i32 %count1
79  store volatile i8 0, i8 *%array1
80  call void @llvm.stackrestore(i8 *%src)
81  %array2 = alloca i8, i32 %count2
82  store volatile i8 0, i8 *%array2
83  ret void
84}
85