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 -pass-remarks-missed=isel 2>&1 >/dev/null | FileCheck %s --check-prefix=STDERR --allow-empty
3 ; RUN: llc < %s -mattr=+avx -fast-isel -mcpu=core2 -O0 -regalloc=fast -asm-verbose=0 -fast-isel-abort=1 | FileCheck %s --check-prefix=AVX
5 target 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"
6 target triple = "x86_64-apple-darwin10.0.0"
8 ; Make sure that fast-isel folds the immediate into the binop even though it
10 define i32 @test1(i32 %i) nounwind ssp {
19 ; rdar://9289512 - The load should fold into the compare.
20 define void @test2(i64 %x) nounwind ssp {
22 %x.addr = alloca i64, align 8
23 store i64 %x, i64* %x.addr, align 8
24 %tmp = load i64, i64* %x.addr, align 8
25 %cmp = icmp sgt i64 %tmp, 42
26 br i1 %cmp, label %if.then, label %if.end
28 if.then: ; preds = %entry
31 if.end: ; preds = %if.then, %entry
34 ; CHECK: movq %rdi, -8(%rsp)
35 ; CHECK: cmpq $42, -8(%rsp)
41 @G = external global i32
42 define i64 @test3() nounwind {
43 %A = ptrtoint i32* @G to i64
46 ; CHECK: movq _G@GOTPCREL(%rip), %rax
53 @rtx_length = external global [153 x i8]
55 define i32 @test4(i64 %idxprom9) nounwind {
56 %arrayidx10 = getelementptr inbounds [153 x i8], [153 x i8]* @rtx_length, i32 0, i64 %idxprom9
57 %tmp11 = load i8, i8* %arrayidx10, align 1
58 %conv = zext i8 %tmp11 to i32
62 ; CHECK: movq _rtx_length@GOTPCREL(%rip), %rax
63 ; CHECK-NEXT: movzbl (%rax,%rdi), %eax
68 ; PR3242 - Out of range shifts should not be folded by fastisel.
69 define void @test5(i32 %x, i32* %p) nounwind {
70 %y = ashr i32 %x, 50000
75 ; CHECK: movl $50000, %ecx
76 ; CHECK: sarl %cl, %edi
80 ; rdar://9289501 - fast isel should fold trivial multiplies to shifts.
81 define i64 @test6(i64 %x) nounwind ssp {
83 %mul = mul nsw i64 %x, 8
87 ; CHECK: shlq $3, {{%r[a-z]+}}
90 define i32 @test7(i32 %x) nounwind ssp {
92 %mul = mul nsw i32 %x, 8
95 ; CHECK: shll $3, {{%e[a-z]+}}
99 ; rdar://9289507 - folding of immediates into 64-bit operations.
100 define i64 @test8(i64 %x) nounwind ssp {
102 %add = add nsw i64 %x, 7
105 ; CHECK-LABEL: test8:
106 ; CHECK: addq $7, {{%r[a-z]+}}
109 define i64 @test9(i64 %x) nounwind ssp {
111 %add = mul nsw i64 %x, 7
113 ; CHECK-LABEL: test9:
114 ; CHECK: imulq $7, %rdi, %rax
117 ; rdar://9297011 - Don't reject udiv by a power of 2.
118 define i32 @test10(i32 %X) nounwind {
121 ; CHECK-LABEL: test10:
125 define i32 @test11(i32 %X) nounwind {
126 %Y = sdiv exact i32 %X, 8
128 ; CHECK-LABEL: test11:
133 ; rdar://9297006 - Trunc to bool.
134 define void @test12(i8 %tmp) nounwind ssp noredzone {
136 %tobool = trunc i8 %tmp to i1
137 br i1 %tobool, label %if.then, label %if.end
139 if.then: ; preds = %entry
140 call void @test12(i8 0) noredzone
143 if.end: ; preds = %if.then, %entry
145 ; CHECK-LABEL: test12:
148 ; CHECK-NEXT: xorl %edi, %edi
152 declare void @test13f(i1 %X)
154 define void @test13() nounwind {
155 call void @test13f(i1 0)
157 ; CHECK-LABEL: test13:
158 ; CHECK: xorl %edi, %edi
164 ; rdar://9297003 - fast isel bails out on all functions taking bools
165 define void @test14(i8 %tmp) nounwind ssp noredzone {
167 %tobool = trunc i8 %tmp to i1
168 call void @test13f(i1 zeroext %tobool) noredzone
170 ; CHECK-LABEL: test14:
175 declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1)
177 ; rdar://9289488 - fast-isel shouldn't bail out on llvm.memcpy
178 define void @test15(i8* %a, i8* %b) nounwind {
179 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %a, i8* align 4 %b, i64 4, i1 false)
181 ; CHECK-LABEL: test15:
182 ; CHECK-NEXT: movl (%rsi), %eax
183 ; CHECK-NEXT: movl %eax, (%rdi)
187 ; Handling for varargs calls
188 declare void @test16callee(...) nounwind
189 define void @test16() nounwind {
190 ; CHECK-LABEL: test16:
191 ; CHECK: movl $1, %edi
192 ; CHECK: movb $0, %al
193 ; CHECK: callq _test16callee
194 call void (...) @test16callee(i32 1)
198 ; CHECK: movsd LCP{{.*}}_{{.*}}(%rip), %xmm0
199 ; CHECK: movb $1, %al
200 ; CHECK: callq _test16callee
202 ; AVX: vmovsd LCP{{.*}}_{{.*}}(%rip), %xmm0
204 ; AVX: callq _test16callee
205 call void (...) @test16callee(double 1.000000e+00)
210 declare void @foo() unnamed_addr ssp align 2
212 ; Verify that we don't fold the load into the compare here. That would move it
214 define i32 @test17(i32 *%P) ssp nounwind {
216 %tmp = load i32, i32* %P
217 %cmp = icmp ne i32 %tmp, 5
219 br i1 %cmp, label %if.then, label %if.else
221 if.then: ; preds = %entry
224 if.else: ; preds = %entry
226 ; CHECK-LABEL: test17:
227 ; CHECK: movl (%rdi), %eax
229 ; CHECK: cmpl $5, %eax
233 ; Check that 0.0 is materialized using xorps
234 define void @test18(float* %p1) {
235 store float 0.0, float* %p1
237 ; CHECK-LABEL: test18:
241 ; Without any type hints, doubles use the smaller xorps instead of xorpd.
242 define void @test19(double* %p1) {
243 store double 0.0, double* %p1
245 ; CHECK-LABEL: test19:
249 ; Check that we fast-isel sret
250 %struct.a = type { i64, i64, i64 }
251 define void @test20() nounwind ssp {
253 %tmp = alloca %struct.a, align 8
254 call void @test20sret(%struct.a* sret %tmp)
256 ; CHECK-LABEL: test20:
257 ; CHECK: movq %rsp, %rdi
258 ; CHECK: callq _test20sret
260 declare void @test20sret(%struct.a* sret)
262 ; Check that -0.0 is not materialized using xor
263 define void @test21(double* %p1) {
264 store double -0.0, double* %p1
266 ; CHECK-LABEL: test21:
271 ; Check that immediate arguments to a function
272 ; do not cause massive spilling and are used
273 ; as immediates just before the call.
274 define void @test22() nounwind {
276 call void @foo22(i32 0)
277 call void @foo22(i32 1)
278 call void @foo22(i32 2)
279 call void @foo22(i32 3)
281 ; CHECK-LABEL: test22:
282 ; CHECK: xorl %edi, %edi
283 ; CHECK: callq _foo22
284 ; CHECK: movl $1, %edi
285 ; CHECK: callq _foo22
286 ; CHECK: movl $2, %edi
287 ; CHECK: callq _foo22
288 ; CHECK: movl $3, %edi
289 ; CHECK: callq _foo22
292 declare void @foo22(i32)
295 define void @test23(i8* noalias sret %result) {
297 %b = call i8* @foo23()
299 ; CHECK-LABEL: test23:
300 ; CHECK: movq %rdi, [[STACK:[0-9]+\(%rsp\)]]
302 ; CHECK: movq [[STACK]], %rcx
303 ; CHECK: movq %rcx, %rax
309 declare void @takesi32ptr(i32* %arg)
311 ; CHECK-LABEL: allocamaterialize
312 define void @allocamaterialize() {
314 ; CHECK: leaq {{.*}}, %rdi
315 call void @takesi32ptr(i32* %a)
319 ; STDERR-NOT: FastISel missed terminator: ret void
320 ; CHECK-LABEL: win64ccfun
321 define win64cc void @win64ccfun(i32 %i) {