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