• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -stack-symbol-ordering=0 -tailcallopt -relocation-model=static -code-model=medium -stack-alignment=8 -mtriple=x86_64-linux-gnu -mcpu=opteron | FileCheck %s
2
3; Check the HiPE calling convention works (x86-64)
4
5define void @zap(i64 %a, i64 %b) nounwind {
6entry:
7  ; CHECK:      movq %rsi, %rdx
8  ; CHECK-NEXT: movl $8, %ecx
9  ; CHECK-NEXT: movl $9, %r8d
10  ; CHECK-NEXT: movq %rdi, %rsi
11  ; CHECK-NEXT: callq addfour
12  %0 = call cc 11 {i64, i64, i64} @addfour(i64 undef, i64 undef, i64 %a, i64 %b, i64 8, i64 9)
13  %res = extractvalue {i64, i64, i64} %0, 2
14
15  ; CHECK:      movl $1, %edx
16  ; CHECK-NEXT: movl $2, %ecx
17  ; CHECK-NEXT: movl $3, %r8d
18  ; CHECK-NEXT: movq %rax, %r9
19  ; CHECK:      callq foo
20  tail call void @foo(i64 undef, i64 undef, i64 1, i64 2, i64 3, i64 %res) nounwind
21  ret void
22}
23
24define cc 11 {i64, i64, i64} @addfour(i64 %hp, i64 %p, i64 %x, i64 %y, i64 %z, i64 %w) nounwind {
25entry:
26  ; CHECK:      leaq (%rsi,%rdx), %rax
27  ; CHECK-NEXT: addq %rcx, %rax
28  ; CHECK-NEXT: addq %r8, %rax
29  %0 = add i64 %x, %y
30  %1 = add i64 %0, %z
31  %2 = add i64 %1, %w
32
33  ; CHECK:      ret
34  %res = insertvalue {i64, i64, i64} undef, i64 %2, 2
35  ret {i64, i64, i64} %res
36}
37
38define cc 11 void @foo(i64 %hp, i64 %p, i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3) nounwind {
39entry:
40  ; CHECK:      movq  %r15, 40(%rsp)
41  ; CHECK-NEXT: movq  %rbp, 32(%rsp)
42  ; CHECK-NEXT: movq  %rsi, 24(%rsp)
43  ; CHECK-NEXT: movq  %rdx, 16(%rsp)
44  ; CHECK-NEXT: movq  %rcx, 8(%rsp)
45  ; CHECK-NEXT: movq  %r8, (%rsp)
46  %hp_var   = alloca i64
47  %p_var    = alloca i64
48  %arg0_var = alloca i64
49  %arg1_var = alloca i64
50  %arg2_var = alloca i64
51  %arg3_var = alloca i64
52  store i64 %hp, i64* %hp_var
53  store i64 %p, i64* %p_var
54  store i64 %arg0, i64* %arg0_var
55  store i64 %arg1, i64* %arg1_var
56  store i64 %arg2, i64* %arg2_var
57  store i64 %arg3, i64* %arg3_var
58
59  ; Loads are reading values just writen from corresponding register and are therefore noops.
60  %0 = load i64, i64* %hp_var
61  %1 = load i64, i64* %p_var
62  %2 = load i64, i64* %arg0_var
63  %3 = load i64, i64* %arg1_var
64  %4 = load i64, i64* %arg2_var
65  %5 = load i64, i64* %arg3_var
66  ; CHECK:      jmp bar
67  tail call cc 11 void @bar(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) nounwind
68  ret void
69}
70
71define cc 11 void @baz() nounwind {
72  %tmp_clos = load i64, i64* @clos
73  %tmp_clos2 = inttoptr i64 %tmp_clos to i64*
74  %indirect_call = bitcast i64* %tmp_clos2 to void (i64, i64, i64)*
75  ; CHECK:      movl $42, %esi
76  ; CHECK-NEXT: jmpq *(%rax)
77  tail call cc 11 void %indirect_call(i64 undef, i64 undef, i64 42) nounwind
78  ret void
79}
80
81; Sanity-check the tail call sequence. Number of arguments was chosen as to
82; expose a bug where the tail call sequence clobbered the stack.
83define cc 11 { i64, i64, i64 } @tailcaller(i64 %hp, i64 %p) #0 {
84  ; CHECK:      movl	$15, %esi
85  ; CHECK-NEXT: movl	$31, %edx
86  ; CHECK-NEXT: movl	$47, %ecx
87  ; CHECK-NEXT: movl	$63, %r8d
88  ; CHECK-NEXT: popq	%rax
89  ; CHECK-NEXT: .cfi_def_cfa_offset 16
90  ; CHECK-NEXT: jmp	tailcallee
91  %ret = tail call cc11 { i64, i64, i64 } @tailcallee(i64 %hp, i64 %p, i64 15,
92     i64 31, i64 47, i64 63, i64 79) #1
93  ret { i64, i64, i64 } %ret
94}
95
96!hipe.literals = !{ !0, !1, !2 }
97!0 = !{ !"P_NSP_LIMIT", i32 160 }
98!1 = !{ !"X86_LEAF_WORDS", i32 24 }
99!2 = !{ !"AMD64_LEAF_WORDS", i32 24 }
100@clos = external constant i64
101declare cc 11 void @bar(i64, i64, i64, i64, i64, i64)
102declare cc 11 { i64, i64, i64 } @tailcallee(i64, i64, i64, i64, i64, i64, i64)
103