1 ; RUN: opt -loop-unroll-and-jam -allow-unroll-and-jam -unroll-runtime -unroll-partial-threshold=60 < %s -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 ; CHECK-LABEL: function
7 ; The explicit metadata here should force this to be unroll and jammed 4 times (hence the %.pre60.3)
8 ; CHECK: %.pre = phi i8 [ %.pre60.3, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %.pre.pre, %for.cond1.preheader.us.preheader.new ]
9 ; CHECK: %indvars.iv.3 = phi i64 [ 0, %for.cond1.preheader.us ], [ %indvars.iv.next.3, %for.body4.us ]
10 define void @function(i8* noalias nocapture %dst, i32 %dst_stride, i8* noalias nocapture readonly %src, i32 %src_stride, i32 %A, i32 %B, i32 %C, i32 %D, i32 %width, i32 %height) {
12 %idxprom = sext i32 %src_stride to i64
13 %cmp52 = icmp sgt i32 %height, 0
14 br i1 %cmp52, label %for.cond1.preheader.lr.ph, label %for.cond.cleanup
16 for.cond1.preheader.lr.ph: ; preds = %entry
17 %cmp249 = icmp sgt i32 %width, 0
18 %idx.ext = sext i32 %dst_stride to i64
19 br i1 %cmp249, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup
21 for.cond1.preheader.us.preheader: ; preds = %for.cond1.preheader.lr.ph
22 %.pre.pre = load i8, i8* %src, align 1
23 %wide.trip.count = zext i32 %width to i64
24 br label %for.cond1.preheader.us
26 for.cond1.preheader.us: ; preds = %for.cond1.for.cond.cleanup3_crit_edge.us, %for.cond1.preheader.us.preheader
27 %.pre = phi i8 [ %.pre60, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %.pre.pre, %for.cond1.preheader.us.preheader ]
28 %srcp.056.us.pn = phi i8* [ %srcp.056.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %src, %for.cond1.preheader.us.preheader ]
29 %y.055.us = phi i32 [ %inc30.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
30 %dst.addr.054.us = phi i8* [ %add.ptr.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %dst, %for.cond1.preheader.us.preheader ]
31 %srcp.056.us = getelementptr inbounds i8, i8* %srcp.056.us.pn, i64 %idxprom
32 %.pre60 = load i8, i8* %srcp.056.us, align 1
33 br label %for.body4.us
35 for.body4.us: ; preds = %for.body4.us, %for.cond1.preheader.us
36 %0 = phi i8 [ %.pre60, %for.cond1.preheader.us ], [ %3, %for.body4.us ]
37 %1 = phi i8 [ %.pre, %for.cond1.preheader.us ], [ %2, %for.body4.us ]
38 %indvars.iv = phi i64 [ 0, %for.cond1.preheader.us ], [ %indvars.iv.next, %for.body4.us ]
39 %conv.us = zext i8 %1 to i32
40 %mul.us = mul nsw i32 %conv.us, %A
41 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
42 %arrayidx8.us = getelementptr inbounds i8, i8* %srcp.056.us.pn, i64 %indvars.iv.next
43 %2 = load i8, i8* %arrayidx8.us, align 1
44 %conv9.us = zext i8 %2 to i32
45 %mul10.us = mul nsw i32 %conv9.us, %B
46 %conv14.us = zext i8 %0 to i32
47 %mul15.us = mul nsw i32 %conv14.us, %C
48 %arrayidx19.us = getelementptr inbounds i8, i8* %srcp.056.us, i64 %indvars.iv.next
49 %3 = load i8, i8* %arrayidx19.us, align 1
50 %conv20.us = zext i8 %3 to i32
51 %mul21.us = mul nsw i32 %conv20.us, %D
52 %add11.us = add i32 %mul.us, 32
53 %add16.us = add i32 %add11.us, %mul10.us
54 %add22.us = add i32 %add16.us, %mul15.us
55 %add23.us = add i32 %add22.us, %mul21.us
56 %4 = lshr i32 %add23.us, 6
57 %conv24.us = trunc i32 %4 to i8
58 %arrayidx26.us = getelementptr inbounds i8, i8* %dst.addr.054.us, i64 %indvars.iv
59 store i8 %conv24.us, i8* %arrayidx26.us, align 1
60 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
61 br i1 %exitcond, label %for.cond1.for.cond.cleanup3_crit_edge.us, label %for.body4.us
63 for.cond1.for.cond.cleanup3_crit_edge.us: ; preds = %for.body4.us
64 %add.ptr.us = getelementptr inbounds i8, i8* %dst.addr.054.us, i64 %idx.ext
65 %inc30.us = add nuw nsw i32 %y.055.us, 1
66 %exitcond58 = icmp eq i32 %inc30.us, %height
67 br i1 %exitcond58, label %for.cond.cleanup, label %for.cond1.preheader.us, !llvm.loop !5
69 for.cond.cleanup: ; preds = %for.cond1.for.cond.cleanup3_crit_edge.us, %for.cond1.preheader.lr.ph, %entry
73 ; CHECK-LABEL: function2
74 ; The explicit metadata here should force this to be unroll and jammed, but
75 ; the count is left to thresholds. In this case 2 (hence %.pre60.1).
76 ; CHECK: %.pre = phi i8 [ %.pre60.1, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %.pre.pre, %for.cond1.preheader.us.preheader.new ]
77 ; CHECK: %indvars.iv.1 = phi i64 [ 0, %for.cond1.preheader.us ], [ %indvars.iv.next.1, %for.body4.us ]
78 define void @function2(i8* noalias nocapture %dst, i32 %dst_stride, i8* noalias nocapture readonly %src, i32 %src_stride, i32 %A, i32 %B, i32 %C, i32 %D, i32 %width, i32 %height) {
80 %idxprom = sext i32 %src_stride to i64
81 %cmp52 = icmp sgt i32 %height, 0
82 br i1 %cmp52, label %for.cond1.preheader.lr.ph, label %for.cond.cleanup
84 for.cond1.preheader.lr.ph: ; preds = %entry
85 %cmp249 = icmp sgt i32 %width, 0
86 %idx.ext = sext i32 %dst_stride to i64
87 br i1 %cmp249, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup
89 for.cond1.preheader.us.preheader: ; preds = %for.cond1.preheader.lr.ph
90 %.pre.pre = load i8, i8* %src, align 1
91 %wide.trip.count = zext i32 %width to i64
92 br label %for.cond1.preheader.us
94 for.cond1.preheader.us: ; preds = %for.cond1.for.cond.cleanup3_crit_edge.us, %for.cond1.preheader.us.preheader
95 %.pre = phi i8 [ %.pre60, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %.pre.pre, %for.cond1.preheader.us.preheader ]
96 %srcp.056.us.pn = phi i8* [ %srcp.056.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %src, %for.cond1.preheader.us.preheader ]
97 %y.055.us = phi i32 [ %inc30.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
98 %dst.addr.054.us = phi i8* [ %add.ptr.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ %dst, %for.cond1.preheader.us.preheader ]
99 %srcp.056.us = getelementptr inbounds i8, i8* %srcp.056.us.pn, i64 %idxprom
100 %.pre60 = load i8, i8* %srcp.056.us, align 1
101 br label %for.body4.us
103 for.body4.us: ; preds = %for.body4.us, %for.cond1.preheader.us
104 %0 = phi i8 [ %.pre60, %for.cond1.preheader.us ], [ %3, %for.body4.us ]
105 %1 = phi i8 [ %.pre, %for.cond1.preheader.us ], [ %2, %for.body4.us ]
106 %indvars.iv = phi i64 [ 0, %for.cond1.preheader.us ], [ %indvars.iv.next, %for.body4.us ]
107 %conv.us = zext i8 %1 to i32
108 %mul.us = mul nsw i32 %conv.us, %A
109 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
110 %arrayidx8.us = getelementptr inbounds i8, i8* %srcp.056.us.pn, i64 %indvars.iv.next
111 %2 = load i8, i8* %arrayidx8.us, align 1
112 %conv9.us = zext i8 %2 to i32
113 %mul10.us = mul nsw i32 %conv9.us, %B
114 %conv14.us = zext i8 %0 to i32
115 %mul15.us = mul nsw i32 %conv14.us, %C
116 %arrayidx19.us = getelementptr inbounds i8, i8* %srcp.056.us, i64 %indvars.iv.next
117 %3 = load i8, i8* %arrayidx19.us, align 1
118 %conv20.us = zext i8 %3 to i32
119 %mul21.us = mul nsw i32 %conv20.us, %D
120 %add11.us = add i32 %mul.us, 32
121 %add16.us = add i32 %add11.us, %mul10.us
122 %add22.us = add i32 %add16.us, %mul15.us
123 %add23.us = add i32 %add22.us, %mul21.us
124 %4 = lshr i32 %add23.us, 6
125 %conv24.us = trunc i32 %4 to i8
126 %arrayidx26.us = getelementptr inbounds i8, i8* %dst.addr.054.us, i64 %indvars.iv
127 store i8 %conv24.us, i8* %arrayidx26.us, align 1
128 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
129 br i1 %exitcond, label %for.cond1.for.cond.cleanup3_crit_edge.us, label %for.body4.us
131 for.cond1.for.cond.cleanup3_crit_edge.us: ; preds = %for.body4.us
132 %add.ptr.us = getelementptr inbounds i8, i8* %dst.addr.054.us, i64 %idx.ext
133 %inc30.us = add nuw nsw i32 %y.055.us, 1
134 %exitcond58 = icmp eq i32 %inc30.us, %height
135 br i1 %exitcond58, label %for.cond.cleanup, label %for.cond1.preheader.us, !llvm.loop !7
137 for.cond.cleanup: ; preds = %for.cond1.for.cond.cleanup3_crit_edge.us, %for.cond1.preheader.lr.ph, %entry
141 !5 = distinct !{!5, !6}
142 !6 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
143 !7 = distinct !{!7, !8}
144 !8 = !{!"llvm.loop.unroll_and_jam.enable"}