1 ; RUN: llc < %s -mtriple=armv7-apple-darwin | FileCheck %s
2 ; RUN: llc < %s -mtriple=thumbv7-apple-darwin > %t
3 ; RUN: FileCheck %s < %t
4 ; RUN: FileCheck %s < %t --check-prefix=CHECK-T2ADDRMODE
10 define i64 @f0(ptr %p) nounwind readonly {
12 %ldrexd = tail call %0 @llvm.arm.ldrexd(ptr %p)
13 %0 = extractvalue %0 %ldrexd, 1
14 %1 = extractvalue %0 %ldrexd, 0
15 %2 = zext i32 %0 to i64
16 %3 = zext i32 %1 to i64
17 %shl = shl nuw i64 %2, 32
24 define i32 @f1(ptr %ptr, i64 %val) nounwind {
26 %tmp4 = trunc i64 %val to i32
27 %tmp6 = lshr i64 %val, 32
28 %tmp7 = trunc i64 %tmp6 to i32
29 %strexd = tail call i32 @llvm.arm.strexd(i32 %tmp4, i32 %tmp7, ptr %ptr)
33 declare %0 @llvm.arm.ldrexd(ptr) nounwind readonly
34 declare i32 @llvm.arm.strexd(i32, i32, ptr) nounwind
36 ; CHECK-LABEL: test_load_i8:
37 ; CHECK: ldrexb r0, [r0]
40 define zeroext i8 @test_load_i8(ptr %addr) {
41 %val = call i32 @llvm.arm.ldrex.p0(ptr elementtype(i8) %addr)
42 %val8 = trunc i32 %val to i8
46 ; CHECK-LABEL: test_load_i16:
47 ; CHECK: ldrexh r0, [r0]
50 define zeroext i16 @test_load_i16(ptr %addr) {
51 %val = call i32 @llvm.arm.ldrex.p0(ptr elementtype(i16) %addr)
52 %val16 = trunc i32 %val to i16
56 ; CHECK-LABEL: test_load_i32:
57 ; CHECK: ldrex r0, [r0]
58 define i32 @test_load_i32(ptr %addr) {
59 %val = call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %addr)
63 declare i32 @llvm.arm.ldrex.p0(ptr) nounwind readonly
65 ; CHECK-LABEL: test_store_i8:
67 ; CHECK: strexb r0, r1, [r2]
68 define i32 @test_store_i8(i32, i8 %val, ptr %addr) {
69 %extval = zext i8 %val to i32
70 %res = call i32 @llvm.arm.strex.p0(i32 %extval, ptr elementtype(i8) %addr)
74 ; CHECK-LABEL: test_store_i16:
76 ; CHECK: strexh r0, r1, [r2]
77 define i32 @test_store_i16(i32, i16 %val, ptr %addr) {
78 %extval = zext i16 %val to i32
79 %res = call i32 @llvm.arm.strex.p0(i32 %extval, ptr elementtype(i16) %addr)
83 ; CHECK-LABEL: test_store_i32:
84 ; CHECK: strex r0, r1, [r2]
85 define i32 @test_store_i32(i32, i32 %val, ptr %addr) {
86 %res = call i32 @llvm.arm.strex.p0(i32 %val, ptr elementtype(i32) %addr)
90 declare i32 @llvm.arm.strex.p0(i32, ptr) nounwind
92 ; CHECK-LABEL: test_clear:
94 define void @test_clear() {
95 call void @llvm.arm.clrex()
99 declare void @llvm.arm.clrex() nounwind
101 @base = global ptr null
103 define void @excl_addrmode() {
104 ; CHECK-T2ADDRMODE-LABEL: excl_addrmode:
105 %base1020 = load ptr, ptr @base
106 %offset1020 = getelementptr i32, ptr %base1020, i32 255
107 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %offset1020)
108 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %offset1020)
109 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [{{r[0-9]+}}, #1020]
110 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [{{r[0-9]+}}, #1020]
112 %base1024 = load ptr, ptr @base
113 %offset1024 = getelementptr i32, ptr %base1024, i32 256
114 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %offset1024)
115 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %offset1024)
116 ; CHECK-T2ADDRMODE: add.w r[[ADDR:[0-9]+]], {{r[0-9]+}}, #1024
117 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
118 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
120 %base1 = load ptr, ptr @base
121 %offset1_8 = getelementptr i8, ptr %base1, i32 1
122 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %offset1_8)
123 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %offset1_8)
124 ; CHECK-T2ADDRMODE: adds r[[ADDR:[0-9]+]], #1
125 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
126 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
128 %local = alloca i8, i32 1024
129 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local)
130 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local)
131 ; CHECK-T2ADDRMODE: mov r[[ADDR:[0-9]+]], sp
132 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
133 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
138 define void @test_excl_addrmode_folded() {
139 ; CHECK-LABEL: test_excl_addrmode_folded:
140 %local = alloca i8, i32 4096
142 %local.0 = getelementptr i8, ptr %local, i32 4
143 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.0)
144 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.0)
145 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [sp, #4]
146 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [sp, #4]
148 %local.1 = getelementptr i8, ptr %local, i32 1020
149 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.1)
150 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.1)
151 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [sp, #1020]
152 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [sp, #1020]
157 define void @test_excl_addrmode_range() {
158 ; CHECK-LABEL: test_excl_addrmode_range:
159 %local = alloca i8, i32 4096
161 %local.0 = getelementptr i8, ptr %local, i32 1024
162 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.0)
163 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.0)
164 ; CHECK-T2ADDRMODE: mov r[[TMP:[0-9]+]], sp
165 ; CHECK-T2ADDRMODE: add.w r[[ADDR:[0-9]+]], r[[TMP]], #1024
166 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
167 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
172 define void @test_excl_addrmode_align() {
173 ; CHECK-LABEL: test_excl_addrmode_align:
174 %local = alloca i8, i32 4096
176 %local.0 = getelementptr i8, ptr %local, i32 2
177 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.0)
178 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.0)
179 ; CHECK-T2ADDRMODE: mov r[[ADDR:[0-9]+]], sp
180 ; CHECK-T2ADDRMODE: adds r[[ADDR:[0-9]+]], #2
181 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
182 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
187 define void @test_excl_addrmode_sign() {
188 ; CHECK-LABEL: test_excl_addrmode_sign:
189 %local = alloca i8, i32 4096
191 %local.0 = getelementptr i8, ptr %local, i32 -4
192 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.0)
193 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.0)
194 ; CHECK-T2ADDRMODE: mov r[[ADDR:[0-9]+]], sp
195 ; CHECK-T2ADDRMODE: subs r[[ADDR:[0-9]+]], #4
196 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [r[[ADDR]]]
197 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [r[[ADDR]]]
202 define void @test_excl_addrmode_combination() {
203 ; CHECK-LABEL: test_excl_addrmode_combination:
204 %local = alloca i8, i32 4096
205 %unused = alloca i8, i32 64
207 %local.0 = getelementptr i8, ptr %local, i32 4
208 call i32 @llvm.arm.ldrex.p0(ptr elementtype(i32) %local.0)
209 call i32 @llvm.arm.strex.p0(i32 0, ptr elementtype(i32) %local.0)
210 ; CHECK-T2ADDRMODE: ldrex {{r[0-9]+}}, [sp, #68]
211 ; CHECK-T2ADDRMODE: strex {{r[0-9]+}}, {{r[0-9]+}}, [sp, #68]
217 ; LLVM should know, even across basic blocks, that ldrex is setting the high
218 ; bits of its i32 to 0. There should be no zero-extend operation.
219 define zeroext i8 @test_cross_block_zext_i8(i1 %tst, ptr %addr) {
220 ; CHECK: test_cross_block_zext_i8:
224 %val = call i32 @llvm.arm.ldrex.p0(ptr elementtype(i8) %addr)
225 br i1 %tst, label %end, label %mid
229 %val8 = trunc i32 %val to i8