1; RUN: opt < %s -licm -pass-remarks=licm -o /dev/null 2>&1 | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' %s -o /dev/null -pass-remarks=licm 2>&1 | FileCheck %s
3target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
4
5define void @hoist(i32* %array, i32* noalias %p) {
6Entry:
7  br label %Loop
8
9Loop:
10  %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ]
11  %addr = getelementptr i32, i32* %array, i32 %j
12  %a = load i32, i32* %addr
13; CHECK: remark: /tmp/kk.c:2:20: hoisting load
14  %b = load i32, i32* %p, !dbg !8
15  %a2 = add i32 %a, %b
16  store i32 %a2, i32* %addr
17  %Next = add i32 %j, 1
18  %cond = icmp eq i32 %Next, 0
19  br i1 %cond, label %Out, label %Loop
20
21Out:
22  ret void
23}
24
25define i32 @sink(i32* %array, i32* noalias %p, i32 %b) {
26Entry:
27  br label %Loop
28
29Loop:
30  %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ]
31  %addr = getelementptr i32, i32* %array, i32 %j
32  %a = load i32, i32* %addr
33  %a2 = add i32 %a, %b
34  store i32 %a2, i32* %addr
35; CHECK: remark: /tmp/kk.c:2:21: sinking add
36  %a3 = add i32 %a, 1, !dbg !9
37  %Next = add i32 %j, 1
38  %cond = icmp eq i32 %Next, 0
39  br i1 %cond, label %Out, label %Loop
40
41Out:
42  %a4 = phi i32 [ %a3, %Loop ]
43  ret i32 %a4
44}
45
46define void @promote(i32* %array, i32* noalias %p) {
47Entry:
48  br label %Loop
49
50Loop:
51  %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ]
52  %addr = getelementptr i32, i32* %array, i32 %j
53  %a = load i32, i32* %addr
54  %b = load i32, i32* %p
55  %a2 = add i32 %a, %b
56  store i32 %a2, i32* %addr
57; CHECK: remark: /tmp/kk.c:2:22: Moving accesses to memory location out of the loop
58  store i32 %b, i32* %p, !dbg !10
59  %Next = add i32 %j, 1
60  %cond = icmp eq i32 %Next, 0
61  br i1 %cond, label %Out, label %Loop
62
63Out:
64  ret void
65}
66
67!llvm.dbg.cu = !{!0}
68!llvm.module.flags = !{!3, !4}
69!llvm.ident = !{!5}
70
71!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
72!1 = !DIFile(filename: "/tmp/kk.c", directory: "/tmp")
73!2 = !{}
74!3 = !{i32 2, !"Debug Info Version", i32 3}
75!4 = !{i32 1, !"PIC Level", i32 2}
76!5 = !{!"clang version 3.9.0 "}
77!6 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
78!7 = !DISubroutineType(types: !2)
79!8 = !DILocation(line: 2, column: 20, scope: !6)
80!9 = !DILocation(line: 2, column: 21, scope: !6)
81!10 = !DILocation(line: 2, column: 22, scope: !6)
82