2016-05-05 01:45:40 +08:00
|
|
|
; RUN: opt < %s -S -loop-unroll -unroll-count=4 | FileCheck -check-prefix=CHECK_COUNT4 %s
|
|
|
|
; RUN: opt < %s -S -loop-unroll | FileCheck -check-prefix=CHECK_NOCOUNT %s
|
|
|
|
|
|
|
|
|
|
|
|
;///////////////////// TEST 1 //////////////////////////////
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; This test shows that the loop is unrolled according to the specified
|
|
|
|
; unroll factor.
|
2016-05-05 01:45:40 +08:00
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
define void @Test1() nounwind {
|
2016-05-05 01:45:40 +08:00
|
|
|
entry:
|
|
|
|
br label %loop
|
|
|
|
|
|
|
|
loop:
|
|
|
|
%iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
|
|
|
|
%inc = add i32 %iv, 1
|
|
|
|
%exitcnd = icmp uge i32 %inc, 1024
|
|
|
|
br i1 %exitcnd, label %exit, label %loop
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK_COUNT4-LABEL: @Test1
|
|
|
|
; CHECK_COUNT4: phi
|
|
|
|
; CHECK_COUNT4-NEXT: add
|
|
|
|
; CHECK_COUNT4-NEXT: add
|
|
|
|
; CHECK_COUNT4-NEXT: add
|
|
|
|
; CHECK_COUNT4-NEXT: add
|
|
|
|
; CHECK_COUNT4-NEXT: icmp
|
|
|
|
|
|
|
|
|
|
|
|
;///////////////////// TEST 2 //////////////////////////////
|
|
|
|
|
|
|
|
; This test shows that with optnone attribute, the loop is not unrolled
|
|
|
|
; even if an unroll factor was specified.
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
define void @Test2() nounwind optnone noinline {
|
2016-05-05 01:45:40 +08:00
|
|
|
entry:
|
|
|
|
br label %loop
|
|
|
|
|
|
|
|
loop:
|
|
|
|
%iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
|
|
|
|
%inc = add i32 %iv, 1
|
|
|
|
%exitcnd = icmp uge i32 %inc, 1024
|
|
|
|
br i1 %exitcnd, label %exit, label %loop
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; CHECK_COUNT4-LABEL: @Test2
|
2016-05-05 01:45:40 +08:00
|
|
|
; CHECK_COUNT4: phi
|
|
|
|
; CHECK_COUNT4-NEXT: add
|
|
|
|
; CHECK_COUNT4-NEXT: icmp
|
|
|
|
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
;///////////////////// TEST 3 //////////////////////////////
|
2016-05-05 01:45:40 +08:00
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; This test shows that this loop is fully unrolled by default.
|
2016-05-05 01:45:40 +08:00
|
|
|
|
|
|
|
@tab = common global [24 x i32] zeroinitializer, align 4
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
define i32 @Test3() {
|
2016-05-05 01:45:40 +08:00
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
for.body: ; preds = %for.body, %entry
|
|
|
|
%i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
|
|
%arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
|
|
|
|
store i32 %i.05, i32* %arrayidx, align 4
|
|
|
|
%inc = add nuw nsw i32 %i.05, 1
|
|
|
|
%exitcond = icmp eq i32 %inc, 24
|
|
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
|
|
|
|
for.end: ; preds = %for.body
|
|
|
|
ret i32 42
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; CHECK_NOCOUNT-LABEL: @Test3
|
2016-05-05 01:45:40 +08:00
|
|
|
; CHECK_NOCOUNT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: store
|
|
|
|
; CHECK_NOCOUNT-NEXT: ret
|
|
|
|
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
;///////////////////// TEST 4 //////////////////////////////
|
2016-05-05 01:45:40 +08:00
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; This test shows that with optsize attribute, this loop is not unrolled.
|
2016-05-05 01:45:40 +08:00
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
define i32 @Test4() optsize {
|
2016-05-05 01:45:40 +08:00
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
for.body: ; preds = %for.body, %entry
|
|
|
|
%i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
|
|
%arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
|
|
|
|
store i32 %i.05, i32* %arrayidx, align 4
|
|
|
|
%inc = add nuw nsw i32 %i.05, 1
|
|
|
|
%exitcond = icmp eq i32 %inc, 24
|
|
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
|
|
|
|
for.end: ; preds = %for.body
|
|
|
|
ret i32 42
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:45:55 +08:00
|
|
|
; CHECK_NOCOUNT-LABEL: @Test4
|
2016-05-05 01:45:40 +08:00
|
|
|
; CHECK_NOCOUNT: phi
|
|
|
|
; CHECK_NOCOUNT: icmp
|