Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 51b20e8

Browse files
author
Marianne Mailhot-Sarrasin
committed
Adding test cases showing the behavior of LoopUnrollPass according to optnone and optsize attributes
The unroll pass was disabled by clang in /Os. Those new test cases shows that the pass will behave correctly even if it is not fully disabled. This patch is related in some way to the clang commit (http://reviews.llvm.org/D19827), which re-enables the pass in /Os. Differential Revision: http://reviews.llvm.org/D19870 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268524 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 811f094 commit 51b20e8

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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 with optsize attribute, the loop is unrolled
8+
; according to the specified unroll factor.
9+
10+
define void @Test1() nounwind optsize {
11+
entry:
12+
br label %loop
13+
14+
loop:
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+
20+
exit:
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 minsize attribute, the loop is unrolled
36+
; according to the specified unroll factor.
37+
38+
define void @Test2() nounwind minsize {
39+
entry:
40+
br label %loop
41+
42+
loop:
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+
48+
exit:
49+
ret void
50+
}
51+
52+
; CHECK_COUNT4-LABEL: @Test2
53+
; CHECK_COUNT4: phi
54+
; CHECK_COUNT4-NEXT: add
55+
; CHECK_COUNT4-NEXT: add
56+
; CHECK_COUNT4-NEXT: add
57+
; CHECK_COUNT4-NEXT: add
58+
; CHECK_COUNT4-NEXT: icmp
59+
60+
61+
;///////////////////// TEST 3 //////////////////////////////
62+
63+
; This test shows that with optnone attribute, the loop is not unrolled
64+
; even if an unroll factor was specified.
65+
66+
define void @Test3() nounwind optnone noinline {
67+
entry:
68+
br label %loop
69+
70+
loop:
71+
%iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
72+
%inc = add i32 %iv, 1
73+
%exitcnd = icmp uge i32 %inc, 1024
74+
br i1 %exitcnd, label %exit, label %loop
75+
76+
exit:
77+
ret void
78+
}
79+
80+
; CHECK_COUNT4-LABEL: @Test3
81+
; CHECK_COUNT4: phi
82+
; CHECK_COUNT4-NEXT: add
83+
; CHECK_COUNT4-NEXT: icmp
84+
85+
86+
;///////////////////// TEST 4 //////////////////////////////
87+
88+
; This test shows that without any attribute, this loop is fully unrolled
89+
; by default.
90+
91+
@tab = common global [24 x i32] zeroinitializer, align 4
92+
93+
define i32 @Test4() {
94+
entry:
95+
br label %for.body
96+
97+
for.body: ; preds = %for.body, %entry
98+
%i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
99+
%arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
100+
store i32 %i.05, i32* %arrayidx, align 4
101+
%inc = add nuw nsw i32 %i.05, 1
102+
%exitcond = icmp eq i32 %inc, 24
103+
br i1 %exitcond, label %for.end, label %for.body
104+
105+
for.end: ; preds = %for.body
106+
ret i32 42
107+
}
108+
109+
; CHECK_NOCOUNT-LABEL: @Test4
110+
; CHECK_NOCOUNT: store
111+
; CHECK_NOCOUNT-NEXT: store
112+
; CHECK_NOCOUNT-NEXT: store
113+
; CHECK_NOCOUNT-NEXT: store
114+
; CHECK_NOCOUNT-NEXT: store
115+
; CHECK_NOCOUNT-NEXT: store
116+
; CHECK_NOCOUNT-NEXT: store
117+
; CHECK_NOCOUNT-NEXT: store
118+
; CHECK_NOCOUNT-NEXT: store
119+
; CHECK_NOCOUNT-NEXT: store
120+
; CHECK_NOCOUNT-NEXT: store
121+
; CHECK_NOCOUNT-NEXT: store
122+
; CHECK_NOCOUNT-NEXT: store
123+
; CHECK_NOCOUNT-NEXT: store
124+
; CHECK_NOCOUNT-NEXT: store
125+
; CHECK_NOCOUNT-NEXT: store
126+
; CHECK_NOCOUNT-NEXT: store
127+
; CHECK_NOCOUNT-NEXT: store
128+
; CHECK_NOCOUNT-NEXT: store
129+
; CHECK_NOCOUNT-NEXT: store
130+
; CHECK_NOCOUNT-NEXT: store
131+
; CHECK_NOCOUNT-NEXT: store
132+
; CHECK_NOCOUNT-NEXT: store
133+
; CHECK_NOCOUNT-NEXT: store
134+
; CHECK_NOCOUNT-NEXT: ret
135+
136+
137+
;///////////////////// TEST 5 //////////////////////////////
138+
139+
; This test shows that with optsize attribute, this loop is not unrolled
140+
; by default.
141+
142+
define i32 @Test5() optsize {
143+
entry:
144+
br label %for.body
145+
146+
for.body: ; preds = %for.body, %entry
147+
%i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
148+
%arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
149+
store i32 %i.05, i32* %arrayidx, align 4
150+
%inc = add nuw nsw i32 %i.05, 1
151+
%exitcond = icmp eq i32 %inc, 24
152+
br i1 %exitcond, label %for.end, label %for.body
153+
154+
for.end: ; preds = %for.body
155+
ret i32 42
156+
}
157+
158+
; CHECK_NOCOUNT-LABEL: @Test5
159+
; CHECK_NOCOUNT: phi
160+
; CHECK_NOCOUNT: icmp

0 commit comments

Comments
 (0)