AArch64: treat [N x Ty] as a block during procedure calls.
[oota-llvm.git] / test / CodeGen / AArch64 / argument-blocks.ll
1 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DARWINPCS
2 ; RUN: llc -mtriple=aarch64-linux-gnu -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AAPCS
3
4 declare void @callee(...)
5
6 define float @test_hfa_regs(float, [2 x float] %in) {
7 ; CHECK-LABEL: test_hfa_regs:
8 ; CHECK: fadd s0, s1, s2
9
10   %lhs = extractvalue [2 x float] %in, 0
11   %rhs = extractvalue [2 x float] %in, 1
12   %sum = fadd float %lhs, %rhs
13   ret float %sum
14 }
15
16 ; Check that the array gets allocated to a contiguous block on the stack (rather
17 ; than the default of 2 8-byte slots).
18 define float @test_hfa_block([7 x float], [2 x float] %in) {
19 ; CHECK-LABEL: test_hfa_block:
20 ; CHECK: ldp [[LHS:s[0-9]+]], [[RHS:s[0-9]+]], [sp]
21 ; CHECK: fadd s0, [[LHS]], [[RHS]]
22
23   %lhs = extractvalue [2 x float] %in, 0
24   %rhs = extractvalue [2 x float] %in, 1
25   %sum = fadd float %lhs, %rhs
26   ret float %sum
27 }
28
29 ; Check that an HFA prevents backfilling of VFP registers (i.e. %rhs must go on
30 ; the stack rather than in s7).
31 define float @test_hfa_block_consume([7 x float], [2 x float] %in, float %rhs) {
32 ; CHECK-LABEL: test_hfa_block_consume:
33 ; CHECK-DAG: ldr [[LHS:s[0-9]+]], [sp]
34 ; CHECK-DAG: ldr [[RHS:s[0-9]+]], [sp, #8]
35 ; CHECK: fadd s0, [[LHS]], [[RHS]]
36
37   %lhs = extractvalue [2 x float] %in, 0
38   %sum = fadd float %lhs, %rhs
39   ret float %sum
40 }
41
42 define float @test_hfa_stackalign([8 x float], [1 x float], [2 x float] %in) {
43 ; CHECK-LABEL: test_hfa_stackalign:
44 ; CHECK-AAPCS: ldp [[LHS:s[0-9]+]], [[RHS:s[0-9]+]], [sp, #8]
45 ; CHECK-DARWINPCS: ldp [[LHS:s[0-9]+]], [[RHS:s[0-9]+]], [sp, #4]
46 ; CHECK: fadd s0, [[LHS]], [[RHS]]
47   %lhs = extractvalue [2 x float] %in, 0
48   %rhs = extractvalue [2 x float] %in, 1
49   %sum = fadd float %lhs, %rhs
50   ret float %sum
51 }
52
53 ; An HFA that ends up on the stack should not have any effect on where
54 ; integer-based arguments go.
55 define i64 @test_hfa_ignores_gprs([7 x float], [2 x float] %in, i64, i64 %res) {
56 ; CHECK-LABEL: test_hfa_ignores_gprs:
57 ; CHECK: mov x0, x1
58   ret i64 %res
59 }
60
61 ; [2 x float] should not be promoted to double by the Darwin varargs handling,
62 ; but should go in an 8-byte aligned slot.
63 define void @test_varargs_stackalign() {
64 ; CHECK-LABEL: test_varargs_stackalign:
65 ; CHECK-DARWINPCS: stp {{w[0-9]+}}, {{w[0-9]+}}, [sp, #16]
66
67   call void(...)* @callee([3 x float] undef, [2 x float] [float 1.0, float 2.0])
68   ret void
69 }
70
71 define i64 @test_smallstruct_block([7 x i64], [2 x i64] %in) {
72 ; CHECK-LABEL: test_smallstruct_block:
73 ; CHECK: ldp [[LHS:x[0-9]+]], [[RHS:x[0-9]+]], [sp]
74 ; CHECK: add x0, [[LHS]], [[RHS]]
75   %lhs = extractvalue [2 x i64] %in, 0
76   %rhs = extractvalue [2 x i64] %in, 1
77   %sum = add i64 %lhs, %rhs
78   ret i64 %sum
79 }
80
81 ; Check that a small struct prevents backfilling of registers (i.e. %rhs
82 ; must go on the stack rather than in x7).
83 define i64 @test_smallstruct_block_consume([7 x i64], [2 x i64] %in, i64 %rhs) {
84 ; CHECK-LABEL: test_smallstruct_block_consume:
85 ; CHECK-DAG: ldr [[LHS:x[0-9]+]], [sp]
86 ; CHECK-DAG: ldr [[RHS:x[0-9]+]], [sp, #16]
87 ; CHECK: add x0, [[LHS]], [[RHS]]
88
89   %lhs = extractvalue [2 x i64] %in, 0
90   %sum = add i64 %lhs, %rhs
91   ret i64 %sum
92 }