• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -mattr=-avx -fast-isel -mcpu=core2 -O0 -regalloc=fast -asm-verbose=0 -fast-isel-abort=1 | FileCheck %s
2; RUN: llc < %s -mattr=+avx -fast-isel -mcpu=core2 -O0 -regalloc=fast -asm-verbose=0 -fast-isel-abort=1 | FileCheck %s --check-prefix=AVX
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5target triple = "x86_64-apple-darwin10.0.0"
6
7; Make sure that fast-isel folds the immediate into the binop even though it
8; is non-canonical.
9define i32 @test1(i32 %i) nounwind ssp {
10  %and = and i32 8, %i
11  ret i32 %and
12}
13
14; CHECK-LABEL: test1:
15; CHECK: andl	$8,
16
17
18; rdar://9289512 - The load should fold into the compare.
19define void @test2(i64 %x) nounwind ssp {
20entry:
21  %x.addr = alloca i64, align 8
22  store i64 %x, i64* %x.addr, align 8
23  %tmp = load i64, i64* %x.addr, align 8
24  %cmp = icmp sgt i64 %tmp, 42
25  br i1 %cmp, label %if.then, label %if.end
26
27if.then:                                          ; preds = %entry
28  br label %if.end
29
30if.end:                                           ; preds = %if.then, %entry
31  ret void
32; CHECK-LABEL: test2:
33; CHECK: movq	%rdi, -8(%rsp)
34; CHECK: cmpq	$42, -8(%rsp)
35}
36
37
38
39
40@G = external global i32
41define i64 @test3() nounwind {
42  %A = ptrtoint i32* @G to i64
43  ret i64 %A
44; CHECK-LABEL: test3:
45; CHECK: movq _G@GOTPCREL(%rip), %rax
46; CHECK-NEXT: ret
47}
48
49
50
51; rdar://9289558
52@rtx_length = external global [153 x i8]
53
54define i32 @test4(i64 %idxprom9) nounwind {
55  %arrayidx10 = getelementptr inbounds [153 x i8], [153 x i8]* @rtx_length, i32 0, i64 %idxprom9
56  %tmp11 = load i8, i8* %arrayidx10, align 1
57  %conv = zext i8 %tmp11 to i32
58  ret i32 %conv
59
60; CHECK-LABEL: test4:
61; CHECK: movq	_rtx_length@GOTPCREL(%rip), %rax
62; CHECK-NEXT: movzbl	(%rax,%rdi), %eax
63; CHECK-NEXT: ret
64}
65
66
67; PR3242 - Out of range shifts should not be folded by fastisel.
68define void @test5(i32 %x, i32* %p) nounwind {
69  %y = ashr i32 %x, 50000
70  store i32 %y, i32* %p
71  ret void
72
73; CHECK-LABEL: test5:
74; CHECK: movl	$50000, %ecx
75; CHECK: sarl	%cl, %edi
76; CHECK: ret
77}
78
79; rdar://9289501 - fast isel should fold trivial multiplies to shifts.
80define i64 @test6(i64 %x) nounwind ssp {
81entry:
82  %mul = mul nsw i64 %x, 8
83  ret i64 %mul
84
85; CHECK-LABEL: test6:
86; CHECK: shlq	$3, %rdi
87}
88
89define i32 @test7(i32 %x) nounwind ssp {
90entry:
91  %mul = mul nsw i32 %x, 8
92  ret i32 %mul
93; CHECK-LABEL: test7:
94; CHECK: shll	$3, %edi
95}
96
97
98; rdar://9289507 - folding of immediates into 64-bit operations.
99define i64 @test8(i64 %x) nounwind ssp {
100entry:
101  %add = add nsw i64 %x, 7
102  ret i64 %add
103
104; CHECK-LABEL: test8:
105; CHECK: addq	$7, %rdi
106}
107
108define i64 @test9(i64 %x) nounwind ssp {
109entry:
110  %add = mul nsw i64 %x, 7
111  ret i64 %add
112; CHECK-LABEL: test9:
113; CHECK: imulq	$7, %rdi, %rax
114}
115
116; rdar://9297011 - Don't reject udiv by a power of 2.
117define i32 @test10(i32 %X) nounwind {
118  %Y = udiv i32 %X, 8
119  ret i32 %Y
120; CHECK-LABEL: test10:
121; CHECK: shrl	$3,
122}
123
124define i32 @test11(i32 %X) nounwind {
125  %Y = sdiv exact i32 %X, 8
126  ret i32 %Y
127; CHECK-LABEL: test11:
128; CHECK: sarl	$3,
129}
130
131
132; rdar://9297006 - Trunc to bool.
133define void @test12(i8 %tmp) nounwind ssp noredzone {
134entry:
135  %tobool = trunc i8 %tmp to i1
136  br i1 %tobool, label %if.then, label %if.end
137
138if.then:                                          ; preds = %entry
139  call void @test12(i8 0) noredzone
140  br label %if.end
141
142if.end:                                           ; preds = %if.then, %entry
143  ret void
144; CHECK-LABEL: test12:
145; CHECK: testb	$1,
146; CHECK-NEXT: je L
147; CHECK-NEXT: xorl %edi, %edi
148; CHECK-NEXT: callq
149}
150
151declare void @test13f(i1 %X)
152
153define void @test13() nounwind {
154  call void @test13f(i1 0)
155  ret void
156; CHECK-LABEL: test13:
157; CHECK: xorl %edi, %edi
158; CHECK-NEXT: callq
159}
160
161
162
163; rdar://9297003 - fast isel bails out on all functions taking bools
164define void @test14(i8 %tmp) nounwind ssp noredzone {
165entry:
166  %tobool = trunc i8 %tmp to i1
167  call void @test13f(i1 zeroext %tobool) noredzone
168  ret void
169; CHECK-LABEL: test14:
170; CHECK: andb	$1,
171; CHECK: callq
172}
173
174declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1)
175
176; rdar://9289488 - fast-isel shouldn't bail out on llvm.memcpy
177define void @test15(i8* %a, i8* %b) nounwind {
178  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 4, i32 4, i1 false)
179  ret void
180; CHECK-LABEL: test15:
181; CHECK-NEXT: movl	(%rsi), %eax
182; CHECK-NEXT: movl	%eax, (%rdi)
183; CHECK-NEXT: ret
184}
185
186; Handling for varargs calls
187declare void @test16callee(...) nounwind
188define void @test16() nounwind {
189; CHECK-LABEL: test16:
190; CHECK: movl $1, %edi
191; CHECK: movb $0, %al
192; CHECK: callq _test16callee
193  call void (...) @test16callee(i32 1)
194  br label %block2
195
196block2:
197; CHECK: movsd LCP{{.*}}_{{.*}}(%rip), %xmm0
198; CHECK: movb $1, %al
199; CHECK: callq _test16callee
200
201; AVX: vmovsd LCP{{.*}}_{{.*}}(%rip), %xmm0
202; AVX: movb $1, %al
203; AVX: callq _test16callee
204  call void (...) @test16callee(double 1.000000e+00)
205  ret void
206}
207
208
209declare void @foo() unnamed_addr ssp align 2
210
211; Verify that we don't fold the load into the compare here.  That would move it
212; w.r.t. the call.
213define i32 @test17(i32 *%P) ssp nounwind {
214entry:
215  %tmp = load i32, i32* %P
216  %cmp = icmp ne i32 %tmp, 5
217  call void @foo()
218  br i1 %cmp, label %if.then, label %if.else
219
220if.then:                                          ; preds = %entry
221  ret i32 1
222
223if.else:                                          ; preds = %entry
224  ret i32 2
225; CHECK-LABEL: test17:
226; CHECK: movl	(%rdi), %eax
227; CHECK: callq _foo
228; CHECK: cmpl	$5, %eax
229; CHECK-NEXT: je
230}
231
232; Check that 0.0 is materialized using xorps
233define void @test18(float* %p1) {
234  store float 0.0, float* %p1
235  ret void
236; CHECK-LABEL: test18:
237; CHECK: xorps
238}
239
240; Without any type hints, doubles use the smaller xorps instead of xorpd.
241define void @test19(double* %p1) {
242  store double 0.0, double* %p1
243  ret void
244; CHECK-LABEL: test19:
245; CHECK: xorps
246}
247
248; Check that we fast-isel sret
249%struct.a = type { i64, i64, i64 }
250define void @test20() nounwind ssp {
251entry:
252  %tmp = alloca %struct.a, align 8
253  call void @test20sret(%struct.a* sret %tmp)
254  ret void
255; CHECK-LABEL: test20:
256; CHECK: leaq (%rsp), %rdi
257; CHECK: callq _test20sret
258}
259declare void @test20sret(%struct.a* sret)
260
261; Check that -0.0 is not materialized using xor
262define void @test21(double* %p1) {
263  store double -0.0, double* %p1
264  ret void
265; CHECK-LABEL: test21:
266; CHECK-NOT: xor
267; CHECK: movsd	LCPI
268}
269
270; Check that immediate arguments to a function
271; do not cause massive spilling and are used
272; as immediates just before the call.
273define void @test22() nounwind {
274entry:
275  call void @foo22(i32 0)
276  call void @foo22(i32 1)
277  call void @foo22(i32 2)
278  call void @foo22(i32 3)
279  ret void
280; CHECK-LABEL: test22:
281; CHECK: xorl	%edi, %edi
282; CHECK: callq	_foo22
283; CHECK: movl	$1, %edi
284; CHECK: callq	_foo22
285; CHECK: movl	$2, %edi
286; CHECK: callq	_foo22
287; CHECK: movl	$3, %edi
288; CHECK: callq	_foo22
289}
290
291declare void @foo22(i32)
292
293; PR13563
294define void @test23(i8* noalias sret %result) {
295  %a = alloca i8
296  %b = call i8* @foo23()
297  ret void
298; CHECK-LABEL: test23:
299; CHECK: call
300; CHECK: movq  %rdi, %rax
301; CHECK: ret
302}
303
304declare i8* @foo23()
305
306declare void @takesi32ptr(i32* %arg)
307
308; CHECK-LABEL: allocamaterialize
309define void @allocamaterialize() {
310  %a = alloca i32
311; CHECK: leaq {{.*}}, %rdi
312  call void @takesi32ptr(i32* %a)
313  ret void
314}
315