162 lines · plain
1; RUN: llc -mtriple=hexagon -enable-pipeliner=false < %s | FileCheck %s2; Check that we generate hardware loop instructions.3 4; Case 1 : Loop with a constant number of iterations.5; CHECK-LABEL: @hwloop16; CHECK: loop0(.LBB{{.}}_{{.}},#10)7; CHECK: endloop08 9@a = common global [10 x i32] zeroinitializer, align 410define i32 @hwloop1() nounwind {11entry:12 br label %for.body13for.body:14 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]15 %arrayidx = getelementptr inbounds [10 x i32], ptr @a, i32 0, i32 %i.0116 store i32 %i.01, ptr %arrayidx, align 417 %inc = add nsw i32 %i.01, 118 %exitcond = icmp eq i32 %inc, 1019 br i1 %exitcond, label %for.end, label %for.body20for.end:21 ret i32 022}23 24; Case 2 : Loop with a run-time number of iterations.25; CHECK-LABEL: @hwloop226; CHECK: loop0(.LBB{{.}}_{{.}},r{{[0-9]+}})27; CHECK: endloop028 29define i32 @hwloop2(i32 %n, ptr nocapture %b) nounwind {30entry:31 %cmp1 = icmp sgt i32 %n, 032 br i1 %cmp1, label %for.body.preheader, label %for.end33 34for.body.preheader:35 br label %for.body36 37for.body:38 %a.03 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]39 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]40 %arrayidx = getelementptr inbounds i32, ptr %b, i32 %i.0241 %0 = load i32, ptr %arrayidx, align 442 %add = add nsw i32 %0, %a.0343 %inc = add nsw i32 %i.02, 144 %exitcond = icmp eq i32 %inc, %n45 br i1 %exitcond, label %for.end.loopexit, label %for.body46 47for.end.loopexit:48 br label %for.end49 50for.end:51 %a.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]52 ret i32 %a.0.lcssa53}54 55; Case 3 : Induction variable increment more than 1.56; CHECK-LABEL: @hwloop357; CHECK: lsr(r{{[0-9]+}},#2)58; CHECK: loop0(.LBB{{.}}_{{.}},r{{[0-9]+}})59; CHECK: endloop060 61define i32 @hwloop3(i32 %n, ptr nocapture %b) nounwind {62entry:63 %cmp1 = icmp sgt i32 %n, 064 br i1 %cmp1, label %for.body.preheader, label %for.end65 66for.body.preheader:67 br label %for.body68 69for.body:70 %a.03 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]71 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]72 %arrayidx = getelementptr inbounds i32, ptr %b, i32 %i.0273 %0 = load i32, ptr %arrayidx, align 474 %add = add nsw i32 %0, %a.0375 %inc = add nsw i32 %i.02, 476 %exitcond = icmp eq i32 %inc, %n77 br i1 %exitcond, label %for.end.loopexit, label %for.body78 79for.end.loopexit:80 br label %for.end81 82for.end:83 %a.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]84 ret i32 %a.0.lcssa85}86 87; Case 4 : Loop exit compare uses register instead of immediate value.88; CHECK-LABEL: @hwloop489; CHECK: loop0(.LBB{{.}}_{{.}},r{{[0-9]+}})90; CHECK: endloop091 92define i32 @hwloop4(i32 %n, ptr nocapture %b) nounwind {93entry:94 %cmp1 = icmp sgt i32 %n, 095 br i1 %cmp1, label %for.body.preheader, label %for.end96 97for.body.preheader:98 br label %for.body99 100for.body:101 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]102 %arrayidx = getelementptr inbounds i32, ptr %b, i32 %i.02103 store i32 %i.02, ptr %arrayidx, align 4104 %inc = add nsw i32 %i.02, 1105 %exitcond = icmp eq i32 %inc, %n106 br i1 %exitcond, label %for.end.loopexit, label %for.body107 108for.end.loopexit:109 br label %for.end110 111for.end:112 ret i32 0113}114 115; Case 5: After LSR, the initial value is 100 and the iv decrements to 0.116; CHECK-LABEL: @hwloop5117; CHECK: loop0(.LBB{{.}}_{{.}},#100)118; CHECK: endloop0119 120define void @hwloop5(ptr nocapture %a, ptr nocapture %res) nounwind {121entry:122 br label %for.body123 124for.body:125 %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]126 %arrayidx = getelementptr inbounds i32, ptr %a, i32 %i.03127 %0 = load i32, ptr %arrayidx, align 4128 %mul = mul nsw i32 %0, %0129 %arrayidx2 = getelementptr inbounds i32, ptr %res, i32 %i.03130 store i32 %mul, ptr %arrayidx2, align 4131 %inc = add nsw i32 %i.03, 1132 %exitcond = icmp eq i32 %inc, 100133 br i1 %exitcond, label %for.end, label %for.body134 135for.end:136 ret void137}138 139; Case 6: Large immediate offset140; CHECK-LABEL: @hwloop6141; CHECK-NOT: loop0(.LBB{{.}}_{{.}},#1024)142; CHECK: loop0(.LBB{{.}}_{{.}},r{{[0-9]+}})143; CHECK: endloop0144 145define void @hwloop6(ptr nocapture %a, ptr nocapture %res) nounwind {146entry:147 br label %for.body148 149for.body:150 %i.02 = phi i32 [ 0, %entry ], [ %inc, %for.body ]151 %arrayidx = getelementptr inbounds i32, ptr %a, i32 %i.02152 %0 = load i32, ptr %arrayidx, align 4153 %arrayidx1 = getelementptr inbounds i32, ptr %res, i32 %i.02154 store i32 %0, ptr %arrayidx1, align 4155 %inc = add nsw i32 %i.02, 1156 %exitcond = icmp eq i32 %inc, 1024157 br i1 %exitcond, label %for.end, label %for.body158 159for.end:160 ret void161}162