1 ; RUN: opt < %s -S -loop-unroll -unroll-count=2 | FileCheck %s -check-prefixes=COUNT,COMMON
2 ; RUN: opt < %s -S -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=true | FileCheck %s -check-prefixes=EPILOG,COMMON
3 ; RUN: opt < %s -S -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false | FileCheck %s -check-prefixes=PROLOG,COMMON
5 ; Check that followup-attributes are applied after LoopUnroll.
7 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
9 define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {
11 %cmp1 = icmp eq i32 %n, 0
12 br i1 %cmp1, label %for.end, label %for.body
14 for.body: ; preds = %for.body, %entry
15 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
16 %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ]
17 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
18 %0 = load i32, i32* %arrayidx, align 4
19 %add = add nsw i32 %0, %sum.02
20 %indvars.iv.next = add i64 %indvars.iv, 1
21 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
22 %exitcond = icmp eq i32 %lftr.wideiv, %n
23 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !4
25 for.end: ; preds = %for.body, %entry
26 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]
30 !1 = !{!"llvm.loop.unroll.followup_all", !{!"FollowupAll"}}
31 !2 = !{!"llvm.loop.unroll.followup_unrolled", !{!"FollowupUnrolled"}}
32 !3 = !{!"llvm.loop.unroll.followup_remainder", !{!"FollowupRemainder"}}
33 !4 = distinct !{!4, !1, !2, !3}
36 ; COMMON-LABEL: @test(
39 ; COUNT: br i1 %exitcond.1, label %for.end.loopexit, label %for.body, !llvm.loop ![[LOOP:[0-9]+]]
41 ; COUNT: ![[FOLLOWUP_ALL:[0-9]+]] = !{!"FollowupAll"}
42 ; COUNT: ![[FOLLOWUP_UNROLLED:[0-9]+]] = !{!"FollowupUnrolled"}
43 ; COUNT: ![[LOOP]] = distinct !{![[LOOP]], ![[FOLLOWUP_ALL]], ![[FOLLOWUP_UNROLLED]]}
46 ; EPILOG: br i1 %niter.ncmp.7, label %for.end.loopexit.unr-lcssa.loopexit, label %for.body, !llvm.loop ![[LOOP_0:[0-9]+]]
47 ; EPILOG: br i1 %epil.iter.cmp, label %for.body.epil, label %for.end.loopexit.epilog-lcssa, !llvm.loop ![[LOOP_2:[0-9]+]]
49 ; EPILOG: ![[LOOP_0]] = distinct !{![[LOOP_0]], ![[FOLLOWUP_ALL:[0-9]+]], ![[FOLLOWUP_UNROLLED:[0-9]+]]}
50 ; EPILOG: ![[FOLLOWUP_ALL]] = !{!"FollowupAll"}
51 ; EPILOG: ![[FOLLOWUP_UNROLLED]] = !{!"FollowupUnrolled"}
52 ; EPILOG: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[FOLLOWUP_ALL]], ![[FOLLOWUP_REMAINDER:[0-9]+]]}
53 ; EPILOG: ![[FOLLOWUP_REMAINDER]] = !{!"FollowupRemainder"}
56 ; PROLOG: br i1 %prol.iter.cmp, label %for.body.prol, label %for.body.prol.loopexit.unr-lcssa, !llvm.loop ![[LOOP_0:[0-9]+]]
57 ; PROLOG: br i1 %exitcond.7, label %for.end.loopexit.unr-lcssa, label %for.body, !llvm.loop ![[LOOP_2:[0-9]+]]
59 ; PROLOG: ![[LOOP_0]] = distinct !{![[LOOP_0]], ![[FOLLOWUP_ALL:[0-9]+]], ![[FOLLOWUP_REMAINDER:[0-9]+]]}
60 ; PROLOG: ![[FOLLOWUP_ALL]] = !{!"FollowupAll"}
61 ; PROLOG: ![[FOLLOWUP_REMAINDER]] = !{!"FollowupRemainder"}
62 ; PROLOG: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[FOLLOWUP_ALL]], ![[FOLLOWUP_UNROLLED:[0-9]+]]}
63 ; PROLOG: ![[FOLLOWUP_UNROLLED]] = !{!"FollowupUnrolled"}