1 ; RUN: opt < %s -O1 -S -loop-versioning-licm -licm 2>&1 | FileCheck %s
2 ; RUN: opt < %s -S -passes='function(loop-versioning-licm,loop-mssa(licm))' 2>&1 | FileCheck %s
4 ; CHECK-LABEL: @without_metadata(
5 define i32 @without_metadata(i32* nocapture %var1, i32* nocapture readnone %var2, i32* nocapture %var3, i32 %itr) #0 {
7 %cmp14 = icmp eq i32 %itr, 0
8 br i1 %cmp14, label %for.end13, label %for.cond1.preheader.preheader
10 for.cond1.preheader.preheader: ; preds = %entry
11 br label %for.cond1.preheader
13 for.cond1.preheader: ; preds = %for.cond1.preheader.preheader, %for.inc11
14 %j.016 = phi i32 [ %j.1.lcssa, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
15 %i.015 = phi i32 [ %inc12, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
16 %cmp212 = icmp ult i32 %j.016, %itr
17 br i1 %cmp212, label %for.body3.lr.ph, label %for.inc11
19 for.body3.lr.ph: ; preds = %for.cond1.preheader
20 %add = add i32 %i.015, %itr
21 %idxprom6 = zext i32 %i.015 to i64
22 %arrayidx7 = getelementptr inbounds i32, i32* %var3, i64 %idxprom6
25 for.body3: ; preds = %for.body3.lr.ph, %for.body3
26 %j.113 = phi i32 [ %j.016, %for.body3.lr.ph ], [ %inc, %for.body3 ]
27 %idxprom = zext i32 %j.113 to i64
28 %arrayidx = getelementptr inbounds i32, i32* %var1, i64 %idxprom
29 ; CHECK: store i32 %add, i32* %arrayidx, align 4, !alias.scope {{.*}}, !noalias {{.*}}
30 store i32 %add, i32* %arrayidx, align 4
31 %0 = load i32, i32* %arrayidx7, align 4
32 %add8 = add nsw i32 %0, %add
33 store i32 %add8, i32* %arrayidx7, align 4
34 %inc = add nuw i32 %j.113, 1
35 %cmp2 = icmp ult i32 %inc, %itr
36 br i1 %cmp2, label %for.body3, label %for.inc11.loopexit
38 for.inc11.loopexit: ; preds = %for.body3
41 for.inc11: ; preds = %for.inc11.loopexit, %for.cond1.preheader
42 %j.1.lcssa = phi i32 [ %j.016, %for.cond1.preheader ], [ %itr, %for.inc11.loopexit ]
43 %inc12 = add nuw i32 %i.015, 1
44 %cmp = icmp ult i32 %inc12, %itr
45 br i1 %cmp, label %for.cond1.preheader, label %for.end13.loopexit
47 for.end13.loopexit: ; preds = %for.inc11
50 for.end13: ; preds = %for.end13.loopexit, %entry
54 ; CHECK-LABEL: @with_metadata(
55 define i32 @with_metadata(i32* nocapture %var1, i32* nocapture readnone %var2, i32* nocapture %var3, i32 %itr) #0 {
57 %cmp14 = icmp eq i32 %itr, 0
58 br i1 %cmp14, label %for.end13, label %for.cond1.preheader.preheader
60 for.cond1.preheader.preheader: ; preds = %entry
61 br label %for.cond1.preheader
63 for.cond1.preheader: ; preds = %for.cond1.preheader.preheader, %for.inc11
64 %j.016 = phi i32 [ %j.1.lcssa, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
65 %i.015 = phi i32 [ %inc12, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
66 %cmp212 = icmp ult i32 %j.016, %itr
67 br i1 %cmp212, label %for.body3.lr.ph, label %for.inc11
69 for.body3.lr.ph: ; preds = %for.cond1.preheader
70 %add = add i32 %i.015, %itr
71 %idxprom6 = zext i32 %i.015 to i64
72 %arrayidx7 = getelementptr inbounds i32, i32* %var3, i64 %idxprom6
75 for.body3: ; preds = %for.body3.lr.ph, %for.body3
76 %j.113 = phi i32 [ %j.016, %for.body3.lr.ph ], [ %inc, %for.body3 ]
77 %idxprom = zext i32 %j.113 to i64
78 %arrayidx = getelementptr inbounds i32, i32* %var1, i64 %idxprom
79 ; CHECK-NOT: store i32 %add, i32* %arrayidx, align 4, !alias.scope {{.*}}, !noalias {{.*}}
80 store i32 %add, i32* %arrayidx, align 4
81 %0 = load i32, i32* %arrayidx7, align 4
82 %add8 = add nsw i32 %0, %add
83 store i32 %add8, i32* %arrayidx7, align 4
84 %inc = add nuw i32 %j.113, 1
85 %cmp2 = icmp ult i32 %inc, %itr
86 br i1 %cmp2, label %for.body3, label %for.inc11.loopexit, !llvm.loop !0
88 for.inc11.loopexit: ; preds = %for.body3
91 for.inc11: ; preds = %for.inc11.loopexit, %for.cond1.preheader
92 %j.1.lcssa = phi i32 [ %j.016, %for.cond1.preheader ], [ %itr, %for.inc11.loopexit ]
93 %inc12 = add nuw i32 %i.015, 1
94 %cmp = icmp ult i32 %inc12, %itr
95 br i1 %cmp, label %for.cond1.preheader, label %for.end13.loopexit
97 for.end13.loopexit: ; preds = %for.inc11
100 for.end13: ; preds = %for.end13.loopexit, %entry
104 !0 = distinct !{!0, !1}
105 !1 = !{!"llvm.loop.licm_versioning.disable"}