1; RUN: opt < %s -S -loop-unroll -unroll-count=4 | FileCheck -check-prefix=CHECK_COUNT4 %s 2; RUN: opt < %s -S -loop-unroll | FileCheck -check-prefix=CHECK_NOCOUNT %s 3 4 5;///////////////////// TEST 1 ////////////////////////////// 6 7; This test shows that the loop is unrolled according to the specified 8; unroll factor. 9 10define void @Test1() nounwind { 11entry: 12 br label %loop 13 14loop: 15 %iv = phi i32 [ 0, %entry ], [ %inc, %loop ] 16 %inc = add i32 %iv, 1 17 %exitcnd = icmp uge i32 %inc, 1024 18 br i1 %exitcnd, label %exit, label %loop 19 20exit: 21 ret void 22} 23 24; CHECK_COUNT4-LABEL: @Test1 25; CHECK_COUNT4: phi 26; CHECK_COUNT4-NEXT: add 27; CHECK_COUNT4-NEXT: add 28; CHECK_COUNT4-NEXT: add 29; CHECK_COUNT4-NEXT: add 30; CHECK_COUNT4-NEXT: icmp 31 32 33;///////////////////// TEST 2 ////////////////////////////// 34 35; This test shows that with optnone attribute, the loop is not unrolled 36; even if an unroll factor was specified. 37 38define void @Test2() nounwind optnone noinline { 39entry: 40 br label %loop 41 42loop: 43 %iv = phi i32 [ 0, %entry ], [ %inc, %loop ] 44 %inc = add i32 %iv, 1 45 %exitcnd = icmp uge i32 %inc, 1024 46 br i1 %exitcnd, label %exit, label %loop 47 48exit: 49 ret void 50} 51 52; CHECK_COUNT4-LABEL: @Test2 53; CHECK_COUNT4: phi 54; CHECK_COUNT4-NEXT: add 55; CHECK_COUNT4-NEXT: icmp 56 57 58;///////////////////// TEST 3 ////////////////////////////// 59 60; This test shows that this loop is fully unrolled by default. 61 62@tab = common global [24 x i32] zeroinitializer, align 4 63 64define i32 @Test3() { 65entry: 66 br label %for.body 67 68for.body: ; preds = %for.body, %entry 69 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 70 %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05 71 store i32 %i.05, i32* %arrayidx, align 4 72 %inc = add nuw nsw i32 %i.05, 1 73 %exitcond = icmp eq i32 %inc, 24 74 br i1 %exitcond, label %for.end, label %for.body 75 76for.end: ; preds = %for.body 77 ret i32 42 78} 79 80; CHECK_NOCOUNT-LABEL: @Test3 81; CHECK_NOCOUNT: store 82; CHECK_NOCOUNT-NEXT: store 83; CHECK_NOCOUNT-NEXT: store 84; CHECK_NOCOUNT-NEXT: store 85; CHECK_NOCOUNT-NEXT: store 86; CHECK_NOCOUNT-NEXT: store 87; CHECK_NOCOUNT-NEXT: store 88; CHECK_NOCOUNT-NEXT: store 89; CHECK_NOCOUNT-NEXT: store 90; CHECK_NOCOUNT-NEXT: store 91; CHECK_NOCOUNT-NEXT: store 92; CHECK_NOCOUNT-NEXT: store 93; CHECK_NOCOUNT-NEXT: store 94; CHECK_NOCOUNT-NEXT: store 95; CHECK_NOCOUNT-NEXT: store 96; CHECK_NOCOUNT-NEXT: store 97; CHECK_NOCOUNT-NEXT: store 98; CHECK_NOCOUNT-NEXT: store 99; CHECK_NOCOUNT-NEXT: store 100; CHECK_NOCOUNT-NEXT: store 101; CHECK_NOCOUNT-NEXT: store 102; CHECK_NOCOUNT-NEXT: store 103; CHECK_NOCOUNT-NEXT: store 104; CHECK_NOCOUNT-NEXT: store 105; CHECK_NOCOUNT-NEXT: ret 106 107 108;///////////////////// TEST 4 ////////////////////////////// 109 110; This test shows that with optsize attribute, this loop is not unrolled. 111 112define i32 @Test4() optsize { 113entry: 114 br label %for.body 115 116for.body: ; preds = %for.body, %entry 117 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 118 %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05 119 store i32 %i.05, i32* %arrayidx, align 4 120 %inc = add nuw nsw i32 %i.05, 1 121 %exitcond = icmp eq i32 %inc, 24 122 br i1 %exitcond, label %for.end, label %for.body 123 124for.end: ; preds = %for.body 125 ret i32 42 126} 127 128; CHECK_NOCOUNT-LABEL: @Test4 129; CHECK_NOCOUNT: phi 130; CHECK_NOCOUNT: icmp 131