Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \ |
| 3 | ; RUN: | FileCheck -check-prefix=RV32I %s |
| 4 | |
| 5 | declare i32 @external_function(i32) |
| 6 | |
| 7 | define i32 @test_call_external(i32 %a) nounwind { |
| 8 | ; RV32I-LABEL: test_call_external: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 9 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 10 | ; RV32I-NEXT: addi sp, sp, -16 |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 11 | ; RV32I-NEXT: sw ra, 12(sp) |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame^] | 12 | ; RV32I-NEXT: call external_function |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 13 | ; RV32I-NEXT: lw ra, 12(sp) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 14 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 15 | ; RV32I-NEXT: ret |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 16 | %1 = call i32 @external_function(i32 %a) |
| 17 | ret i32 %1 |
| 18 | } |
| 19 | |
| 20 | define i32 @defined_function(i32 %a) nounwind { |
| 21 | ; RV32I-LABEL: defined_function: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 22 | ; RV32I: # %bb.0: |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 23 | ; RV32I-NEXT: addi a0, a0, 1 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 24 | ; RV32I-NEXT: ret |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 25 | %1 = add i32 %a, 1 |
| 26 | ret i32 %1 |
| 27 | } |
| 28 | |
| 29 | define i32 @test_call_defined(i32 %a) nounwind { |
| 30 | ; RV32I-LABEL: test_call_defined: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 31 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 32 | ; RV32I-NEXT: addi sp, sp, -16 |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 33 | ; RV32I-NEXT: sw ra, 12(sp) |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame^] | 34 | ; RV32I-NEXT: call defined_function |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 35 | ; RV32I-NEXT: lw ra, 12(sp) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 36 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 37 | ; RV32I-NEXT: ret |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 38 | %1 = call i32 @defined_function(i32 %a) |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 39 | ret i32 %1 |
| 40 | } |
| 41 | |
| 42 | define i32 @test_call_indirect(i32 (i32)* %a, i32 %b) nounwind { |
| 43 | ; RV32I-LABEL: test_call_indirect: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 44 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 45 | ; RV32I-NEXT: addi sp, sp, -16 |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 46 | ; RV32I-NEXT: sw ra, 12(sp) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 47 | ; RV32I-NEXT: mv a2, a0 |
| 48 | ; RV32I-NEXT: mv a0, a1 |
| 49 | ; RV32I-NEXT: jalr a2 |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 50 | ; RV32I-NEXT: lw ra, 12(sp) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 51 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 52 | ; RV32I-NEXT: ret |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 53 | %1 = call i32 %a(i32 %b) |
| 54 | ret i32 %1 |
| 55 | } |
| 56 | |
| 57 | ; Ensure that calls to fastcc functions aren't rejected. Such calls may be |
| 58 | ; introduced when compiling with optimisation. |
| 59 | |
| 60 | define fastcc i32 @fastcc_function(i32 %a, i32 %b) nounwind { |
| 61 | ; RV32I-LABEL: fastcc_function: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 62 | ; RV32I: # %bb.0: |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 63 | ; RV32I-NEXT: add a0, a0, a1 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 64 | ; RV32I-NEXT: ret |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 65 | %1 = add i32 %a, %b |
| 66 | ret i32 %1 |
| 67 | } |
| 68 | |
| 69 | define i32 @test_call_fastcc(i32 %a, i32 %b) nounwind { |
| 70 | ; RV32I-LABEL: test_call_fastcc: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 71 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 72 | ; RV32I-NEXT: addi sp, sp, -16 |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 73 | ; RV32I-NEXT: sw ra, 12(sp) |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 74 | ; RV32I-NEXT: sw s1, 8(sp) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 75 | ; RV32I-NEXT: mv s1, a0 |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame^] | 76 | ; RV32I-NEXT: call fastcc_function |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 77 | ; RV32I-NEXT: mv a0, s1 |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 78 | ; RV32I-NEXT: lw s1, 8(sp) |
Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 79 | ; RV32I-NEXT: lw ra, 12(sp) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 80 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 81 | ; RV32I-NEXT: ret |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 82 | %1 = call fastcc i32 @fastcc_function(i32 %a, i32 %b) |
| 83 | ret i32 %a |
| 84 | } |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 85 | |
| 86 | declare i32 @external_many_args(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) nounwind |
| 87 | |
| 88 | define i32 @test_call_external_many_args(i32 %a) nounwind { |
| 89 | ; RV32I-LABEL: test_call_external_many_args: |
| 90 | ; RV32I: # %bb.0: |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 91 | ; RV32I-NEXT: addi sp, sp, -16 |
| 92 | ; RV32I-NEXT: sw ra, 12(sp) |
| 93 | ; RV32I-NEXT: sw s1, 8(sp) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 94 | ; RV32I-NEXT: mv s1, a0 |
Alex Bradbury | 1b2a0f4 | 2018-02-28 08:20:47 +0000 | [diff] [blame] | 95 | ; RV32I-NEXT: sw a0, 4(sp) |
| 96 | ; RV32I-NEXT: sw a0, 0(sp) |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame^] | 97 | ; RV32I-NEXT: mv a1, a0 |
| 98 | ; RV32I-NEXT: mv a2, a0 |
| 99 | ; RV32I-NEXT: mv a3, a0 |
| 100 | ; RV32I-NEXT: mv a4, a0 |
| 101 | ; RV32I-NEXT: mv a5, a0 |
| 102 | ; RV32I-NEXT: mv a6, a0 |
| 103 | ; RV32I-NEXT: mv a7, a0 |
| 104 | ; RV32I-NEXT: call external_many_args |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 105 | ; RV32I-NEXT: mv a0, s1 |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 106 | ; RV32I-NEXT: lw s1, 8(sp) |
| 107 | ; RV32I-NEXT: lw ra, 12(sp) |
| 108 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 109 | ; RV32I-NEXT: ret |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 110 | %1 = call i32 @external_many_args(i32 %a, i32 %a, i32 %a, i32 %a, i32 %a, |
| 111 | i32 %a, i32 %a, i32 %a, i32 %a, i32 %a) |
| 112 | ret i32 %a |
| 113 | } |
| 114 | |
| 115 | define i32 @defined_many_args(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 %j) nounwind { |
| 116 | ; RV32I-LABEL: defined_many_args: |
| 117 | ; RV32I: # %bb.0: |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 118 | ; RV32I-NEXT: lw a0, 4(sp) |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 119 | ; RV32I-NEXT: addi a0, a0, 1 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 120 | ; RV32I-NEXT: ret |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 121 | %added = add i32 %j, 1 |
| 122 | ret i32 %added |
| 123 | } |
| 124 | |
| 125 | define i32 @test_call_defined_many_args(i32 %a) nounwind { |
| 126 | ; RV32I-LABEL: test_call_defined_many_args: |
| 127 | ; RV32I: # %bb.0: |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 128 | ; RV32I-NEXT: addi sp, sp, -16 |
| 129 | ; RV32I-NEXT: sw ra, 12(sp) |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 130 | ; RV32I-NEXT: sw a0, 4(sp) |
| 131 | ; RV32I-NEXT: sw a0, 0(sp) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 132 | ; RV32I-NEXT: mv a1, a0 |
| 133 | ; RV32I-NEXT: mv a2, a0 |
| 134 | ; RV32I-NEXT: mv a3, a0 |
| 135 | ; RV32I-NEXT: mv a4, a0 |
| 136 | ; RV32I-NEXT: mv a5, a0 |
| 137 | ; RV32I-NEXT: mv a6, a0 |
| 138 | ; RV32I-NEXT: mv a7, a0 |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame^] | 139 | ; RV32I-NEXT: call defined_many_args |
Alex Bradbury | 7d6aa1f | 2018-01-18 11:34:02 +0000 | [diff] [blame] | 140 | ; RV32I-NEXT: lw ra, 12(sp) |
| 141 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 142 | ; RV32I-NEXT: ret |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 143 | %1 = call i32 @defined_many_args(i32 %a, i32 %a, i32 %a, i32 %a, i32 %a, |
| 144 | i32 %a, i32 %a, i32 %a, i32 %a, i32 %a) |
| 145 | ret i32 %1 |
| 146 | } |