1cee313d2SEric Christopher; REQUIRES: asserts
2cee313d2SEric Christopher; RUN: opt < %s -disable-output -stats -loop-unroll -unroll-runtime -unroll-partial-threshold=200 -unroll-threshold=400 -info-output-file - | FileCheck %s --check-prefix=STATS
3*a95796a3SArthur Eubanks; RUN: opt < %s -disable-output -stats -passes='require<opt-remark-emit>,loop-unroll' -unroll-runtime -unroll-partial-threshold=200 -unroll-threshold=400 -info-output-file - | FileCheck %s --check-prefix=STATS
4cee313d2SEric Christopher
5cee313d2SEric Christopher; Test that nested loops can be unrolled.  We need to increase threshold to do it
6cee313d2SEric Christopher
7cee313d2SEric Christopher; STATS: 2 loop-unroll - Number of loops unrolled (completely or otherwise)
8cee313d2SEric Christopher
9cee313d2SEric Christopherdefine i32 @nested(i32* nocapture %a, i32 %n, i32 %m) nounwind uwtable readonly {
10cee313d2SEric Christopherentry:
11cee313d2SEric Christopher  %cmp11 = icmp sgt i32 %n, 0
12cee313d2SEric Christopher  br i1 %cmp11, label %for.cond1.preheader.lr.ph, label %for.end7
13cee313d2SEric Christopher
14cee313d2SEric Christopherfor.cond1.preheader.lr.ph:                        ; preds = %entry
15cee313d2SEric Christopher  %cmp28 = icmp sgt i32 %m, 0
16cee313d2SEric Christopher  br label %for.cond1.preheader
17cee313d2SEric Christopher
18cee313d2SEric Christopherfor.cond1.preheader:                              ; preds = %for.inc5, %for.cond1.preheader.lr.ph
19cee313d2SEric Christopher  %indvars.iv16 = phi i64 [ 0, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next17, %for.inc5 ]
20cee313d2SEric Christopher  %sum.012 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %sum.1.lcssa, %for.inc5 ]
21cee313d2SEric Christopher  br i1 %cmp28, label %for.body3, label %for.inc5
22cee313d2SEric Christopher
23cee313d2SEric Christopherfor.body3:                                        ; preds = %for.cond1.preheader, %for.body3
24cee313d2SEric Christopher  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 0, %for.cond1.preheader ]
25cee313d2SEric Christopher  %sum.19 = phi i32 [ %add4, %for.body3 ], [ %sum.012, %for.cond1.preheader ]
26cee313d2SEric Christopher  %0 = add nsw i64 %indvars.iv, %indvars.iv16
27cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %0
28cee313d2SEric Christopher  %1 = load i32, i32* %arrayidx, align 4
29cee313d2SEric Christopher  %add4 = add nsw i32 %1, %sum.19
30cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
31cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
32cee313d2SEric Christopher  %exitcond = icmp eq i32 %lftr.wideiv, %m
33cee313d2SEric Christopher  br i1 %exitcond, label %for.inc5, label %for.body3
34cee313d2SEric Christopher
35cee313d2SEric Christopherfor.inc5:                                         ; preds = %for.body3, %for.cond1.preheader
36cee313d2SEric Christopher  %sum.1.lcssa = phi i32 [ %sum.012, %for.cond1.preheader ], [ %add4, %for.body3 ]
37cee313d2SEric Christopher  %indvars.iv.next17 = add i64 %indvars.iv16, 1
38cee313d2SEric Christopher  %lftr.wideiv18 = trunc i64 %indvars.iv.next17 to i32
39cee313d2SEric Christopher  %exitcond19 = icmp eq i32 %lftr.wideiv18, %n
40cee313d2SEric Christopher  br i1 %exitcond19, label %for.end7, label %for.cond1.preheader
41cee313d2SEric Christopher
42cee313d2SEric Christopherfor.end7:                                         ; preds = %for.inc5, %entry
43cee313d2SEric Christopher  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %sum.1.lcssa, %for.inc5 ]
44cee313d2SEric Christopher  ret i32 %sum.0.lcssa
45cee313d2SEric Christopher}
46cee313d2SEric Christopher
47