1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-linux-gnu | FileCheck %s
4 ; Note that this should be refactored (for efficiency if nothing else)
5 ; when the PCS is implemented so we don't have to worry about the
8 @var_i32 = global i32 42
9 @var2_i32 = global i32 43
10 @var_i64 = global i64 0
12 ; Add pure 12-bit immediates:
13 define void @add_small() {
14 ; CHECK-LABEL: add_small:
16 ; CHECK-NEXT: adrp x8, :got:var_i32
17 ; CHECK-NEXT: adrp x9, :got:var_i64
18 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
19 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
20 ; CHECK-NEXT: ldr w10, [x8]
21 ; CHECK-NEXT: ldr x11, [x9]
22 ; CHECK-NEXT: add w10, w10, #4095
23 ; CHECK-NEXT: add x11, x11, #52
24 ; CHECK-NEXT: str w10, [x8]
25 ; CHECK-NEXT: str x11, [x9]
28 %val32 = load i32, i32* @var_i32
29 %newval32 = add i32 %val32, 4095
30 store i32 %newval32, i32* @var_i32
32 %val64 = load i64, i64* @var_i64
33 %newval64 = add i64 %val64, 52
34 store i64 %newval64, i64* @var_i64
39 ; Make sure we grab the imm variant when the register operand
40 ; can be implicitly zero-extend.
41 ; We used to generate something horrible like this:
44 ; xC = add xB, wA, uxtb
45 ; whereas this can be achieved with:
47 ; xC = add xA, #12 ; <- xA implicitly zero extend wA.
48 define void @add_small_imm(i8* %p, i64* %q, i32 %b, i32* %addr) {
49 ; CHECK-LABEL: add_small_imm:
50 ; CHECK: // %bb.0: // %entry
51 ; CHECK-NEXT: ldrb w8, [x0]
52 ; CHECK-NEXT: add w9, w8, w2
53 ; CHECK-NEXT: add x8, x8, #12
54 ; CHECK-NEXT: str w9, [x3]
55 ; CHECK-NEXT: str x8, [x1]
60 %promoted = zext i8 %t to i64
61 %zextt = zext i8 %t to i32
62 %add = add nuw i32 %zextt, %b
64 %add2 = add nuw i64 %promoted, 12
65 store i32 %add, i32* %addr
67 store i64 %add2, i64* %q
71 ; Add 12-bit immediates, shifted left by 12 bits
72 define void @add_med() {
73 ; CHECK-LABEL: add_med:
75 ; CHECK-NEXT: adrp x8, :got:var_i32
76 ; CHECK-NEXT: adrp x9, :got:var_i64
77 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
78 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
79 ; CHECK-NEXT: ldr w10, [x8]
80 ; CHECK-NEXT: ldr x11, [x9]
81 ; CHECK-NEXT: add w10, w10, #3567, lsl #12 // =14610432
82 ; CHECK-NEXT: add x11, x11, #4095, lsl #12 // =16773120
83 ; CHECK-NEXT: str w10, [x8]
84 ; CHECK-NEXT: str x11, [x9]
87 %val32 = load i32, i32* @var_i32
88 %newval32 = add i32 %val32, 14610432 ; =0xdef000
89 store i32 %newval32, i32* @var_i32
91 %val64 = load i64, i64* @var_i64
92 %newval64 = add i64 %val64, 16773120 ; =0xfff000
93 store i64 %newval64, i64* @var_i64
98 ; Subtract 12-bit immediates
99 define void @sub_small() {
100 ; CHECK-LABEL: sub_small:
102 ; CHECK-NEXT: adrp x8, :got:var_i32
103 ; CHECK-NEXT: adrp x9, :got:var_i64
104 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
105 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
106 ; CHECK-NEXT: ldr w10, [x8]
107 ; CHECK-NEXT: ldr x11, [x9]
108 ; CHECK-NEXT: sub w10, w10, #4095
109 ; CHECK-NEXT: sub x11, x11, #52
110 ; CHECK-NEXT: str w10, [x8]
111 ; CHECK-NEXT: str x11, [x9]
114 %val32 = load i32, i32* @var_i32
115 %newval32 = sub i32 %val32, 4095
116 store i32 %newval32, i32* @var_i32
118 %val64 = load i64, i64* @var_i64
119 %newval64 = sub i64 %val64, 52
120 store i64 %newval64, i64* @var_i64
125 ; Subtract 12-bit immediates, shifted left by 12 bits
126 define void @sub_med() {
127 ; CHECK-LABEL: sub_med:
129 ; CHECK-NEXT: adrp x8, :got:var_i32
130 ; CHECK-NEXT: adrp x9, :got:var_i64
131 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
132 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
133 ; CHECK-NEXT: ldr w10, [x8]
134 ; CHECK-NEXT: ldr x11, [x9]
135 ; CHECK-NEXT: sub w10, w10, #3567, lsl #12 // =14610432
136 ; CHECK-NEXT: sub x11, x11, #4095, lsl #12 // =16773120
137 ; CHECK-NEXT: str w10, [x8]
138 ; CHECK-NEXT: str x11, [x9]
141 %val32 = load i32, i32* @var_i32
142 %newval32 = sub i32 %val32, 14610432 ; =0xdef000
143 store i32 %newval32, i32* @var_i32
145 %val64 = load i64, i64* @var_i64
146 %newval64 = sub i64 %val64, 16773120 ; =0xfff000
147 store i64 %newval64, i64* @var_i64
152 define void @testing() {
153 ; CHECK-LABEL: testing:
155 ; CHECK-NEXT: adrp x8, :got:var_i32
156 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
157 ; CHECK-NEXT: ldr w9, [x8]
158 ; CHECK-NEXT: cmp w9, #4095
159 ; CHECK-NEXT: b.ne .LBB5_6
160 ; CHECK-NEXT: // %bb.1: // %test2
161 ; CHECK-NEXT: adrp x10, :got:var2_i32
162 ; CHECK-NEXT: ldr x10, [x10, :got_lo12:var2_i32]
163 ; CHECK-NEXT: add w11, w9, #1
164 ; CHECK-NEXT: str w11, [x8]
165 ; CHECK-NEXT: ldr w10, [x10]
166 ; CHECK-NEXT: cmp w10, #3567, lsl #12 // =14610432
167 ; CHECK-NEXT: b.lo .LBB5_6
168 ; CHECK-NEXT: // %bb.2: // %test3
169 ; CHECK-NEXT: add w11, w9, #2
170 ; CHECK-NEXT: cmp w9, #123
171 ; CHECK-NEXT: str w11, [x8]
172 ; CHECK-NEXT: b.lt .LBB5_6
173 ; CHECK-NEXT: // %bb.3: // %test4
174 ; CHECK-NEXT: add w11, w9, #3
175 ; CHECK-NEXT: cmp w10, #321
176 ; CHECK-NEXT: str w11, [x8]
177 ; CHECK-NEXT: b.gt .LBB5_6
178 ; CHECK-NEXT: // %bb.4: // %test5
179 ; CHECK-NEXT: add w11, w9, #4
180 ; CHECK-NEXT: cmn w10, #443
181 ; CHECK-NEXT: str w11, [x8]
182 ; CHECK-NEXT: b.ge .LBB5_6
183 ; CHECK-NEXT: // %bb.5: // %test6
184 ; CHECK-NEXT: add w9, w9, #5
185 ; CHECK-NEXT: str w9, [x8]
186 ; CHECK-NEXT: .LBB5_6: // %common.ret
188 %val = load i32, i32* @var_i32
189 %val2 = load i32, i32* @var2_i32
191 %cmp_pos_small = icmp ne i32 %val, 4095
192 br i1 %cmp_pos_small, label %ret, label %test2
195 %newval2 = add i32 %val, 1
196 store i32 %newval2, i32* @var_i32
197 %cmp_pos_big = icmp ult i32 %val2, 14610432
198 br i1 %cmp_pos_big, label %ret, label %test3
201 %newval3 = add i32 %val, 2
202 store i32 %newval3, i32* @var_i32
203 %cmp_pos_slt = icmp slt i32 %val, 123
204 br i1 %cmp_pos_slt, label %ret, label %test4
207 %newval4 = add i32 %val, 3
208 store i32 %newval4, i32* @var_i32
209 %cmp_pos_sgt = icmp sgt i32 %val2, 321
210 br i1 %cmp_pos_sgt, label %ret, label %test5
213 %newval5 = add i32 %val, 4
214 store i32 %newval5, i32* @var_i32
215 %cmp_neg_uge = icmp sgt i32 %val2, -444
216 br i1 %cmp_neg_uge, label %ret, label %test6
219 %newval6 = add i32 %val, 5
220 store i32 %newval6, i32* @var_i32
227 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
229 define i1 @sadd_add(i32 %a, i32 %b, i32* %p) {
230 ; CHECK-LABEL: sadd_add:
232 ; CHECK-NEXT: mvn w8, w0
233 ; CHECK-NEXT: adds w8, w8, w1
234 ; CHECK-NEXT: cset w0, vs
235 ; CHECK-NEXT: add w8, w8, #1
236 ; CHECK-NEXT: str w8, [x2]
238 %nota = xor i32 %a, -1
239 %a0 = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %nota, i32 %b)
240 %e0 = extractvalue {i32, i1} %a0, 0
241 %e1 = extractvalue {i32, i1} %a0, 1
242 %res = add i32 %e0, 1
243 store i32 %res, i32* %p
247 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
249 define i1 @uadd_add(i8 %a, i8 %b, i8* %p) {
250 ; CHECK-LABEL: uadd_add:
252 ; CHECK-NEXT: mvn w8, w0
253 ; CHECK-NEXT: and w8, w8, #0xff
254 ; CHECK-NEXT: add w8, w8, w1, uxtb
255 ; CHECK-NEXT: lsr w0, w8, #8
256 ; CHECK-NEXT: add w8, w8, #1
257 ; CHECK-NEXT: strb w8, [x2]
259 %nota = xor i8 %a, -1
260 %a0 = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %nota, i8 %b)
261 %e0 = extractvalue {i8, i1} %a0, 0
262 %e1 = extractvalue {i8, i1} %a0, 1
264 store i8 %res, i8* %p