• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -stack-symbol-ordering=0 -tailcallopt -code-model=medium -stack-alignment=4 -mtriple=i686-linux-gnu -mcpu=pentium | FileCheck %s
2
3; Check the HiPE calling convention works (x86-32)
4
5define void @zap(i32 %a, i32 %b) nounwind {
6entry:
7  ; CHECK:      movl 40(%esp), %eax
8  ; CHECK-NEXT: movl 44(%esp), %edx
9  ; CHECK-NEXT: movl       $8, %ecx
10  ; CHECK-NEXT: calll addfour
11  %0 = call cc 11 {i32, i32, i32} @addfour(i32 undef, i32 undef, i32 %a, i32 %b, i32 8)
12  %res = extractvalue {i32, i32, i32} %0, 2
13
14  ; CHECK:      movl %eax, 16(%esp)
15  ; CHECK-NEXT: movl   $2, 12(%esp)
16  ; CHECK-NEXT: movl   $1,  8(%esp)
17  ; CHECK:      calll foo
18  tail call void @foo(i32 undef, i32 undef, i32 1, i32 2, i32 %res) nounwind
19  ret void
20}
21
22define cc 11 {i32, i32, i32} @addfour(i32 %hp, i32 %p, i32 %x, i32 %y, i32 %z) nounwind {
23entry:
24  ; CHECK:      addl %edx, %eax
25  ; CHECK-NEXT: addl %ecx, %eax
26  %0 = add i32 %x, %y
27  %1 = add i32 %0, %z
28
29  ; CHECK:      ret
30  %res = insertvalue {i32, i32, i32} undef, i32 %1, 2
31  ret {i32, i32, i32} %res
32}
33
34define cc 11 void @foo(i32 %hp, i32 %p, i32 %arg0, i32 %arg1, i32 %arg2) nounwind {
35entry:
36  ; CHECK:      movl  %esi, 16(%esp)
37  ; CHECK-NEXT: movl  %ebp, 12(%esp)
38  ; CHECK-NEXT: movl  %eax,  8(%esp)
39  ; CHECK-NEXT: movl  %edx,  4(%esp)
40  ; CHECK-NEXT: movl  %ecx,   (%esp)
41  %hp_var   = alloca i32
42  %p_var    = alloca i32
43  %arg0_var = alloca i32
44  %arg1_var = alloca i32
45  %arg2_var = alloca i32
46  store i32 %hp, i32* %hp_var
47  store i32 %p, i32* %p_var
48  store i32 %arg0, i32* %arg0_var
49  store i32 %arg1, i32* %arg1_var
50  store i32 %arg2, i32* %arg2_var
51
52  ; CHECK:      movl  16(%esp), %esi
53  ; CHECK-NEXT: movl  12(%esp), %ebp
54  ; CHECK-NEXT: movl   8(%esp), %eax
55  ; CHECK-NEXT: movl   4(%esp), %edx
56  %0 = load i32, i32* %hp_var
57  %1 = load i32, i32* %p_var
58  %2 = load i32, i32* %arg0_var
59  %3 = load i32, i32* %arg1_var
60  %4 = load i32, i32* %arg2_var
61  ; CHECK:      jmp bar
62  tail call cc 11 void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) nounwind
63  ret void
64}
65
66define cc 11 void @baz() nounwind {
67  %tmp_clos = load i32, i32* @clos
68  %tmp_clos2 = inttoptr i32 %tmp_clos to i32*
69  %indirect_call = bitcast i32* %tmp_clos2 to void (i32, i32, i32)*
70  ; CHECK:      movl $42, %eax
71  ; CHECK-NEXT: jmpl *clos
72  tail call cc 11 void %indirect_call(i32 undef, i32 undef, i32 42) nounwind
73  ret void
74}
75
76; Sanity-check the tail call sequence. Number of arguments was chosen as to
77; expose a bug where the tail call sequence clobbered the stack.
78define cc 11 { i32, i32, i32 } @tailcaller(i32 %hp, i32 %p) nounwind {
79  ; CHECK:      movl	$15, %eax
80  ; CHECK-NEXT: movl	$31, %edx
81  ; CHECK-NEXT: movl	$47, %ecx
82  ; CHECK-NEXT: popl	%edi
83  ; CHECK-NEXT: jmp	tailcallee
84  %ret = tail call cc11 { i32, i32, i32 } @tailcallee(i32 %hp, i32 %p, i32 15,
85     i32 31, i32 47, i32 63) nounwind
86  ret { i32, i32, i32 } %ret
87}
88
89!hipe.literals = !{ !0, !1, !2 }
90!0 = !{ !"P_NSP_LIMIT", i32 84 }
91!1 = !{ !"X86_LEAF_WORDS", i32 24 }
92!2 = !{ !"AMD64_LEAF_WORDS", i32 24 }
93@clos = external constant i32
94declare cc 11 void @bar(i32, i32, i32, i32, i32)
95declare cc 11 { i32, i32, i32 } @tailcallee(i32, i32, i32, i32, i32, i32)
96