move an optimization for memcmp out of simplifylibcalls and into
[oota-llvm.git] / test / CodeGen / X86 / memcmp.ll
1 ; RUN: llc %s -o - -march=x86-64 | FileCheck %s
2
3 ; This tests codegen time inlining/optimization of memcmp
4 ; rdar://6480398
5
6 @.str = private constant [6 x i8] c"fooxx\00", align 1 ; <[6 x i8]*> [#uses=1]
7
8 declare i32 @memcmp(...)
9
10 define void @memcmp2(i8* %X, i8* %Y, i32* nocapture %P) nounwind {
11 entry:
12   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* %Y, i32 2) nounwind ; <i32> [#uses=1]
13   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
14   br i1 %1, label %return, label %bb
15
16 bb:                                               ; preds = %entry
17   store i32 4, i32* %P, align 4
18   ret void
19
20 return:                                           ; preds = %entry
21   ret void
22 ; CHECK: memcmp2:
23 ; CHECK: movw    (%rsi), %ax
24 ; CHECK: cmpw    %ax, (%rdi)
25 }
26
27 define void @memcmp2a(i8* %X, i32* nocapture %P) nounwind {
28 entry:
29   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 1), i32 2) nounwind ; <i32> [#uses=1]
30   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
31   br i1 %1, label %return, label %bb
32
33 bb:                                               ; preds = %entry
34   store i32 4, i32* %P, align 4
35   ret void
36
37 return:                                           ; preds = %entry
38   ret void
39 ; CHECK: memcmp2a:
40 ; CHECK: cmpw    $28527, (%rdi)
41 }
42
43
44 define void @memcmp4(i8* %X, i8* %Y, i32* nocapture %P) nounwind {
45 entry:
46   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* %Y, i32 4) nounwind ; <i32> [#uses=1]
47   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
48   br i1 %1, label %return, label %bb
49
50 bb:                                               ; preds = %entry
51   store i32 4, i32* %P, align 4
52   ret void
53
54 return:                                           ; preds = %entry
55   ret void
56 ; CHECK: memcmp4:
57 ; CHECK: movl    (%rsi), %eax
58 ; CHECK: cmpl    %eax, (%rdi)
59 }
60
61 define void @memcmp4a(i8* %X, i32* nocapture %P) nounwind {
62 entry:
63   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 1), i32 4) nounwind ; <i32> [#uses=1]
64   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
65   br i1 %1, label %return, label %bb
66
67 bb:                                               ; preds = %entry
68   store i32 4, i32* %P, align 4
69   ret void
70
71 return:                                           ; preds = %entry
72   ret void
73 ; CHECK: memcmp4a:
74 ; CHECK: cmpl $2021158767, (%rdi)
75 }
76