320 lines · plain
1; RUN: opt -passes=loop-unroll-and-jam -allow-unroll-and-jam -unroll-runtime < %s -S | FileCheck %s2; RUN: opt -passes=loop-unroll-and-jam -allow-unroll-and-jam -unroll-runtime -unroll-and-jam-threshold=15 < %s -S | FileCheck %s --check-prefix=CHECK-LOWTHRES3 4target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"5 6; CHECK-LABEL: test17; Basic check that these loops are by default UnJ'd8define void @test1(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {9; CHECK: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ]10; CHECK-LOWTHRES: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]11entry:12 %cmp = icmp ne i32 %J, 013 %cmp122 = icmp ne i32 %I, 014 %or.cond = and i1 %cmp, %cmp12215 br i1 %or.cond, label %for.outer.preheader, label %for.end16 17for.outer.preheader:18 br label %for.outer19 20for.outer:21 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]22 br label %for.inner23 24for.inner:25 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]26 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]27 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us28 %0 = load i32, ptr %arrayidx.us, align 429 %add.us = add i32 %0, %sum1.us30 %inc.us = add nuw i32 %j.us, 131 %exitcond = icmp eq i32 %inc.us, %J32 br i1 %exitcond, label %for.latch, label %for.inner33 34for.latch:35 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]36 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us37 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 438 %add8.us = add nuw i32 %i.us, 139 %exitcond25 = icmp eq i32 %add8.us, %I40 br i1 %exitcond25, label %for.end.loopexit, label %for.outer41 42for.end.loopexit:43 br label %for.end44 45for.end:46 ret void47}48 49 50; CHECK-LABEL: nounroll_and_jam51; #pragma nounroll_and_jam52define void @nounroll_and_jam(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {53; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]54entry:55 %cmp = icmp ne i32 %J, 056 %cmp122 = icmp ne i32 %I, 057 %or.cond = and i1 %cmp, %cmp12258 br i1 %or.cond, label %for.outer.preheader, label %for.end59 60for.outer.preheader:61 br label %for.outer62 63for.outer:64 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]65 br label %for.inner66 67for.inner:68 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]69 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]70 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us71 %0 = load i32, ptr %arrayidx.us, align 472 %add.us = add i32 %0, %sum1.us73 %inc.us = add nuw i32 %j.us, 174 %exitcond = icmp eq i32 %inc.us, %J75 br i1 %exitcond, label %for.latch, label %for.inner76 77for.latch:78 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]79 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us80 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 481 %add8.us = add nuw i32 %i.us, 182 %exitcond25 = icmp eq i32 %add8.us, %I83 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !184 85for.end.loopexit:86 br label %for.end87 88for.end:89 ret void90}91 92 93; CHECK-LABEL: unroll_and_jam_count94; #pragma unroll_and_jam(8)95define void @unroll_and_jam_count(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {96; CHECK: %i.us = phi i32 [ %add8.us.7, %for.latch ], [ 0, %for.outer.preheader.new ]97entry:98 %cmp = icmp ne i32 %J, 099 %cmp122 = icmp ne i32 %I, 0100 %or.cond = and i1 %cmp, %cmp122101 br i1 %or.cond, label %for.outer.preheader, label %for.end102 103for.outer.preheader:104 br label %for.outer105 106for.outer:107 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]108 br label %for.inner109 110for.inner:111 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]112 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]113 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us114 %0 = load i32, ptr %arrayidx.us, align 4115 %add.us = add i32 %0, %sum1.us116 %inc.us = add nuw i32 %j.us, 1117 %exitcond = icmp eq i32 %inc.us, %J118 br i1 %exitcond, label %for.latch, label %for.inner119 120for.latch:121 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]122 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us123 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 4124 %add8.us = add nuw i32 %i.us, 1125 %exitcond25 = icmp eq i32 %add8.us, %I126 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !3127 128for.end.loopexit:129 br label %for.end130 131for.end:132 ret void133}134 135 136; CHECK-LABEL: unroll_and_jam137; #pragma unroll_and_jam138define void @unroll_and_jam(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {139; CHECK: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ]140; CHECK-LOWTHRES: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ]141entry:142 %cmp = icmp ne i32 %J, 0143 %cmp122 = icmp ne i32 %I, 0144 %or.cond = and i1 %cmp, %cmp122145 br i1 %or.cond, label %for.outer.preheader, label %for.end146 147for.outer.preheader:148 br label %for.outer149 150for.outer:151 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]152 br label %for.inner153 154for.inner:155 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]156 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]157 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us158 %0 = load i32, ptr %arrayidx.us, align 4159 %add.us = add i32 %0, %sum1.us160 %inc.us = add nuw i32 %j.us, 1161 %exitcond = icmp eq i32 %inc.us, %J162 br i1 %exitcond, label %for.latch, label %for.inner163 164for.latch:165 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]166 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us167 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 4168 %add8.us = add nuw i32 %i.us, 1169 %exitcond25 = icmp eq i32 %add8.us, %I170 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !5171 172for.end.loopexit:173 br label %for.end174 175for.end:176 ret void177}178 179 180; CHECK-LABEL: nounroll181; #pragma nounroll (which we take to mean disable unroll and jam too)182define void @nounroll(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {183; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]184entry:185 %cmp = icmp ne i32 %J, 0186 %cmp122 = icmp ne i32 %I, 0187 %or.cond = and i1 %cmp, %cmp122188 br i1 %or.cond, label %for.outer.preheader, label %for.end189 190for.outer.preheader:191 br label %for.outer192 193for.outer:194 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]195 br label %for.inner196 197for.inner:198 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]199 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]200 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us201 %0 = load i32, ptr %arrayidx.us, align 4202 %add.us = add i32 %0, %sum1.us203 %inc.us = add nuw i32 %j.us, 1204 %exitcond = icmp eq i32 %inc.us, %J205 br i1 %exitcond, label %for.latch, label %for.inner206 207for.latch:208 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]209 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us210 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 4211 %add8.us = add nuw i32 %i.us, 1212 %exitcond25 = icmp eq i32 %add8.us, %I213 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !7214 215for.end.loopexit:216 br label %for.end217 218for.end:219 ret void220}221 222 223; CHECK-LABEL: unroll224; #pragma unroll (which we take to mean disable unroll and jam)225define void @unroll(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {226; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]227entry:228 %cmp = icmp ne i32 %J, 0229 %cmp122 = icmp ne i32 %I, 0230 %or.cond = and i1 %cmp, %cmp122231 br i1 %or.cond, label %for.outer.preheader, label %for.end232 233for.outer.preheader:234 br label %for.outer235 236for.outer:237 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]238 br label %for.inner239 240for.inner:241 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]242 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]243 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us244 %0 = load i32, ptr %arrayidx.us, align 4245 %add.us = add i32 %0, %sum1.us246 %inc.us = add nuw i32 %j.us, 1247 %exitcond = icmp eq i32 %inc.us, %J248 br i1 %exitcond, label %for.latch, label %for.inner249 250for.latch:251 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]252 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us253 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 4254 %add8.us = add nuw i32 %i.us, 1255 %exitcond25 = icmp eq i32 %add8.us, %I256 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !9257 258for.end.loopexit:259 br label %for.end260 261for.end:262 ret void263}264 265 266; CHECK-LABEL: nounroll_plus_unroll_and_jam267; #pragma clang loop nounroll, unroll_and_jam (which we take to mean do unroll_and_jam)268define void @nounroll_plus_unroll_and_jam(i32 %I, i32 %J, ptr noalias nocapture %A, ptr noalias nocapture readonly %B) {269; CHECK: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ]270entry:271 %cmp = icmp ne i32 %J, 0272 %cmp122 = icmp ne i32 %I, 0273 %or.cond = and i1 %cmp, %cmp122274 br i1 %or.cond, label %for.outer.preheader, label %for.end275 276for.outer.preheader:277 br label %for.outer278 279for.outer:280 %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ]281 br label %for.inner282 283for.inner:284 %j.us = phi i32 [ 0, %for.outer ], [ %inc.us, %for.inner ]285 %sum1.us = phi i32 [ 0, %for.outer ], [ %add.us, %for.inner ]286 %arrayidx.us = getelementptr inbounds i32, ptr %B, i32 %j.us287 %0 = load i32, ptr %arrayidx.us, align 4288 %add.us = add i32 %0, %sum1.us289 %inc.us = add nuw i32 %j.us, 1290 %exitcond = icmp eq i32 %inc.us, %J291 br i1 %exitcond, label %for.latch, label %for.inner292 293for.latch:294 %add.us.lcssa = phi i32 [ %add.us, %for.inner ]295 %arrayidx6.us = getelementptr inbounds i32, ptr %A, i32 %i.us296 store i32 %add.us.lcssa, ptr %arrayidx6.us, align 4297 %add8.us = add nuw i32 %i.us, 1298 %exitcond25 = icmp eq i32 %add8.us, %I299 br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop !11300 301for.end.loopexit:302 br label %for.end303 304for.end:305 ret void306}307 308 309!1 = distinct !{!1, !2}310!2 = distinct !{!"llvm.loop.unroll_and_jam.disable"}311!3 = distinct !{!3, !4}312!4 = distinct !{!"llvm.loop.unroll_and_jam.count", i32 8}313!5 = distinct !{!5, !6}314!6 = distinct !{!"llvm.loop.unroll_and_jam.enable"}315!7 = distinct !{!7, !8}316!8 = distinct !{!"llvm.loop.unroll.disable"}317!9 = distinct !{!9, !10}318!10 = distinct !{!"llvm.loop.unroll.enable"}319!11 = distinct !{!11, !8, !6}320