File: alloca.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (84 lines) | stat: -rw-r--r-- 2,762 bytes parent folder | download | duplicates (17)
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
; RUN: llc < %s -march=avr -mattr=avr6 | FileCheck %s

declare i16 @allocate(i16*, i16*)

; Test taking an address of an alloca with a small offset (adiw)
define i16 @alloca_addressof_small() {
entry:
; CHECK-LABEL: alloca_addressof_small:
; Test that Y is saved
; CHECK: push r28
; CHECK: push r29
; CHECK: movw r24, r28
; CHECK: adiw r24, 17
; CHECK: movw {{.*}}, r28
; CHECK: adiw {{.*}}, 39
; CHECK: movw r22, {{.*}}
; CHECK: pop r29
; CHECK: pop r28
  %p = alloca [18 x i16]
  %k = alloca [14 x i16]
  %arrayidx = getelementptr inbounds [14 x i16], [14 x i16]* %k, i16 0, i16 8
  %arrayidx1 = getelementptr inbounds [18 x i16], [18 x i16]* %p, i16 0, i16 5
  %call = call i16 @allocate(i16* %arrayidx, i16* %arrayidx1)
  ret i16 %call
}

; Test taking an address of an alloca with a big offset (subi/sbci pair)
define i16 @alloca_addressof_big() {
entry:
; CHECK-LABEL: alloca_addressof_big:
; CHECK: movw r24, r28
; CHECK: adiw r24, 17
; CHECK: movw r22, r28
; CHECK: subi r22, 145
; CHECK: sbci r23, 255
  %p = alloca [55 x i16]
  %k = alloca [14 x i16]
  %arrayidx = getelementptr inbounds [14 x i16], [14 x i16]* %k, i16 0, i16 8
  %arrayidx1 = getelementptr inbounds [55 x i16], [55 x i16]* %p, i16 0, i16 41
  %call = call i16 @allocate(i16* %arrayidx, i16* %arrayidx1)
  ret i16 %call
}

; Test writing to an allocated variable with a small and a big offset
define i16 @alloca_write(i16 %x) {
entry:
; CHECK-LABEL: alloca_write:
; Small offset here
; CHECK: std Y+23, {{.*}}
; CHECK: std Y+24, {{.*}}
; Big offset here
; CHECK: adiw r28, 57
; CHECK: std Y+62, {{.*}}
; CHECK: std Y+63, {{.*}}
; CHECK: sbiw r28, 57
  %p = alloca [15 x i16]
  %k = alloca [14 x i16]
  %arrayidx = getelementptr inbounds [15 x i16], [15 x i16]* %p, i16 0, i16 45
  store i16 22, i16* %arrayidx
  %arrayidx1 = getelementptr inbounds [14 x i16], [14 x i16]* %k, i16 0, i16 11
  store i16 42, i16* %arrayidx1
  %arrayidx2 = getelementptr inbounds [14 x i16], [14 x i16]* %k, i16 0, i16 0
  %arrayidx3 = getelementptr inbounds [15 x i16], [15 x i16]* %p, i16 0, i16 0
  %call = call i16 @allocate(i16* %arrayidx2, i16* %arrayidx3)
  ret i16 %call
}

; Test writing to an allocated variable with a huge offset that cant be
; materialized with adiw/sbiw but with a subi/sbci pair.
define void @alloca_write_huge() {
; CHECK-LABEL: alloca_write_huge:
; CHECK: subi r28, 41
; CHECK: sbci r29, 255
; CHECK: std Y+62, {{.*}}
; CHECK: std Y+63, {{.*}}
; CHECK: subi r28, 215
; CHECK: sbci r29, 0
  %k = alloca [140 x i16]
  %arrayidx = getelementptr inbounds [140 x i16], [140 x i16]* %k, i16 0, i16 138
  store i16 22, i16* %arrayidx
  %arraydecay = getelementptr inbounds [140 x i16], [140 x i16]* %k, i16 0, i16 0
  call i16 @allocate(i16* %arraydecay, i16* null)
  ret void
}