blob: c8e0211c60c853cfb28a80bbdd421f001558975e [file] [log] [blame]
Evan Chengafff9412011-12-20 18:26:50 +00001; RUN: llc < %s -O0 -fast-isel-abort -relocation-model=dynamic-no-pic -mtriple=armv7-apple-ios | FileCheck %s --check-prefix=ARM
2; RUN: llc < %s -O0 -fast-isel-abort -relocation-model=dynamic-no-pic -mtriple=thumbv7-apple-ios | FileCheck %s --check-prefix=THUMB
Eric Christopherab695882010-07-21 22:26:11 +00003
4; Very basic fast-isel functionality.
Eric Christopherf2605412010-09-08 19:32:34 +00005define i32 @add(i32 %a, i32 %b) nounwind {
Eric Christopherab695882010-07-21 22:26:11 +00006entry:
7 %a.addr = alloca i32, align 4
8 %b.addr = alloca i32, align 4
9 store i32 %a, i32* %a.addr
10 store i32 %b, i32* %b.addr
11 %tmp = load i32* %a.addr
12 %tmp1 = load i32* %b.addr
13 %add = add nsw i32 %tmp, %tmp1
14 ret i32 %add
Eric Christopherbcf26ae2011-04-29 20:02:39 +000015}
16
Eli Friedmanc573e2c2011-04-29 22:48:03 +000017; Check truncate to bool
Eric Christopherbcf26ae2011-04-29 20:02:39 +000018define void @test1(i32 %tmp) nounwind {
19entry:
20%tobool = trunc i32 %tmp to i1
21br i1 %tobool, label %if.then, label %if.end
22
23if.then: ; preds = %entry
24call void @test1(i32 0)
25br label %if.end
26
27if.end: ; preds = %if.then, %entry
28ret void
Eli Friedmanc573e2c2011-04-29 22:48:03 +000029; ARM: test1:
30; ARM: tst r0, #1
31; THUMB: test1:
32; THUMB: tst.w r0, #1
33}
34
35; Check some simple operations with immediates
36define void @test2(i32 %tmp, i32* %ptr) nounwind {
37; THUMB: test2:
38; ARM: test2:
39
40b1:
Eli Friedmanb2b03fc2011-04-29 23:34:52 +000041 %a = add i32 %tmp, 4096
42 store i32 %a, i32* %ptr
Eli Friedmanc573e2c2011-04-29 22:48:03 +000043 br label %b2
44
45; THUMB: add.w {{.*}} #4096
Jim Grosbach589130f2011-07-11 16:48:36 +000046; ARM: add {{.*}} #4096
Eli Friedmanc573e2c2011-04-29 22:48:03 +000047
48b2:
Eli Friedmanb2b03fc2011-04-29 23:34:52 +000049 %b = add i32 %tmp, 4095
50 store i32 %b, i32* %ptr
51 br label %b3
52; THUMB: addw {{.*}} #4095
53; ARM: movw {{.*}} #4095
54; ARM: add
55
56b3:
Eli Friedmanc573e2c2011-04-29 22:48:03 +000057 %c = or i32 %tmp, 4
58 store i32 %c, i32* %ptr
59 ret void
60
61; THUMB: orr {{.*}} #4
62; ARM: orr {{.*}} #4
Eric Christopherbcf26ae2011-04-29 20:02:39 +000063}
Eli Friedman76927d732011-05-25 23:49:02 +000064
65define void @test3(i32 %tmp, i32* %ptr1, i16* %ptr2, i8* %ptr3) nounwind {
66; THUMB: test3:
67; ARM: test3:
68
69bb1:
70 %a1 = trunc i32 %tmp to i16
71 %a2 = trunc i16 %a1 to i8
72 %a3 = trunc i8 %a2 to i1
73 %a4 = zext i1 %a3 to i8
74 store i8 %a4, i8* %ptr3
75 %a5 = zext i8 %a4 to i16
76 store i16 %a5, i16* %ptr2
77 %a6 = zext i16 %a5 to i32
78 store i32 %a6, i32* %ptr1
79 br label %bb2
80
81; THUMB: and
82; THUMB: strb
83; THUMB: uxtb
84; THUMB: strh
85; THUMB: uxth
86; ARM: and
87; ARM: strb
88; ARM: uxtb
89; ARM: strh
90; ARM: uxth
91
92bb2:
93 %b1 = trunc i32 %tmp to i16
94 %b2 = trunc i16 %b1 to i8
95 store i8 %b2, i8* %ptr3
96 %b3 = sext i8 %b2 to i16
97 store i16 %b3, i16* %ptr2
98 %b4 = sext i16 %b3 to i32
99 store i32 %b4, i32* %ptr1
100 br label %bb3
101
102; THUMB: strb
103; THUMB: sxtb
104; THUMB: strh
105; THUMB: sxth
106; ARM: strb
107; ARM: sxtb
108; ARM: strh
109; ARM: sxth
110
111bb3:
112 %c1 = load i8* %ptr3
113 %c2 = load i16* %ptr2
114 %c3 = load i32* %ptr1
115 %c4 = zext i8 %c1 to i32
116 %c5 = sext i16 %c2 to i32
117 %c6 = add i32 %c4, %c5
118 %c7 = sub i32 %c3, %c6
119 store i32 %c7, i32* %ptr1
120 ret void
121
122; THUMB: ldrb
123; THUMB: ldrh
124; THUMB: uxtb
125; THUMB: sxth
126; THUMB: add
127; THUMB: sub
128; ARM: ldrb
129; ARM: ldrh
130; ARM: uxtb
131; ARM: sxth
132; ARM: add
133; ARM: sub
Eli Friedmand6412c92011-06-03 01:13:19 +0000134}
135
136; Check loads/stores with globals
137@test4g = external global i32
138
139define void @test4() {
140 %a = load i32* @test4g
141 %b = add i32 %a, 1
142 store i32 %b, i32* @test4g
143 ret void
144
Jakob Stoklund Olesen45ca7c62012-01-07 01:47:05 +0000145; THUMB: movw r0, :lower16:L_test4g$non_lazy_ptr
146; THUMB: movt r0, :upper16:L_test4g$non_lazy_ptr
Eli Friedmand6412c92011-06-03 01:13:19 +0000147; THUMB: ldr r0, [r0]
148; THUMB: ldr r0, [r0]
149; THUMB: adds r0, #1
Jakob Stoklund Olesen45ca7c62012-01-07 01:47:05 +0000150; THUMB: movw r1, :lower16:L_test4g$non_lazy_ptr
151; THUMB: movt r1, :upper16:L_test4g$non_lazy_ptr
Eli Friedmand6412c92011-06-03 01:13:19 +0000152; THUMB: ldr r1, [r1]
153; THUMB: str r0, [r1]
154
Jakob Stoklund Olesen45ca7c62012-01-07 01:47:05 +0000155; ARM: movw r0, :lower16:L_test4g$non_lazy_ptr
156; ARM: movt r0, :upper16:L_test4g$non_lazy_ptr
Eli Friedmand6412c92011-06-03 01:13:19 +0000157; ARM: ldr r0, [r0]
158; ARM: ldr r0, [r0]
159; ARM: add r0, r0, #1
Jakob Stoklund Olesen45ca7c62012-01-07 01:47:05 +0000160; ARM: movw r1, :lower16:L_test4g$non_lazy_ptr
161; ARM: movt r1, :upper16:L_test4g$non_lazy_ptr
Eli Friedmand6412c92011-06-03 01:13:19 +0000162; ARM: ldr r1, [r1]
163; ARM: str r0, [r1]
164}
Chad Rosier9eff1e32011-12-03 02:21:57 +0000165
166; Check unaligned stores
167%struct.anon = type <{ float }>
168
169@a = common global %struct.anon* null, align 4
170
171define void @unaligned_store(float %x, float %y) nounwind {
172entry:
173; ARM: @unaligned_store
174; ARM: vmov r1, s0
175; ARM: str r1, [r0]
176
177; THUMB: @unaligned_store
178; THUMB: vmov r1, s0
179; THUMB: str r1, [r0]
180
181 %add = fadd float %x, %y
182 %0 = load %struct.anon** @a, align 4
183 %x1 = getelementptr inbounds %struct.anon* %0, i32 0, i32 0
184 store float %add, float* %x1, align 1
185 ret void
186}
Chad Rosiered42c5f2011-12-06 01:44:17 +0000187
188; Doublewords require only word-alignment.
189; rdar://10528060
190%struct.anon.0 = type { double }
191
192@foo_unpacked = common global %struct.anon.0 zeroinitializer, align 4
193
194define void @test5(double %a, double %b) nounwind {
195entry:
196; ARM: @test5
197; THUMB: @test5
198 %add = fadd double %a, %b
199 store double %add, double* getelementptr inbounds (%struct.anon.0* @foo_unpacked, i32 0, i32 0), align 4
200; ARM: vstr d16, [r0]
201; THUMB: vstr d16, [r0]
202 ret void
203}
204
Chad Rosier8a9bce92011-12-13 19:22:14 +0000205; Check unaligned loads of floats
206%class.TAlignTest = type <{ i16, float }>
207
208define zeroext i1 @test6(%class.TAlignTest* %this) nounwind align 2 {
209entry:
210; ARM: @test6
211; THUMB: @test6
212 %0 = alloca %class.TAlignTest*, align 4
213 store %class.TAlignTest* %this, %class.TAlignTest** %0, align 4
214 %1 = load %class.TAlignTest** %0
215 %2 = getelementptr inbounds %class.TAlignTest* %1, i32 0, i32 1
216 %3 = load float* %2, align 1
217 %4 = fcmp une float %3, 0.000000e+00
218; ARM: ldr r0, [r0, #2]
219; ARM: vmov s0, r0
220; ARM: vcmpe.f32 s0, #0
221; THUMB: ldr.w r0, [r0, #2]
222; THUMB: vmov s0, r0
223; THUMB: vcmpe.f32 s0, #0
224 ret i1 %4
Chad Rosier8f644252011-12-14 01:34:39 +0000225}