Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 1 | ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -tailcallopt | FileCheck %s |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 2 | |
| 3 | declare fastcc void @callee_stack0() |
| 4 | declare fastcc void @callee_stack8([8 x i32], i64) |
| 5 | declare fastcc void @callee_stack16([8 x i32], i64, i64) |
| 6 | |
| 7 | define fastcc void @caller_to0_from0() nounwind { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 8 | ; CHECK-LABEL: caller_to0_from0: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 9 | ; CHECK-NEXT: // BB |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 10 | |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 11 | tail call fastcc void @callee_stack0() |
| 12 | ret void |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 13 | |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 14 | ; CHECK-NEXT: b callee_stack0 |
| 15 | } |
| 16 | |
| 17 | define fastcc void @caller_to0_from8([8 x i32], i64) { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 18 | ; CHECK-LABEL: caller_to0_from8: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 19 | |
| 20 | tail call fastcc void @callee_stack0() |
| 21 | ret void |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 22 | |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 23 | ; CHECK: add sp, sp, #16 |
| 24 | ; CHECK-NEXT: b callee_stack0 |
| 25 | } |
| 26 | |
| 27 | define fastcc void @caller_to8_from0() { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 28 | ; CHECK-LABEL: caller_to8_from0: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 29 | ; CHECK: sub sp, sp, #32 |
| 30 | |
| 31 | ; Key point is that the "42" should go #16 below incoming stack |
| 32 | ; pointer (we didn't have arg space to reuse). |
| 33 | tail call fastcc void @callee_stack8([8 x i32] undef, i64 42) |
| 34 | ret void |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 35 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 36 | ; CHECK: str {{x[0-9]+}}, [sp, #16]! |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 37 | ; CHECK-NEXT: b callee_stack8 |
| 38 | } |
| 39 | |
| 40 | define fastcc void @caller_to8_from8([8 x i32], i64 %a) { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 41 | ; CHECK-LABEL: caller_to8_from8: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 42 | ; CHECK: sub sp, sp, #16 |
| 43 | |
| 44 | ; Key point is that the "%a" should go where at SP on entry. |
| 45 | tail call fastcc void @callee_stack8([8 x i32] undef, i64 42) |
| 46 | ret void |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 47 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 48 | ; CHECK: str {{x[0-9]+}}, [sp, #16]! |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 49 | ; CHECK-NEXT: b callee_stack8 |
| 50 | } |
| 51 | |
| 52 | define fastcc void @caller_to16_from8([8 x i32], i64 %a) { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 53 | ; CHECK-LABEL: caller_to16_from8: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 54 | ; CHECK: sub sp, sp, #16 |
| 55 | |
| 56 | ; Important point is that the call reuses the "dead" argument space |
| 57 | ; above %a on the stack. If it tries to go below incoming-SP then the |
| 58 | ; callee will not deallocate the space, even in fastcc. |
| 59 | tail call fastcc void @callee_stack16([8 x i32] undef, i64 42, i64 2) |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 60 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 61 | ; CHECK: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16] |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 62 | ; CHECK-NEXT: add sp, sp, #16 |
| 63 | ; CHECK-NEXT: b callee_stack16 |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 64 | ret void |
| 65 | } |
| 66 | |
| 67 | |
| 68 | define fastcc void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 69 | ; CHECK-LABEL: caller_to8_from24: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 70 | ; CHECK: sub sp, sp, #16 |
| 71 | |
| 72 | ; Key point is that the "%a" should go where at #16 above SP on entry. |
| 73 | tail call fastcc void @callee_stack8([8 x i32] undef, i64 42) |
| 74 | ret void |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 75 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 76 | ; CHECK: str {{x[0-9]+}}, [sp, #32]! |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 77 | ; CHECK-NEXT: b callee_stack8 |
| 78 | } |
| 79 | |
| 80 | |
| 81 | define fastcc void @caller_to16_from16([8 x i32], i64 %a, i64 %b) { |
Stephen Lin | d24ab20 | 2013-07-14 06:24:09 +0000 | [diff] [blame] | 82 | ; CHECK-LABEL: caller_to16_from16: |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 83 | ; CHECK: sub sp, sp, #16 |
| 84 | |
| 85 | ; Here we want to make sure that both loads happen before the stores: |
| 86 | ; otherwise either %a or %b will be wrongly clobbered. |
| 87 | tail call fastcc void @callee_stack16([8 x i32] undef, i64 %b, i64 %a) |
| 88 | ret void |
| 89 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 90 | ; CHECK: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16] |
| 91 | ; CHECK: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16] |
Jiangning Liu | 09cc564 | 2014-05-15 01:33:17 +0000 | [diff] [blame] | 92 | ; CHECK-NEXT: add sp, sp, #16 |
| 93 | ; CHECK-NEXT: b callee_stack16 |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 94 | } |