1; RUN: llc < %s -stack-symbol-ordering=0 -tailcallopt -code-model=medium -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  ; These loads are loading the values from their previous stores and are optimized away.
52  %0 = load i32, i32* %hp_var
53  %1 = load i32, i32* %p_var
54  %2 = load i32, i32* %arg0_var
55  %3 = load i32, i32* %arg1_var
56  %4 = load i32, i32* %arg2_var
57  ; CHECK:      jmp bar
58  tail call cc 11 void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) nounwind
59  ret void
60}
61
62define cc 11 void @baz() nounwind {
63  %tmp_clos = load i32, i32* @clos
64  %tmp_clos2 = inttoptr i32 %tmp_clos to i32*
65  %indirect_call = bitcast i32* %tmp_clos2 to void (i32, i32, i32)*
66  ; CHECK:      movl $42, %eax
67  ; CHECK-NEXT: jmpl *clos
68  tail call cc 11 void %indirect_call(i32 undef, i32 undef, i32 42) nounwind
69  ret void
70}
71
72; Sanity-check the tail call sequence. Number of arguments was chosen as to
73; expose a bug where the tail call sequence clobbered the stack.
74define cc 11 { i32, i32, i32 } @tailcaller(i32 %hp, i32 %p) nounwind {
75  ; CHECK:      movl	$15, %eax
76  ; CHECK-NEXT: movl	$31, %edx
77  ; CHECK-NEXT: movl	$47, %ecx
78  ; CHECK-NEXT: popl	%edi
79  ; CHECK-NEXT: jmp	tailcallee
80  %ret = tail call cc11 { i32, i32, i32 } @tailcallee(i32 %hp, i32 %p, i32 15,
81     i32 31, i32 47, i32 63) nounwind
82  ret { i32, i32, i32 } %ret
83}
84
85!hipe.literals = !{ !0, !1, !2 }
86!0 = !{ !"P_NSP_LIMIT", i32 84 }
87!1 = !{ !"X86_LEAF_WORDS", i32 24 }
88!2 = !{ !"AMD64_LEAF_WORDS", i32 24 }
89@clos = external dso_local constant i32
90declare cc 11 void @bar(i32, i32, i32, i32, i32)
91declare cc 11 { i32, i32, i32 } @tailcallee(i32, i32, i32, i32, i32, i32)
92
93!llvm.module.flags = !{!3}
94!3 = !{i32 2, !"override-stack-alignment", i32 4}
95