1 ; RUN: opt < %s -O1 -S -loop-versioning-licm -licm -debug-only=loop-versioning-licm 2>&1 | FileCheck %s
4 ; Test to confirm loop is a candidate for LoopVersioningLICM.
5 ; It also confirms invariant moved out of loop.
7 ; CHECK: Loop: Loop at depth 2 containing: %for.body3<header><latch><exiting>
8 ; CHECK-NEXT: Loop Versioning found to be beneficial
11 ; CHECK-NEXT: %[[induction:.*]] = phi i32 [ %arrayidx7.promoted, %for.body3.ph ], [ %add8, %for.body3 ]
12 ; CHECK-NEXT: %j.113 = phi i32 [ %j.016, %for.body3.ph ], [ %inc, %for.body3 ]
13 ; CHECK-NEXT: %idxprom = zext i32 %j.113 to i64
14 ; CHECK-NEXT: %arrayidx = getelementptr inbounds i32, i32* %var1, i64 %idxprom
15 ; CHECK-NEXT: store i32 %add, i32* %arrayidx, align 4, !alias.scope !2, !noalias !2
16 ; CHECK-NEXT: %add8 = add nsw i32 %[[induction]], %add
17 ; CHECK-NEXT: %inc = add nuw i32 %j.113, 1
18 ; CHECK-NEXT: %cmp2 = icmp ult i32 %inc, %itr
19 ; CHECK-NEXT: br i1 %cmp2, label %for.body3, label %for.inc11.loopexit.loopexit7, !llvm.loop !5
20 define i32 @foo(i32* nocapture %var1, i32* nocapture readnone %var2, i32* nocapture %var3, i32 %itr) #0 {
22 %cmp14 = icmp eq i32 %itr, 0
23 br i1 %cmp14, label %for.end13, label %for.cond1.preheader.preheader
25 for.cond1.preheader.preheader: ; preds = %entry
26 br label %for.cond1.preheader
28 for.cond1.preheader: ; preds = %for.cond1.preheader.preheader, %for.inc11
29 %j.016 = phi i32 [ %j.1.lcssa, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
30 %i.015 = phi i32 [ %inc12, %for.inc11 ], [ 0, %for.cond1.preheader.preheader ]
31 %cmp212 = icmp ult i32 %j.016, %itr
32 br i1 %cmp212, label %for.body3.lr.ph, label %for.inc11
34 for.body3.lr.ph: ; preds = %for.cond1.preheader
35 %add = add i32 %i.015, %itr
36 %idxprom6 = zext i32 %i.015 to i64
37 %arrayidx7 = getelementptr inbounds i32, i32* %var3, i64 %idxprom6
40 for.body3: ; preds = %for.body3.lr.ph, %for.body3
41 %j.113 = phi i32 [ %j.016, %for.body3.lr.ph ], [ %inc, %for.body3 ]
42 %idxprom = zext i32 %j.113 to i64
43 %arrayidx = getelementptr inbounds i32, i32* %var1, i64 %idxprom
44 store i32 %add, i32* %arrayidx, align 4
45 %0 = load i32, i32* %arrayidx7, align 4
46 %add8 = add nsw i32 %0, %add
47 store i32 %add8, i32* %arrayidx7, align 4
48 %inc = add nuw i32 %j.113, 1
49 %cmp2 = icmp ult i32 %inc, %itr
50 br i1 %cmp2, label %for.body3, label %for.inc11.loopexit
52 for.inc11.loopexit: ; preds = %for.body3
55 for.inc11: ; preds = %for.inc11.loopexit, %for.cond1.preheader
56 %j.1.lcssa = phi i32 [ %j.016, %for.cond1.preheader ], [ %itr, %for.inc11.loopexit ]
57 %inc12 = add nuw i32 %i.015, 1
58 %cmp = icmp ult i32 %inc12, %itr
59 br i1 %cmp, label %for.cond1.preheader, label %for.end13.loopexit
61 for.end13.loopexit: ; preds = %for.inc11
64 for.end13: ; preds = %for.end13.loopexit, %entry