X86: when we are auto-detecting the subtarget features, make sure we turn on
[oota-llvm.git] / test / CodeGen / X86 / rd-mod-wr-eflags.ll
1 ; RUN: llc < %s -march=x86-64 | FileCheck %s
2
3 %struct.obj = type { i64 }
4
5 ; CHECK: _Z7releaseP3obj
6 define void @_Z7releaseP3obj(%struct.obj* nocapture %o) nounwind uwtable ssp {
7 entry:
8 ; CHECK: decq   (%{{rdi|rcx}})
9 ; CHECK-NEXT: je
10   %refcnt = getelementptr inbounds %struct.obj* %o, i64 0, i32 0
11   %0 = load i64* %refcnt, align 8, !tbaa !0
12   %dec = add i64 %0, -1
13   store i64 %dec, i64* %refcnt, align 8, !tbaa !0
14   %tobool = icmp eq i64 %dec, 0
15   br i1 %tobool, label %if.end, label %return
16
17 if.end:                                           ; preds = %entry
18   %1 = bitcast %struct.obj* %o to i8*
19   tail call void @free(i8* %1)
20   br label %return
21
22 return:                                           ; preds = %entry, %if.end
23   ret void
24 }
25
26 @c = common global i64 0, align 8
27 @a = common global i32 0, align 4
28 @.str = private unnamed_addr constant [5 x i8] c"%ld\0A\00", align 1
29 @b = common global i32 0, align 4
30
31 ; CHECK: test
32 define i32 @test() nounwind uwtable ssp {
33 entry:
34 ; CHECK: decq
35 ; CHECK-NOT: decq
36 %0 = load i64* @c, align 8, !tbaa !0
37 %dec.i = add nsw i64 %0, -1
38 store i64 %dec.i, i64* @c, align 8, !tbaa !0
39 %tobool.i = icmp ne i64 %dec.i, 0
40 %lor.ext.i = zext i1 %tobool.i to i32
41 store i32 %lor.ext.i, i32* @a, align 4, !tbaa !3
42 %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i64 %dec.i) nounwind
43 ret i32 0
44 }
45
46 ; CHECK: test2
47 define i32 @test2() nounwind uwtable ssp {
48 entry:
49 ; CHECK-NOT: decq ({{.*}})
50 %0 = load i64* @c, align 8, !tbaa !0
51 %dec.i = add nsw i64 %0, -1
52 store i64 %dec.i, i64* @c, align 8, !tbaa !0
53 %tobool.i = icmp ne i64 %0, 0
54 %lor.ext.i = zext i1 %tobool.i to i32
55 store i32 %lor.ext.i, i32* @a, align 4, !tbaa !3
56 %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i64 %dec.i) nounwind
57 ret i32 0
58 }
59
60 declare i32 @printf(i8* nocapture, ...) nounwind
61
62 declare void @free(i8* nocapture) nounwind
63
64 !0 = metadata !{metadata !"long", metadata !1}
65 !1 = metadata !{metadata !"omnipotent char", metadata !2}
66 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
67 !3 = metadata !{metadata !"int", metadata !1}
68
69 %struct.obj2 = type { i64, i32, i16, i8 }
70
71 declare void @other(%struct.obj2* ) nounwind;
72
73 ; CHECK: example_dec
74 define void @example_dec(%struct.obj2* %o) nounwind uwtable ssp {
75 ; 64 bit dec
76 entry:
77   %s64 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 0
78 ; CHECK-NOT: load 
79   %0 = load i64* %s64, align 8
80 ; CHECK: decq ({{.*}})
81   %dec = add i64 %0, -1
82   store i64 %dec, i64* %s64, align 8
83   %tobool = icmp eq i64 %dec, 0
84   br i1 %tobool, label %if.end, label %return
85
86 ; 32 bit dec
87 if.end:
88   %s32 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 1
89 ; CHECK-NOT: load 
90   %1 = load i32* %s32, align 4
91 ; CHECK: decl {{[0-9][0-9]*}}({{.*}})
92   %dec1 = add i32 %1, -1
93   store i32 %dec1, i32* %s32, align 4
94   %tobool2 = icmp eq i32 %dec1, 0
95   br i1 %tobool2, label %if.end1, label %return
96
97 ; 16 bit dec
98 if.end1:
99   %s16 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 2
100 ; CHECK-NOT: load 
101   %2 = load i16* %s16, align 2
102 ; CHECK: decw {{[0-9][0-9]*}}({{.*}})
103   %dec2 = add i16 %2, -1
104   store i16 %dec2, i16* %s16, align 2
105   %tobool3 = icmp eq i16 %dec2, 0
106   br i1 %tobool3, label %if.end2, label %return
107
108 ; 8 bit dec
109 if.end2:
110   %s8 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 3
111 ; CHECK-NOT: load 
112   %3 = load i8* %s8
113 ; CHECK: decb {{[0-9][0-9]*}}({{.*}})
114   %dec3 = add i8 %3, -1
115   store i8 %dec3, i8* %s8
116   %tobool4 = icmp eq i8 %dec3, 0
117   br i1 %tobool4, label %if.end4, label %return
118
119 if.end4:
120   tail call void @other(%struct.obj2* %o) nounwind
121   br label %return
122
123 return:                                           ; preds = %if.end4, %if.end, %entry                                                                                                                                                                               
124   ret void
125 }
126
127 ; CHECK: example_inc
128 define void @example_inc(%struct.obj2* %o) nounwind uwtable ssp {
129 ; 64 bit inc
130 entry:
131   %s64 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 0
132 ; CHECK-NOT: load 
133   %0 = load i64* %s64, align 8
134 ; CHECK: incq ({{.*}})
135   %inc = add i64 %0, 1
136   store i64 %inc, i64* %s64, align 8
137   %tobool = icmp eq i64 %inc, 0
138   br i1 %tobool, label %if.end, label %return
139
140 ; 32 bit inc
141 if.end:
142   %s32 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 1
143 ; CHECK-NOT: load 
144   %1 = load i32* %s32, align 4
145 ; CHECK: incl {{[0-9][0-9]*}}({{.*}})
146   %inc1 = add i32 %1, 1
147   store i32 %inc1, i32* %s32, align 4
148   %tobool2 = icmp eq i32 %inc1, 0
149   br i1 %tobool2, label %if.end1, label %return
150
151 ; 16 bit inc
152 if.end1:
153   %s16 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 2
154 ; CHECK-NOT: load 
155   %2 = load i16* %s16, align 2
156 ; CHECK: incw {{[0-9][0-9]*}}({{.*}})
157   %inc2 = add i16 %2, 1
158   store i16 %inc2, i16* %s16, align 2
159   %tobool3 = icmp eq i16 %inc2, 0
160   br i1 %tobool3, label %if.end2, label %return
161
162 ; 8 bit inc
163 if.end2:
164   %s8 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 3
165 ; CHECK-NOT: load 
166   %3 = load i8* %s8
167 ; CHECK: incb {{[0-9][0-9]*}}({{.*}})
168   %inc3 = add i8 %3, 1
169   store i8 %inc3, i8* %s8
170   %tobool4 = icmp eq i8 %inc3, 0
171   br i1 %tobool4, label %if.end4, label %return
172
173 if.end4:
174   tail call void @other(%struct.obj2* %o) nounwind
175   br label %return
176
177 return:
178   ret void
179 }
180
181 ; Deal with TokenFactor chain
182 ; rdar://11236106
183 @foo = external global i64*, align 8
184
185 define void @test3() nounwind ssp {
186 entry:
187 ; CHECK: test3:
188 ; CHECK: decq 16(%rax)
189   %0 = load i64** @foo, align 8
190   %arrayidx = getelementptr inbounds i64* %0, i64 2
191   %1 = load i64* %arrayidx, align 8
192   %dec = add i64 %1, -1
193   store i64 %dec, i64* %arrayidx, align 8
194   %cmp = icmp eq i64 %dec, 0
195   br i1 %cmp, label %if.then, label %if.end
196
197 if.then:
198   tail call void @baz() nounwind
199   br label %if.end
200
201 if.end:
202   ret void
203 }
204
205 declare void @baz()
206
207 ; Avoid creating a cycle in the DAG which would trigger an assert in the
208 ; scheduler.
209 ; PR12565
210 ; rdar://11451474
211 @x = external global i32, align 4
212 @y = external global i32, align 4
213 @z = external global i32, align 4
214
215 define void @test4() nounwind uwtable ssp {
216 entry:
217   %0 = load i32* @x, align 4
218   %1 = load i32* @y, align 4
219   %dec = add nsw i32 %1, -1
220   store i32 %dec, i32* @y, align 4
221   %tobool.i = icmp ne i32 %dec, 0
222   %cond.i = select i1 %tobool.i, i32 %0, i32 0
223   store i32 %cond.i, i32* @z, align 4
224   ret void
225 }