Post-ra LICM should take care not to hoist an instruction that would clobber a
[oota-llvm.git] / test / CodeGen / X86 / dec-eflags-lower.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}