|
| 1 | +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py |
| 2 | +# RUN: llc -mtriple=riscv64 -run-pass=riscv-live-variables -verify-machineinstrs -o - %s | FileCheck %s |
| 3 | +# |
| 4 | +# Test live variable analysis with function calls and register clobbering |
| 5 | +# Function calls clobber caller-saved registers, which affects liveness |
| 6 | + |
| 7 | +--- | |
| 8 | + declare i64 @external_func(i64, i64) |
| 9 | + declare void @void_func(i64) |
| 10 | + |
| 11 | + define i64 @test_call_simple(i64 %a, i64 %b) { |
| 12 | + entry: |
| 13 | + %result = call i64 @external_func(i64 %a, i64 %b) |
| 14 | + ret i64 %result |
| 15 | + } |
| 16 | + |
| 17 | + define i64 @test_call_with_live_values(i64 %a, i64 %b, i64 %c) { |
| 18 | + entry: |
| 19 | + %sum1 = add i64 %a, %b |
| 20 | + %result = call i64 @external_func(i64 %sum1, i64 %c) |
| 21 | + ; %b is live across the call |
| 22 | + %final = add i64 %result, %b |
| 23 | + ret i64 %final |
| 24 | + } |
| 25 | + |
| 26 | + define i64 @test_multiple_calls(i64 %a, i64 %b) { |
| 27 | + entry: |
| 28 | + %r1 = call i64 @external_func(i64 %a, i64 %b) |
| 29 | + call void @void_func(i64 %r1) |
| 30 | + %r2 = call i64 @external_func(i64 %r1, i64 %b) |
| 31 | + ret i64 %r2 |
| 32 | + } |
| 33 | + |
| 34 | + define i64 @test_call_with_spill(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e, i64 %f, i64 %g, i64 %h) { |
| 35 | + entry: |
| 36 | + %sum = add i64 %a, %b |
| 37 | + %result = call i64 @external_func(i64 %sum, i64 %c) |
| 38 | + ; Many values live across call - may require spilling |
| 39 | + %t1 = add i64 %result, %d |
| 40 | + %t2 = add i64 %t1, %e |
| 41 | + %t3 = add i64 %t2, %f |
| 42 | + %t4 = add i64 %t3, %g |
| 43 | + %t5 = add i64 %t4, %h |
| 44 | + ret i64 %t5 |
| 45 | + } |
| 46 | +... |
| 47 | +--- |
| 48 | +name: test_call_simple |
| 49 | +alignment: 4 |
| 50 | +tracksRegLiveness: true |
| 51 | +registers: |
| 52 | + - { id: 0, class: gpr } |
| 53 | + - { id: 1, class: gpr } |
| 54 | + - { id: 2, class: gpr } |
| 55 | +liveins: |
| 56 | + - { reg: '$x10', virtual-reg: '%0' } |
| 57 | + - { reg: '$x11', virtual-reg: '%1' } |
| 58 | +body: | |
| 59 | + bb.0.entry: |
| 60 | + liveins: $x10, $x11 |
| 61 | + ; CHECK-LABEL: name: test_call_simple |
| 62 | + ; CHECK: bb.0.entry: |
| 63 | + ; CHECK-NEXT: liveins: $x10, $x11 |
| 64 | +
|
| 65 | + %0:gpr = COPY $x10 |
| 66 | + %1:gpr = COPY $x11 |
| 67 | + $x10 = COPY %0 |
| 68 | + $x11 = COPY %1 |
| 69 | + ; Call clobbers many registers per calling convention |
| 70 | + PseudoCALL target-flags(riscv-call) @external_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10, implicit $x11, implicit-def $x10 |
| 71 | + %2:gpr = COPY $x10 |
| 72 | + $x10 = COPY %2 |
| 73 | + PseudoRET implicit $x10 |
| 74 | +... |
| 75 | +--- |
| 76 | +name: test_call_with_live_values |
| 77 | +alignment: 4 |
| 78 | +tracksRegLiveness: true |
| 79 | +registers: |
| 80 | + - { id: 0, class: gpr } |
| 81 | + - { id: 1, class: gpr } |
| 82 | + - { id: 2, class: gpr } |
| 83 | + - { id: 3, class: gpr } |
| 84 | + - { id: 4, class: gpr } |
| 85 | + - { id: 5, class: gpr } |
| 86 | +liveins: |
| 87 | + - { reg: '$x10', virtual-reg: '%0' } |
| 88 | + - { reg: '$x11', virtual-reg: '%1' } |
| 89 | + - { reg: '$x12', virtual-reg: '%2' } |
| 90 | +body: | |
| 91 | + bb.0.entry: |
| 92 | + liveins: $x10, $x11, $x12 |
| 93 | + ; CHECK-LABEL: name: test_call_with_live_values |
| 94 | + ; CHECK: bb.0.entry: |
| 95 | + ; CHECK-NEXT: liveins: $x10, $x11, $x12 |
| 96 | +
|
| 97 | + %0:gpr = COPY $x10 |
| 98 | + %1:gpr = COPY $x11 |
| 99 | + %2:gpr = COPY $x12 |
| 100 | + %3:gpr = ADD %0, %1 |
| 101 | + ; %1 must remain live across this call |
| 102 | + $x10 = COPY %3 |
| 103 | + $x11 = COPY %2 |
| 104 | + PseudoCALL target-flags(riscv-call) @external_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10, implicit $x11, implicit-def $x10 |
| 105 | + %4:gpr = COPY $x10 |
| 106 | + ; %1 is used again here after the call |
| 107 | + %5:gpr = ADD %4, %1 |
| 108 | + $x10 = COPY %5 |
| 109 | + PseudoRET implicit $x10 |
| 110 | +... |
| 111 | +--- |
| 112 | +name: test_multiple_calls |
| 113 | +alignment: 4 |
| 114 | +tracksRegLiveness: true |
| 115 | +registers: |
| 116 | + - { id: 0, class: gpr } |
| 117 | + - { id: 1, class: gpr } |
| 118 | + - { id: 2, class: gpr } |
| 119 | + - { id: 3, class: gpr } |
| 120 | +liveins: |
| 121 | + - { reg: '$x10', virtual-reg: '%0' } |
| 122 | + - { reg: '$x11', virtual-reg: '%1' } |
| 123 | +body: | |
| 124 | + bb.0.entry: |
| 125 | + liveins: $x10, $x11 |
| 126 | + ; CHECK-LABEL: name: test_multiple_calls |
| 127 | + ; CHECK: bb.0.entry: |
| 128 | + ; CHECK-NEXT: liveins: $x10, $x11 |
| 129 | +
|
| 130 | + %0:gpr = COPY $x10 |
| 131 | + %1:gpr = COPY $x11 |
| 132 | +
|
| 133 | + ; First call |
| 134 | + $x10 = COPY %0 |
| 135 | + $x11 = COPY %1 |
| 136 | + PseudoCALL target-flags(riscv-call) @external_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10, implicit $x11, implicit-def $x10 |
| 137 | + %2:gpr = COPY $x10 |
| 138 | +
|
| 139 | + ; Second call (void) |
| 140 | + $x10 = COPY %2 |
| 141 | + PseudoCALL target-flags(riscv-call) @void_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10 |
| 142 | +
|
| 143 | + ; Third call - %2 and %1 are both live here |
| 144 | + $x10 = COPY %2 |
| 145 | + $x11 = COPY %1 |
| 146 | + PseudoCALL target-flags(riscv-call) @external_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10, implicit $x11, implicit-def $x10 |
| 147 | + %3:gpr = COPY $x10 |
| 148 | +
|
| 149 | + $x10 = COPY %3 |
| 150 | + PseudoRET implicit $x10 |
| 151 | +... |
| 152 | +--- |
| 153 | +name: test_call_with_spill |
| 154 | +alignment: 4 |
| 155 | +tracksRegLiveness: true |
| 156 | +registers: |
| 157 | + - { id: 0, class: gpr } |
| 158 | + - { id: 1, class: gpr } |
| 159 | + - { id: 2, class: gpr } |
| 160 | + - { id: 3, class: gpr } |
| 161 | + - { id: 4, class: gpr } |
| 162 | + - { id: 5, class: gpr } |
| 163 | + - { id: 6, class: gpr } |
| 164 | + - { id: 7, class: gpr } |
| 165 | + - { id: 8, class: gpr } |
| 166 | + - { id: 9, class: gpr } |
| 167 | + - { id: 10, class: gpr } |
| 168 | + - { id: 11, class: gpr } |
| 169 | + - { id: 12, class: gpr } |
| 170 | + - { id: 13, class: gpr } |
| 171 | +liveins: |
| 172 | + - { reg: '$x10', virtual-reg: '%0' } |
| 173 | + - { reg: '$x11', virtual-reg: '%1' } |
| 174 | + - { reg: '$x12', virtual-reg: '%2' } |
| 175 | + - { reg: '$x13', virtual-reg: '%3' } |
| 176 | + - { reg: '$x14', virtual-reg: '%4' } |
| 177 | + - { reg: '$x15', virtual-reg: '%5' } |
| 178 | + - { reg: '$x16', virtual-reg: '%6' } |
| 179 | + - { reg: '$x17', virtual-reg: '%7' } |
| 180 | +body: | |
| 181 | + bb.0.entry: |
| 182 | + liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17 |
| 183 | + ; CHECK-LABEL: name: test_call_with_spill |
| 184 | + ; CHECK: bb.0.entry: |
| 185 | + ; CHECK-NEXT: liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17 |
| 186 | + ; Many registers live across call - tests register pressure |
| 187 | +
|
| 188 | + %0:gpr = COPY $x10 |
| 189 | + %1:gpr = COPY $x11 |
| 190 | + %2:gpr = COPY $x12 |
| 191 | + %3:gpr = COPY $x13 |
| 192 | + %4:gpr = COPY $x14 |
| 193 | + %5:gpr = COPY $x15 |
| 194 | + %6:gpr = COPY $x16 |
| 195 | + %7:gpr = COPY $x17 |
| 196 | +
|
| 197 | + %8:gpr = ADD %0, %1 |
| 198 | +
|
| 199 | + ; Call with many live values - %3, %4, %5, %6, %7 all live across |
| 200 | + $x10 = COPY %8 |
| 201 | + $x11 = COPY %2 |
| 202 | + PseudoCALL target-flags(riscv-call) @external_func, csr_ilp32_lp64, implicit-def $x1, implicit $x10, implicit $x11, implicit-def $x10 |
| 203 | + %9:gpr = COPY $x10 |
| 204 | +
|
| 205 | + ; All these values should have been kept live |
| 206 | + %10:gpr = ADD %9, %3 |
| 207 | + %11:gpr = ADD %10, %4 |
| 208 | + %12:gpr = ADD %11, %5 |
| 209 | + %13:gpr = ADD %12, %6 |
| 210 | + %14:gpr = ADD %13, %7 |
| 211 | +
|
| 212 | + $x10 = COPY %14 |
| 213 | + PseudoRET implicit $x10 |
| 214 | +... |
0 commit comments