1 ; RUN: opt < %s -S -passes='default<O1>,function(loop-versioning-licm,loop-mssa(licm))' -debug-only=loop-versioning-licm -disable-loop-unrolling 2>&1 | FileCheck %s
4 ; Test to confirm loop is a good candidate for LoopVersioningLICM
5 ; It also confirms invariant moved out of loop.
7 ; CHECK: Loop: Loop at depth 2 containing: %for.body3.us<header><latch><exiting>
8 ; CHECK-NEXT: Loop Versioning found to be beneficial
10 ; CHECK: for.cond1.for.inc17_crit_edge.us.loopexit5: ; preds = %for.body3.us
11 ; CHECK-NEXT: %add14.us.lcssa = phi float [ %add14.us, %for.body3.us ]
12 ; CHECK-NEXT: store float %add14.us.lcssa, ptr %arrayidx.us, align 4, !alias.scope !0, !noalias !0
13 ; CHECK-NEXT: br label %for.cond1.for.inc17_crit_edge.us
15 define i32 @foo(ptr nocapture %var2, ptr nocapture readonly %var3, i32 %itr) #0 {
17 %cmp38 = icmp sgt i32 %itr, 1
18 br i1 %cmp38, label %for.body3.lr.ph.us, label %for.end19
20 for.body3.us: ; preds = %for.body3.us, %for.body3.lr.ph.us
21 %0 = phi float [ %.pre, %for.body3.lr.ph.us ], [ %add14.us, %for.body3.us ]
22 %indvars.iv = phi i64 [ 1, %for.body3.lr.ph.us ], [ %indvars.iv.next, %for.body3.us ]
23 %1 = trunc i64 %indvars.iv to i32
24 %conv.us = sitofp i32 %1 to float
25 %add.us = fadd float %conv.us, %0
26 %arrayidx7.us = getelementptr inbounds float, ptr %3, i64 %indvars.iv
27 store float %add.us, ptr %arrayidx7.us, align 4
28 %2 = load float, ptr %arrayidx.us, align 4
29 %add14.us = fadd float %2, %add.us
30 store float %add14.us, ptr %arrayidx.us, align 4
31 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
32 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
33 %exitcond = icmp eq i32 %lftr.wideiv, %itr
34 br i1 %exitcond, label %for.cond1.for.inc17_crit_edge.us, label %for.body3.us
36 for.body3.lr.ph.us: ; preds = %entry, %for.cond1.for.inc17_crit_edge.us
37 %indvars.iv40 = phi i64 [ %indvars.iv.next41, %for.cond1.for.inc17_crit_edge.us ], [ 1, %entry ]
38 %arrayidx.us = getelementptr inbounds float, ptr %var2, i64 %indvars.iv40
39 %arrayidx6.us = getelementptr inbounds ptr, ptr %var3, i64 %indvars.iv40
40 %3 = load ptr, ptr %arrayidx6.us, align 8
41 %.pre = load float, ptr %arrayidx.us, align 4
42 br label %for.body3.us
44 for.cond1.for.inc17_crit_edge.us: ; preds = %for.body3.us
45 %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
46 %lftr.wideiv42 = trunc i64 %indvars.iv.next41 to i32
47 %exitcond43 = icmp eq i32 %lftr.wideiv42, %itr
48 br i1 %exitcond43, label %for.end19, label %for.body3.lr.ph.us
50 for.end19: ; preds = %for.cond1.for.inc17_crit_edge.us, %entry