1; RUN: opt -disable-output -loop-simplify -licm -enable-new-pm=0 -print-memoryssa -enable-mssa-loop-dependency=true < %s 2>&1 | FileCheck %s
2; RUN: opt -disable-output -aa-pipeline=basic-aa -passes='loop-mssa(licm),print<memoryssa>' < %s 2>&1 | FileCheck %s
3target triple = "x86_64-unknown-linux-gnu"
4
5; CHECK-LABEL: @main()
6; CHECK: 5 = MemoryPhi(
7; CHECK-NOT: 7 = MemoryPhi(
8@v_67 = external dso_local global i32, align 1
9@v_76 = external dso_local global i16, align 1
10@v_86 = external dso_local global i16 *, align 1
11
12define dso_local void @main() {
13entry:
14  %v_59 = alloca i16, align 2
15  br label %for.cond
16
17for.cond:                                         ; preds = %for.body, %entry
18  br i1 undef, label %for.body, label %for.end
19
20for.body:                                         ; preds = %for.cond
21  store i16 undef, i16* %v_59, align 2
22  br label %for.cond
23
24for.end:                                          ; preds = %for.cond
25  br i1 undef, label %if.else568, label %cond.end82
26
27cond.false69:                                     ; No predecessors!
28  br label %cond.end82
29
30cond.end82:                                       ; preds = %cond.false69, %cond.true55
31  br i1 undef, label %if.else568, label %land.lhs.true87
32
33land.lhs.true87:                                  ; preds = %cond.end82
34  br i1 undef, label %if.then88, label %if.else568
35
36if.then88:                                        ; preds = %land.lhs.true87
37  store i16 * @v_76, i16 ** @v_86, align 1
38  br label %if.end569
39
40if.else568:                                       ; preds = %land.lhs.true87, %cond.end82, %for.end
41  store volatile i32 undef, i32 * @v_67, align 1
42  br label %if.end569
43
44if.end569:                                        ; preds = %if.else568, %if.then88
45  ret void
46}
47
48
49; CHECK-LABEL: @f()
50; CHECK: 7 = MemoryPhi(
51; CHECK: 6 = MemoryPhi(
52; CHECK: 10 = MemoryPhi(
53; CHECK: 9 = MemoryPhi(
54; CHECK: 8 = MemoryPhi(
55define void @f() {
56entry:
57  %e = alloca i16, align 1
58  br label %lbl1
59
60lbl1:                                             ; preds = %if.else, %for.end5, %entry
61  store i16 undef, i16* %e, align 1
62  %0 = load i16, i16* %e, align 1
63  %call = call i16 @g(i16 %0)
64  br i1 undef, label %for.end, label %if.else
65
66for.end:                                          ; preds = %if.then
67  br i1 true, label %for.cond2, label %lbl2
68
69lbl2:                                             ; preds = %for.body4, %if.end
70  br label %for.cond2
71
72for.cond2:                                        ; preds = %lbl3
73  br i1 undef, label %for.body4, label %for.end5
74
75for.body4:                                        ; preds = %for.cond2
76  br label %lbl2
77
78for.end5:                                         ; preds = %for.cond2
79  switch i32 undef, label %unreachable [
80    i32 0, label %if.end12
81    i32 2, label %lbl1
82  ]
83
84if.else:                                          ; preds = %lbl1
85  switch i32 undef, label %unreachable [
86    i32 0, label %if.end12
87    i32 2, label %lbl1
88  ]
89
90if.end12:                                         ; preds = %cleanup.cont11s, %cleanup.cont
91  call void @llvm.lifetime.end.p0i8(i64 1, i8* undef)
92  ret void
93
94unreachable:                                      ; preds = %if.else, %for.end5
95  unreachable
96}
97
98declare i16 @g(i16)
99
100; Function Attrs: argmemonly nounwind willreturn
101declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
102