Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +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 %s -check-prefix=RV32I |
| 4 | |
| 5 | declare void @notdead(i8*) |
| 6 | |
| 7 | ; These tests must ensure the stack pointer is restored using the frame |
| 8 | ; pointer |
| 9 | |
| 10 | define void @simple_alloca(i32 %n) nounwind { |
| 11 | ; RV32I-LABEL: simple_alloca: |
| 12 | ; RV32I: # %bb.0: |
| 13 | ; RV32I-NEXT: addi sp, sp, -16 |
| 14 | ; RV32I-NEXT: sw ra, 12(sp) |
| 15 | ; RV32I-NEXT: sw s0, 8(sp) |
| 16 | ; RV32I-NEXT: addi s0, sp, 16 |
| 17 | ; RV32I-NEXT: addi a0, a0, 15 |
| 18 | ; RV32I-NEXT: andi a0, a0, -16 |
| 19 | ; RV32I-NEXT: sub a0, sp, a0 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 20 | ; RV32I-NEXT: mv sp, a0 |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 21 | ; RV32I-NEXT: lui a1, %hi(notdead) |
| 22 | ; RV32I-NEXT: addi a1, a1, %lo(notdead) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 23 | ; RV32I-NEXT: jalr a1 |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 24 | ; RV32I-NEXT: addi sp, s0, -16 |
| 25 | ; RV32I-NEXT: lw s0, 8(sp) |
| 26 | ; RV32I-NEXT: lw ra, 12(sp) |
| 27 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 28 | ; RV32I-NEXT: ret |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 29 | %1 = alloca i8, i32 %n |
| 30 | call void @notdead(i8* %1) |
| 31 | ret void |
| 32 | } |
| 33 | |
| 34 | declare i8* @llvm.stacksave() |
| 35 | declare void @llvm.stackrestore(i8*) |
| 36 | |
| 37 | define void @scoped_alloca(i32 %n) nounwind { |
| 38 | ; RV32I-LABEL: scoped_alloca: |
| 39 | ; RV32I: # %bb.0: |
| 40 | ; RV32I-NEXT: addi sp, sp, -16 |
| 41 | ; RV32I-NEXT: sw ra, 12(sp) |
| 42 | ; RV32I-NEXT: sw s0, 8(sp) |
| 43 | ; RV32I-NEXT: sw s1, 4(sp) |
| 44 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 45 | ; RV32I-NEXT: mv s1, sp |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 46 | ; RV32I-NEXT: addi a0, a0, 15 |
| 47 | ; RV32I-NEXT: andi a0, a0, -16 |
| 48 | ; RV32I-NEXT: sub a0, sp, a0 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 49 | ; RV32I-NEXT: mv sp, a0 |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 50 | ; RV32I-NEXT: lui a1, %hi(notdead) |
| 51 | ; RV32I-NEXT: addi a1, a1, %lo(notdead) |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 52 | ; RV32I-NEXT: jalr a1 |
| 53 | ; RV32I-NEXT: mv sp, s1 |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 54 | ; RV32I-NEXT: addi sp, s0, -16 |
| 55 | ; RV32I-NEXT: lw s1, 4(sp) |
| 56 | ; RV32I-NEXT: lw s0, 8(sp) |
| 57 | ; RV32I-NEXT: lw ra, 12(sp) |
| 58 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | 59136ff | 2017-12-15 09:47:01 +0000 | [diff] [blame] | 59 | ; RV32I-NEXT: ret |
Alex Bradbury | bfb00d4 | 2017-12-11 12:38:17 +0000 | [diff] [blame] | 60 | %sp = call i8* @llvm.stacksave() |
| 61 | %addr = alloca i8, i32 %n |
| 62 | call void @notdead(i8* %addr) |
| 63 | call void @llvm.stackrestore(i8* %sp) |
| 64 | ret void |
| 65 | } |