|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2 |
| 2 | +; RUN: llc -global-isel=1 -mtriple=riscv32 -o - %s | FileCheck %s --check-prefix=RV32 |
| 3 | +; RUN: llc -global-isel=1 -mtriple=riscv64 -o - %s | FileCheck %s --check-prefix=RV64 |
| 4 | + |
| 5 | +declare void @use_addr(ptr) |
| 6 | + |
| 7 | +define void @test_scoped_alloca(i64 %n) { |
| 8 | +; RV32-LABEL: test_scoped_alloca: |
| 9 | +; RV32: # %bb.0: |
| 10 | +; RV32-NEXT: addi sp, sp, -16 |
| 11 | +; RV32-NEXT: .cfi_def_cfa_offset 16 |
| 12 | +; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill |
| 13 | +; RV32-NEXT: sw s0, 8(sp) # 4-byte Folded Spill |
| 14 | +; RV32-NEXT: sw s1, 4(sp) # 4-byte Folded Spill |
| 15 | +; RV32-NEXT: .cfi_offset ra, -4 |
| 16 | +; RV32-NEXT: .cfi_offset s0, -8 |
| 17 | +; RV32-NEXT: .cfi_offset s1, -12 |
| 18 | +; RV32-NEXT: addi s0, sp, 16 |
| 19 | +; RV32-NEXT: .cfi_def_cfa s0, 0 |
| 20 | +; RV32-NEXT: addi a0, a0, 15 |
| 21 | +; RV32-NEXT: andi a0, a0, -16 |
| 22 | +; RV32-NEXT: sub a0, sp, a0 |
| 23 | +; RV32-NEXT: mv s1, sp |
| 24 | +; RV32-NEXT: mv sp, a0 |
| 25 | +; RV32-NEXT: call use_addr |
| 26 | +; RV32-NEXT: mv sp, s1 |
| 27 | +; RV32-NEXT: addi sp, s0, -16 |
| 28 | +; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload |
| 29 | +; RV32-NEXT: lw s0, 8(sp) # 4-byte Folded Reload |
| 30 | +; RV32-NEXT: lw s1, 4(sp) # 4-byte Folded Reload |
| 31 | +; RV32-NEXT: addi sp, sp, 16 |
| 32 | +; RV32-NEXT: ret |
| 33 | +; |
| 34 | +; RV64-LABEL: test_scoped_alloca: |
| 35 | +; RV64: # %bb.0: |
| 36 | +; RV64-NEXT: addi sp, sp, -32 |
| 37 | +; RV64-NEXT: .cfi_def_cfa_offset 32 |
| 38 | +; RV64-NEXT: sd ra, 24(sp) # 8-byte Folded Spill |
| 39 | +; RV64-NEXT: sd s0, 16(sp) # 8-byte Folded Spill |
| 40 | +; RV64-NEXT: sd s1, 8(sp) # 8-byte Folded Spill |
| 41 | +; RV64-NEXT: .cfi_offset ra, -8 |
| 42 | +; RV64-NEXT: .cfi_offset s0, -16 |
| 43 | +; RV64-NEXT: .cfi_offset s1, -24 |
| 44 | +; RV64-NEXT: addi s0, sp, 32 |
| 45 | +; RV64-NEXT: .cfi_def_cfa s0, 0 |
| 46 | +; RV64-NEXT: addi a0, a0, 15 |
| 47 | +; RV64-NEXT: andi a0, a0, -16 |
| 48 | +; RV64-NEXT: sub a0, sp, a0 |
| 49 | +; RV64-NEXT: mv s1, sp |
| 50 | +; RV64-NEXT: mv sp, a0 |
| 51 | +; RV64-NEXT: call use_addr |
| 52 | +; RV64-NEXT: mv sp, s1 |
| 53 | +; RV64-NEXT: addi sp, s0, -32 |
| 54 | +; RV64-NEXT: ld ra, 24(sp) # 8-byte Folded Reload |
| 55 | +; RV64-NEXT: ld s0, 16(sp) # 8-byte Folded Reload |
| 56 | +; RV64-NEXT: ld s1, 8(sp) # 8-byte Folded Reload |
| 57 | +; RV64-NEXT: addi sp, sp, 32 |
| 58 | +; RV64-NEXT: ret |
| 59 | + %sp = call ptr @llvm.stacksave.p0() |
| 60 | + %addr = alloca i8, i64 %n |
| 61 | + call void @use_addr(ptr %addr) |
| 62 | + call void @llvm.stackrestore.p0(ptr %sp) |
| 63 | + ret void |
| 64 | +} |
0 commit comments