1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
; RUN: llc -mtriple=riscv32 < %s | FileCheck %s -check-prefix=RV32I
; RUN: llc -mtriple=riscv64 < %s | FileCheck %s -check-prefix=RV64I
; RUN: llc -mtriple=riscv32 -mattr=+save-restore < %s | FileCheck %s -check-prefix=RV32I-SR
; RUN: llc -mtriple=riscv64 -mattr=+save-restore < %s | FileCheck %s -check-prefix=RV64I-SR
; RUN: llc -mtriple=riscv32 -mattr=+f,+save-restore -target-abi=ilp32f < %s | FileCheck %s -check-prefix=RV32I-FP-SR
; RUN: llc -mtriple=riscv64 -mattr=+f,+d,+save-restore -target-abi=lp64d < %s | FileCheck %s -check-prefix=RV64I-FP-SR
; Check that the correct save/restore libcalls are generated.
@var0 = global [18 x i32] zeroinitializer
@var1 = global [24 x i32] zeroinitializer
@var2 = global [30 x i32] zeroinitializer
define void @callee_saved0() nounwind {
; RV32I-LABEL: callee_saved0:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: callee_saved0:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: callee_saved0:
; RV32I-SR: call t0, __riscv_save_5
; RV32I-SR: tail __riscv_restore_5
;
; RV64I-SR-LABEL: callee_saved0:
; RV64I-SR: call t0, __riscv_save_5
; RV64I-SR: tail __riscv_restore_5
;
; RV32I-FP-SR-LABEL: callee_saved0:
; RV32I-FP-SR: call t0, __riscv_save_5
; RV32I-FP-SR: tail __riscv_restore_5
;
; RV64I-FP-SR-LABEL: callee_saved0:
; RV64I-FP-SR: call t0, __riscv_save_5
; RV64I-FP-SR: tail __riscv_restore_5
%val = load [18 x i32], ptr @var0
store volatile [18 x i32] %val, ptr @var0
ret void
}
define void @callee_saved1() nounwind {
; RV32I-LABEL: callee_saved1:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: callee_saved1:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: callee_saved1:
; RV32I-SR: call t0, __riscv_save_11
; RV32I-SR: tail __riscv_restore_11
;
; RV64I-SR-LABEL: callee_saved1:
; RV64I-SR: call t0, __riscv_save_11
; RV64I-SR: tail __riscv_restore_11
;
; RV32I-FP-SR-LABEL: callee_saved1:
; RV32I-FP-SR: call t0, __riscv_save_11
; RV32I-FP-SR: tail __riscv_restore_11
;
; RV64I-FP-SR-LABEL: callee_saved1:
; RV64I-FP-SR: call t0, __riscv_save_11
; RV64I-FP-SR: tail __riscv_restore_11
%val = load [24 x i32], ptr @var1
store volatile [24 x i32] %val, ptr @var1
ret void
}
define void @callee_saved2() nounwind {
; RV32I-LABEL: callee_saved2:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: callee_saved2:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: callee_saved2:
; RV32I-SR: call t0, __riscv_save_12
; RV32I-SR: tail __riscv_restore_12
;
; RV64I-SR-LABEL: callee_saved2:
; RV64I-SR: call t0, __riscv_save_12
; RV64I-SR: tail __riscv_restore_12
;
; RV32I-FP-SR-LABEL: callee_saved2:
; RV32I-FP-SR: call t0, __riscv_save_12
; RV32I-FP-SR: tail __riscv_restore_12
;
; RV64I-FP-SR-LABEL: callee_saved2:
; RV64I-FP-SR: call t0, __riscv_save_12
; RV64I-FP-SR: tail __riscv_restore_12
%val = load [30 x i32], ptr @var2
store volatile [30 x i32] %val, ptr @var2
ret void
}
; Check that floating point callee saved registers are still manually saved and
; restored.
define void @callee_saved_fp() nounwind {
; RV32I-LABEL: callee_saved_fp:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: callee_saved_fp:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: callee_saved_fp:
; RV32I-SR: call t0, __riscv_save_7
; RV32I-SR: tail __riscv_restore_7
;
; RV64I-SR-LABEL: callee_saved_fp:
; RV64I-SR: call t0, __riscv_save_7
; RV64I-SR: tail __riscv_restore_7
;
; RV32I-FP-SR-LABEL: callee_saved_fp:
; RV32I-FP-SR: call t0, __riscv_save_7
; RV32I-FP-SR-NEXT: addi sp, sp, -16
; RV32I-FP-SR-NEXT: fsw fs0, 12(sp)
; RV32I-FP-SR: flw fs0, 12(sp)
; RV32I-FP-SR-NEXT: addi sp, sp, 16
; RV32I-FP-SR-NEXT: tail __riscv_restore_7
;
; RV64I-FP-SR-LABEL: callee_saved_fp:
; RV64I-FP-SR: call t0, __riscv_save_7
; RV64I-FP-SR-NEXT: addi sp, sp, -16
; RV64I-FP-SR-NEXT: fsd fs0, 8(sp)
; RV64I-FP-SR: fld fs0, 8(sp)
; RV64I-FP-SR-NEXT: addi sp, sp, 16
; RV64I-FP-SR-NEXT: tail __riscv_restore_7
call void asm sideeffect "", "~{f8},~{x9},~{x18},~{x19},~{x20},~{x21},~{x22}"()
ret void
}
; Check that preserving tail calls is preferred over save/restore
declare i32 @tail_callee(i32 %i)
define i32 @tail_call(i32 %i) nounwind {
; RV32I-LABEL: tail_call:
; RV32I-NOT: call t0, __riscv_save
; RV32I: tail tail_callee
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: tail_call:
; RV64I-NOT: call t0, __riscv_save
; RV64I: tail tail_callee
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: tail_call:
; RV32I-SR-NOT: call t0, __riscv_save
; RV32I-SR: tail tail_callee
; RV32I-SR-NOT: tail __riscv_restore
;
; RV64I-SR-LABEL: tail_call:
; RV64I-SR-NOT: call t0, __riscv_save
; RV64I-SR: tail tail_callee
; RV64I-SR-NOT: tail __riscv_restore
;
; RV32I-FP-SR-LABEL: tail_call:
; RV32I-FP-SR-NOT: call t0, __riscv_save
; RV32I-FP-SR: tail tail_callee
; RV32I-FP-SR-NOT: tail __riscv_restore
;
; RV64I-FP-SR-LABEL: tail_call:
; RV64I-FP-SR-NOT: call t0, __riscv_save
; RV64I-FP-SR: tail tail_callee
; RV64I-FP-SR-NOT: tail __riscv_restore
entry:
%val = load [18 x i32], ptr @var0
store volatile [18 x i32] %val, ptr @var0
%r = tail call i32 @tail_callee(i32 %i)
ret i32 %r
}
; Check that functions with varargs do not use save/restore code
declare void @llvm.va_start(ptr)
declare void @llvm.va_end(ptr)
define i32 @varargs(ptr %fmt, ...) nounwind {
; RV32I-LABEL: varargs:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: varargs:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: varargs:
; RV32I-SR-NOT: call t0, __riscv_save
; RV32I-SR-NOT: tail __riscv_restore
;
; RV64I-SR-LABEL: varargs:
; RV64I-SR-NOT: call t0, __riscv_save
; RV64I-SR-NOT: tail __riscv_restore
;
; RV32I-FP-SR-LABEL: varargs:
; RV32I-FP-SR-NOT: call t0, __riscv_save
; RV32I-FP-SR-NOT: tail __riscv_restore
;
; RV64I-FP-SR-LABEL: varargs:
; RV64I-FP-SR-NOT: call t0, __riscv_save
; RV64I-FP-SR-NOT: tail __riscv_restore
%va = alloca ptr, align 4
call void @llvm.va_start(ptr %va)
%argp.cur = load ptr, ptr %va, align 4
%argp.next = getelementptr inbounds i8, ptr %argp.cur, i32 4
store ptr %argp.next, ptr %va, align 4
%1 = load i32, ptr %argp.cur, align 4
call void @llvm.va_end(ptr %va)
ret i32 %1
}
define void @many_args(i32, i32, i32, i32, i32, i32, i32, i32, i32) nounwind {
; RV32I-LABEL: many_args:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: many_args:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: many_args:
; RV32I-SR: call t0, __riscv_save_5
; RV32I-SR: tail __riscv_restore_5
;
; RV64I-SR-LABEL: many_args:
; RV64I-SR: call t0, __riscv_save_5
; RV64I-SR: tail __riscv_restore_5
;
; RV32I-FP-SR-LABEL: many_args:
; RV32I-FP-SR: call t0, __riscv_save_5
; RV32I-FP-SR: tail __riscv_restore_5
;
; RV64I-FP-SR-LABEL: many_args:
; RV64I-FP-SR: call t0, __riscv_save_5
; RV64I-FP-SR: tail __riscv_restore_5
entry:
%val = load [18 x i32], ptr @var0
store volatile [18 x i32] %val, ptr @var0
ret void
}
; Check that dynamic allocation calculations remain correct
declare ptr @llvm.stacksave()
declare void @llvm.stackrestore(ptr)
declare void @notdead(ptr)
define void @alloca(i32 %n) nounwind {
; RV32I-LABEL: alloca:
; RV32I-NOT: call t0, __riscv_save
; RV32I: addi s0, sp, 16
; RV32I: addi sp, s0, -16
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: alloca:
; RV64I-NOT: call t0, __riscv_save
; RV64I: addi s0, sp, 32
; RV64I: addi sp, s0, -32
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: alloca:
; RV32I-SR: call t0, __riscv_save_2
; RV32I-SR: addi s0, sp, 16
; RV32I-SR: addi sp, s0, -16
; RV32I-SR: tail __riscv_restore_2
;
; RV64I-SR-LABEL: alloca:
; RV64I-SR: call t0, __riscv_save_2
; RV64I-SR: addi s0, sp, 32
; RV64I-SR: addi sp, s0, -32
; RV64I-SR: tail __riscv_restore_2
;
; RV32I-FP-SR-LABEL: alloca:
; RV32I-FP-SR: call t0, __riscv_save_2
; RV32I-FP-SR: addi s0, sp, 16
; RV32I-FP-SR: addi sp, s0, -16
; RV32I-FP-SR: tail __riscv_restore_2
;
; RV64I-FP-SR-LABEL: alloca:
; RV64I-FP-SR: call t0, __riscv_save_2
; RV64I-FP-SR: addi s0, sp, 32
; RV64I-FP-SR: addi sp, s0, -32
; RV64I-FP-SR: tail __riscv_restore_2
%sp = call ptr @llvm.stacksave()
%addr = alloca i8, i32 %n
call void @notdead(ptr %addr)
call void @llvm.stackrestore(ptr %sp)
ret void
}
; Check that functions with interrupt attribute do not use save/restore code
declare i32 @foo(...)
define void @interrupt() nounwind "interrupt"="supervisor" {
; RV32I-LABEL: interrupt:
; RV32I-NOT: call t0, __riscv_save
; RV32I-NOT: tail __riscv_restore
;
; RV64I-LABEL: interrupt:
; RV64I-NOT: call t0, __riscv_save
; RV64I-NOT: tail __riscv_restore
;
; RV32I-SR-LABEL: interrupt:
; RV32I-SR-NOT: call t0, __riscv_save
; RV32I-SR-NOT: tail __riscv_restore
;
; RV64I-SR-LABEL: interrupt:
; RV64I-SR-NOT: call t0, __riscv_save
; RV64I-SR-NOT: tail __riscv_restore
;
; RV32I-FP-SR-LABEL: interrupt:
; RV32I-FP-SR-NOT: call t0, __riscv_save
; RV32I-FP-SR-NOT: tail __riscv_restore
;
; RV64I-FP-SR-LABEL: interrupt:
; RV64I-FP-SR-NOT: call t0, __riscv_save
; RV64I-FP-SR-NOT: tail __riscv_restore
%call = call i32 @foo()
ret void
}
|