1 ; RUN: llc < %s -march=x86-64 | FileCheck %s
3 %struct.obj = type { i64 }
5 ; CHECK: _Z7releaseP3obj
6 define void @_Z7releaseP3obj(%struct.obj* nocapture %o) nounwind uwtable ssp {
8 ; CHECK: decq (%{{rdi|rcx}})
10 %refcnt = getelementptr inbounds %struct.obj* %o, i64 0, i32 0
11 %0 = load i64* %refcnt, align 8, !tbaa !0
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
17 if.end: ; preds = %entry
18 %1 = bitcast %struct.obj* %o to i8*
19 tail call void @free(i8* %1)
22 return: ; preds = %entry, %if.end
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
32 define i32 @test() nounwind uwtable ssp {
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
47 define i32 @test2() nounwind uwtable ssp {
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
60 declare i32 @printf(i8* nocapture, ...) nounwind
62 declare void @free(i8* nocapture) nounwind
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}
69 %struct.obj2 = type { i64, i32, i16, i8 }
71 declare void @other(%struct.obj2* ) nounwind;
74 define void @example_dec(%struct.obj2* %o) nounwind uwtable ssp {
77 %s64 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 0
78 ; CHECK-NOT: load (%{{rdi|rcs}})
79 %0 = load i64* %s64, align 8
80 ; CHECK: decq (%{{rdi|rcs}})
82 store i64 %dec, i64* %s64, align 8
83 %tobool = icmp eq i64 %dec, 0
84 br i1 %tobool, label %if.end, label %return
88 %s32 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 1
89 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
90 %1 = load i32* %s32, align 4
91 ; CHECK: decl {{[0-9][0-9]*}}(%{{rdi|rcs}})
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
99 %s16 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 2
100 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
101 %2 = load i16* %s16, align 2
102 ; CHECK: decw {{[0-9][0-9]*}}(%{{rdi|rcs}})
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
110 %s8 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 3
111 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
113 ; CHECK: decb {{[0-9][0-9]*}}(%{{rdi|rcs}})
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
120 tail call void @other(%struct.obj2* %o) nounwind
123 return: ; preds = %if.end4, %if.end, %entry
128 define void @example_inc(%struct.obj2* %o) nounwind uwtable ssp {
131 %s64 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 0
132 ; CHECK-NOT: load (%{{rdi|rcs}})
133 %0 = load i64* %s64, align 8
134 ; CHECK: incq (%{{rdi|rcs}})
136 store i64 %inc, i64* %s64, align 8
137 %tobool = icmp eq i64 %inc, 0
138 br i1 %tobool, label %if.end, label %return
142 %s32 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 1
143 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
144 %1 = load i32* %s32, align 4
145 ; CHECK: incl {{[0-9][0-9]*}}(%{{rdi|rcs}})
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
153 %s16 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 2
154 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
155 %2 = load i16* %s16, align 2
156 ; CHECK: incw {{[0-9][0-9]*}}(%{{rdi|rcs}})
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
164 %s8 = getelementptr inbounds %struct.obj2* %o, i64 0, i32 3
165 ; CHECK-NOT: load {{[0-9][0-9]*}}(%{{rdi|rcs}})
167 ; CHECK: incb {{[0-9][0-9]*}}(%{{rdi|rcs}})
169 store i8 %inc3, i8* %s8
170 %tobool4 = icmp eq i8 %inc3, 0
171 br i1 %tobool4, label %if.end4, label %return
174 tail call void @other(%struct.obj2* %o) nounwind