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