indexed-mem.ll
5.33 KB
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
; RUN: llc -mtriple=thumbv8m.main %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V8M
; RUN: llc -mtriple=armv8 %s -o - | FileCheck %s --check-prefix=CHECK-V8
; CHECK-LABEL: pre_inc_ldr
; CHECK: ldr{{.*}}, [r0, #4]!
define i32* @pre_inc_ldr(i32* %base, i32 %a) {
%addr = getelementptr i32, i32* %base, i32 1
%ld = load i32, i32* %addr
%addr.1 = getelementptr i32, i32* %base, i32 2
%res = add i32 %ld, %a
store i32 %res, i32* %addr.1
ret i32* %addr
}
; CHECK-LABEL: pre_dec_ldr
; CHECK: ldr{{.*}}, [r0, #-4]!
define i32* @pre_dec_ldr(i32* %base, i32 %a) {
%addr = getelementptr i32, i32* %base, i32 -1
%ld = load i32, i32* %addr
%addr.1 = getelementptr i32, i32* %base, i32 2
%res = add i32 %ld, %a
store i32 %res, i32* %addr.1
ret i32* %addr
}
; CHECK-LABEL: post_inc_ldr
; CHECK: ldr{{.*}}, [r0], #4
define i32* @post_inc_ldr(i32* %base, i32* %addr.2, i32 %a) {
%addr = getelementptr i32, i32* %base, i32 0
%ld = load i32, i32* %addr
%addr.1 = getelementptr i32, i32* %base, i32 1
%res = add i32 %ld, %a
store i32 %res, i32* %addr.2
ret i32* %addr.1
}
; CHECK-LABEL: post_dec_ldr
; CHECK: ldr{{.*}}, [r0], #-4
define i32* @post_dec_ldr(i32* %base, i32* %addr.2, i32 %a) {
%addr = getelementptr i32, i32* %base, i32 0
%ld = load i32, i32* %addr
%addr.1 = getelementptr i32, i32* %base, i32 -1
%res = add i32 %ld, %a
store i32 %res, i32* %addr.2
ret i32* %addr.1
}
; CHECK-LABEL: pre_inc_str
; CHECK: str{{.*}}, [r0, #4]!
define i32* @pre_inc_str(i32* %base, i32 %a, i32 %b) {
%addr.1 = getelementptr i32, i32* %base, i32 1
%res = add i32 %a, %b
store i32 %res, i32* %addr.1
ret i32* %addr.1
}
; CHECK-LABEL: pre_dec_str
; CHECK: str{{.*}}, [r0, #-4]!
define i32* @pre_dec_str(i32* %base, i32 %a, i32 %b) {
%res = add i32 %a, %b
%addr.1 = getelementptr i32, i32* %base, i32 -1
store i32 %res, i32* %addr.1
ret i32* %addr.1
}
; CHECK-LABEL: post_inc_str
; CHECK: str{{.*}}, [r0], #4
define i32* @post_inc_str(i32* %base, i32 %a, i32 %b) {
%addr.1 = getelementptr i32, i32* %base, i32 1
%res = add i32 %a, %b
store i32 %res, i32* %base
ret i32* %addr.1
}
; CHECK-LABEL: post_dec_str
; CHECK: str{{.*}}, [r0], #-4
define i32* @post_dec_str(i32* %base, i32 %a, i32 %b) {
%addr.1 = getelementptr i32, i32* %base, i32 -1
%res = add i32 %a, %b
store i32 %res, i32* %base
ret i32* %addr.1
}
; TODO: Generate ldrd
; CHECK-LABEL: pre_inc_ldrd
; CHECK: ldr{{.*}}, #4]!
define i32* @pre_inc_ldrd(i32* %base) {
%addr = getelementptr i32, i32* %base, i32 1
%addr.1 = getelementptr i32, i32* %base, i32 2
%addr.2 = getelementptr i32, i32* %base, i32 3
%ld = load i32, i32* %addr
%ld.1 = load i32, i32* %addr.1
%res = add i32 %ld, %ld.1
store i32 %res, i32* %addr.2
ret i32* %addr
}
; TODO: Generate ldrd
; CHECK-LABEL: pre_dec_ldrd
; CHECK: ldr{{.*}}, #-4]!
define i32* @pre_dec_ldrd(i32* %base) {
%addr = getelementptr i32, i32* %base, i32 -1
%addr.1 = getelementptr i32, i32* %base, i32 -2
%addr.2 = getelementptr i32, i32* %base, i32 -3
%ld = load i32, i32* %addr
%ld.1 = load i32, i32* %addr.1
%res = add i32 %ld, %ld.1
store i32 %res, i32* %addr.2
ret i32* %addr
}
; TODO: Generate post inc
; CHECK-LABEL: post_inc_ldrd
; CHECK-V8M: ldrd{{.*}}, [r0]
; CHECK-V8: ldm
; CHECK: add{{.*}}, #8
define i32* @post_inc_ldrd(i32* %base, i32* %addr.3) {
%addr = getelementptr i32, i32* %base, i32 0
%ld = load i32, i32* %addr
%addr.1 = getelementptr i32, i32* %base, i32 1
%ld.1 = load i32, i32* %addr.1
%addr.2 = getelementptr i32, i32* %base, i32 2
%res = add i32 %ld, %ld.1
store i32 %res, i32* %addr.3
ret i32* %addr.2
}
; CHECK-LABEL: pre_inc_str_multi
; CHECK: str{{.*}}, #8]!
define i32* @pre_inc_str_multi(i32* %base) {
%addr = getelementptr i32, i32* %base, i32 0
%addr.1 = getelementptr i32, i32* %base, i32 1
%ld = load i32, i32* %addr
%ld.1 = load i32, i32* %addr.1
%res = add i32 %ld, %ld.1
%addr.2 = getelementptr i32, i32* %base, i32 2
store i32 %res, i32* %addr.2
ret i32* %addr.2
}
; CHECK-LABEL: pre_dec_str_multi
; CHECK: str{{.*}}, #-4]!
define i32* @pre_dec_str_multi(i32* %base) {
%addr = getelementptr i32, i32* %base, i32 0
%addr.1 = getelementptr i32, i32* %base, i32 1
%ld = load i32, i32* %addr
%ld.1 = load i32, i32* %addr.1
%res = add i32 %ld, %ld.1
%addr.2 = getelementptr i32, i32* %base, i32 -1
store i32 %res, i32* %addr.2
ret i32* %addr.2
}
; CHECK-LABEL: illegal_pre_inc_store_1
; CHECK-NOT: str{{.*}} ]!
define i32* @illegal_pre_inc_store_1(i32* %base) {
entry:
%ptr.to.use = getelementptr i32, i32* %base, i32 2
%ptr.to.store = ptrtoint i32* %base to i32
store i32 %ptr.to.store, i32* %ptr.to.use, align 4
ret i32* %ptr.to.use
}
; TODO: The mov should be unecessary
; CHECK-LABEL: legal_pre_inc_store_needs_copy_1
; CHECK: add{{.*}}, #8
; CHECK-NOT: str{{.*}}]!
; CHECK: mov
define i32* @legal_pre_inc_store_needs_copy_1(i32* %base) {
entry:
%ptr.to.use = getelementptr i32, i32* %base, i32 2
%ptr.to.store = ptrtoint i32* %ptr.to.use to i32
store i32 %ptr.to.store, i32* %ptr.to.use, align 4
ret i32* %ptr.to.use
}
; CHECK-LABEL: legal_pre_inc_store_needs_copy_2
; CHECK-NOT: mov
; CHECK-NOT: str{{.*}}]!
define i32* @legal_pre_inc_store_needs_copy_2(i32 %base) {
entry:
%ptr = inttoptr i32 %base to i32*
%ptr.to.use = getelementptr i32, i32* %ptr, i32 2
store i32 %base, i32* %ptr.to.use, align 4
ret i32* %ptr.to.use
}