[BranchProbability] Remove the restriction that known and unknown probabilities canno...
[oota-llvm.git] / test / CodeGen / X86 / materialize-one.ll
1 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK32
2 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK64
3
4 define i32 @one32() optsize {
5 entry:
6   ret i32 1
7
8 ; CHECK32-LABEL: one32
9 ; CHECK32:       xorl %eax, %eax
10 ; CHECK32-NEXT:  incl %eax
11 ; CHECK32-NEXT:  ret
12
13 ; FIXME: Figure out the best approach in 64-bit mode.
14 ; CHECK64-LABEL: one32
15 ; CHECK64:       movl $1, %eax
16 ; CHECK64-NEXT:  retq
17 }
18
19 define i32 @minus_one32() optsize {
20 entry:
21   ret i32 -1
22
23 ; CHECK32-LABEL: minus_one32
24 ; CHECK32:       xorl %eax, %eax
25 ; CHECK32-NEXT:  decl %eax
26 ; CHECK32-NEXT:  ret
27 }
28
29 define i16 @one16() optsize {
30 entry:
31   ret i16 1
32
33 ; CHECK32-LABEL: one16
34 ; CHECK32:       xorl %eax, %eax
35 ; CHECK32-NEXT:  incl %eax
36 ; CHECK32-NEXT:  retl
37 }
38
39 define i16 @minus_one16() optsize {
40 entry:
41   ret i16 -1
42
43 ; CHECK32-LABEL: minus_one16
44 ; CHECK32:       xorl %eax, %eax
45 ; CHECK32-NEXT:  decl %eax
46 ; CHECK32-NEXT:  retl
47 }
48
49 define i32 @test_rematerialization() optsize {
50 entry:
51   ; Materialize -1 (thiscall forces it into %ecx).
52   tail call x86_thiscallcc void @f(i32 -1)
53
54   ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
55   ; spilling it to the stack.
56   tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
57
58   ; -1 should be re-materialized here instead of getting spilled above.
59   ret i32 -1
60
61 ; CHECK32-LABEL: test_rematerialization
62 ; CHECK32:       xorl %ecx, %ecx
63 ; CHECK32-NEXT:  decl %ecx
64 ; CHECK32:       calll
65 ; CHECK32:       xorl %eax, %eax
66 ; CHECK32-NEXT:  decl %eax
67 ; CHECK32-NOT:   %eax
68 ; CHECK32:       retl
69 }
70
71 define i32 @test_rematerialization2(i32 %x) optsize {
72 entry:
73   ; Materialize -1 (thiscall forces it into %ecx).
74   tail call x86_thiscallcc void @f(i32 -1)
75
76   ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
77   ; spilling it to the stack.
78   tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
79
80   ; Define eflags.
81   %a = icmp ne i32 %x, 123
82   %b = zext i1 %a to i32
83   ; Cause -1 to be rematerialized right in front of the cmov, which needs eflags.
84   ; It must therefore not use the xor-dec lowering.
85   %c = select i1 %a, i32 %b, i32 -1
86   ret i32 %c
87
88 ; CHECK32-LABEL: test_rematerialization2
89 ; CHECK32:       xorl %ecx, %ecx
90 ; CHECK32-NEXT:  decl %ecx
91 ; CHECK32:       calll
92 ; CHECK32:       cmpl
93 ; CHECK32:       setne
94 ; CHECK32-NOT:   xorl
95 ; CHECK32:       movl $-1
96 ; CHECK32:       cmov
97 ; CHECK32:       retl
98 }
99
100 declare x86_thiscallcc void @f(i32)