blob: 7fc080463a3367693622844c99eccaab97b4ba6e [file] [log] [blame]
Jim Grosbach6f09fcf2011-09-30 17:41:35 +00001; RUN: llc < %s -O0 -fast-isel-abort -relocation-model=dynamic-no-pic -mtriple=armv7-apple-darwin | FileCheck %s --check-prefix=ARM
2; RUN: llc < %s -O0 -fast-isel-abort -relocation-model=dynamic-no-pic -mtriple=thumbv7-apple-darwin | 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
145; THUMB: ldr.n r0, LCPI4_1
146; THUMB: ldr r0, [r0]
147; THUMB: ldr r0, [r0]
148; THUMB: adds r0, #1
149; THUMB: ldr.n r1, LCPI4_0
150; THUMB: ldr r1, [r1]
151; THUMB: str r0, [r1]
152
153; ARM: ldr r0, LCPI4_1
154; ARM: ldr r0, [r0]
155; ARM: ldr r0, [r0]
156; ARM: add r0, r0, #1
157; ARM: ldr r1, LCPI4_0
158; ARM: ldr r1, [r1]
159; ARM: str r0, [r1]
160}
Chad Rosier9eff1e32011-12-03 02:21:57 +0000161
162; Check unaligned stores
163%struct.anon = type <{ float }>
164
165@a = common global %struct.anon* null, align 4
166
167define void @unaligned_store(float %x, float %y) nounwind {
168entry:
169; ARM: @unaligned_store
170; ARM: vmov r1, s0
171; ARM: str r1, [r0]
172
173; THUMB: @unaligned_store
174; THUMB: vmov r1, s0
175; THUMB: str r1, [r0]
176
177 %add = fadd float %x, %y
178 %0 = load %struct.anon** @a, align 4
179 %x1 = getelementptr inbounds %struct.anon* %0, i32 0, i32 0
180 store float %add, float* %x1, align 1
181 ret void
182}
Chad Rosiered42c5f2011-12-06 01:44:17 +0000183
184; Doublewords require only word-alignment.
185; rdar://10528060
186%struct.anon.0 = type { double }
187
188@foo_unpacked = common global %struct.anon.0 zeroinitializer, align 4
189
190define void @test5(double %a, double %b) nounwind {
191entry:
192; ARM: @test5
193; THUMB: @test5
194 %add = fadd double %a, %b
195 store double %add, double* getelementptr inbounds (%struct.anon.0* @foo_unpacked, i32 0, i32 0), align 4
196; ARM: vstr d16, [r0]
197; THUMB: vstr d16, [r0]
198 ret void
199}
200
Chad Rosier8a9bce92011-12-13 19:22:14 +0000201; Check unaligned loads of floats
202%class.TAlignTest = type <{ i16, float }>
203
204define zeroext i1 @test6(%class.TAlignTest* %this) nounwind align 2 {
205entry:
206; ARM: @test6
207; THUMB: @test6
208 %0 = alloca %class.TAlignTest*, align 4
209 store %class.TAlignTest* %this, %class.TAlignTest** %0, align 4
210 %1 = load %class.TAlignTest** %0
211 %2 = getelementptr inbounds %class.TAlignTest* %1, i32 0, i32 1
212 %3 = load float* %2, align 1
213 %4 = fcmp une float %3, 0.000000e+00
214; ARM: ldr r0, [r0, #2]
215; ARM: vmov s0, r0
216; ARM: vcmpe.f32 s0, #0
217; THUMB: ldr.w r0, [r0, #2]
218; THUMB: vmov s0, r0
219; THUMB: vcmpe.f32 s0, #0
220 ret i1 %4
221}