blob: d83e56635e8cff3a4bdaf10492cef23492b60d0b [file] [log] [blame]
Michael Zolotukhin8c681712015-05-12 17:20:03 +00001; Check that we don't crash on corner cases.
Dehao Chencc763442016-12-30 00:50:28 +00002; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
Chandler Carrutheab3b902017-01-26 02:13:50 +00003; RUN: opt < %s -S -passes='require<opt-remark-emit>,loop(unroll-full)' -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
Michael Zolotukhin8c681712015-05-12 17:20:03 +00004target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5
Michael Zolotukhin3a7d55b2015-07-29 18:10:29 +00006@known_constant = internal unnamed_addr constant [10 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], align 16
7
Michael Zolotukhin8c681712015-05-12 17:20:03 +00008define void @foo1() {
9entry:
10 br label %for.body
11
12for.body:
13 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
14 %idx = zext i32 undef to i64
15 %add.ptr = getelementptr inbounds i64, i64* null, i64 %idx
16 %inc = add nuw nsw i64 %phi, 1
17 %cmp = icmp ult i64 %inc, 999
18 br i1 %cmp, label %for.body, label %for.exit
19
20for.exit:
21 ret void
22}
23
24define void @foo2() {
25entry:
26 br label %for.body
27
28for.body:
29 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
30 %x = getelementptr i32, <4 x i32*> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
31 %inc = add nuw nsw i64 %phi, 1
32 %cmp = icmp ult i64 %inc, 999
33 br i1 %cmp, label %for.body, label %for.exit
34
35for.exit:
36 ret void
37}
Michael Zolotukhin3a7d55b2015-07-29 18:10:29 +000038
39define void @cmp_undef() {
40entry:
41 br label %for.body
42
43for.body: ; preds = %for.inc, %entry
44 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
45 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
46 %x1 = load i32, i32* %arrayidx1, align 4
47 %cmp = icmp eq i32 %x1, undef
48 br i1 %cmp, label %if.then, label %for.inc
49
50if.then: ; preds = %for.body
51 br label %for.inc
52
53for.inc: ; preds = %for.body, %if.then
54 %iv.1 = add nuw nsw i64 %iv.0, 1
55 %exitcond = icmp eq i64 %iv.1, 10
56 br i1 %exitcond, label %for.end, label %for.body
57
58for.end: ; preds = %for.inc
59 ret void
60}
Michael Zolotukhin9f06ef72015-07-29 18:10:33 +000061
62define void @switch() {
63entry:
64 br label %for.body
65
66for.body:
67 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
68 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
69 %x1 = load i32, i32* %arrayidx1, align 4
70 switch i32 %x1, label %l1 [
71 ]
72
73l1:
74 %x2 = add i32 %x1, 2
75 br label %for.inc
76
77for.inc:
78 %iv.1 = add nuw nsw i64 %iv.0, 1
79 %exitcond = icmp eq i64 %iv.1, 10
80 br i1 %exitcond, label %for.end, label %for.body
81
82for.end:
83 ret void
84}
Michael Zolotukhindeade192015-09-22 22:27:12 +000085
86define <4 x i32> @vec_load() {
87entry:
88 br label %for.body
89
90for.body:
91 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
92 %vec_phi = phi <4 x i32> [ <i32 0, i32 0, i32 0, i32 0>, %entry ], [ %r, %for.body ]
93 %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %phi
94 %bc = bitcast i32* %arrayidx to <4 x i32>*
95 %x = load <4 x i32>, < 4 x i32>* %bc, align 4
96 %r = add <4 x i32> %x, %vec_phi
97 %inc = add nuw nsw i64 %phi, 1
98 %cmp = icmp ult i64 %inc, 999
99 br i1 %cmp, label %for.body, label %for.exit
100
101for.exit:
102 ret <4 x i32> %r
103}
Michael Zolotukhin3898b2b2016-05-24 00:51:01 +0000104
105define void @ptrtoint_cast() optsize {
106entry:
107 br label %for.body
108
109for.body:
110 br i1 true, label %for.inc, label %if.then
111
112if.then:
113 %arraydecay = getelementptr inbounds [1 x i32], [1 x i32]* null, i64 0, i64 0
114 %x = ptrtoint i32* %arraydecay to i64
115 br label %for.inc
116
117for.inc:
118 br i1 false, label %for.body, label %for.cond.cleanup
119
120for.cond.cleanup:
121 ret void
122}
Michael Zolotukhin7216dd42016-05-24 22:59:58 +0000123
124define void @ptrtoint_cast2() {
125entry:
126 br i1 false, label %for.body.lr.ph, label %exit
127
128for.body.lr.ph:
129 br label %for.body
130
131for.body:
132 %iv = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
133 %offset = getelementptr inbounds float, float* null, i32 3
134 %bc = bitcast float* %offset to i64*
135 %inc = add nuw nsw i32 %iv, 1
136 br i1 false, label %for.body, label %exit
137
138exit:
139 ret void
140}
Michael Zolotukhin1ecdeda2016-05-26 21:42:51 +0000141
142@i = external global i32, align 4
143
144define void @folded_not_to_constantint() {
145entry:
146 br label %for.body
147
148for.body:
149 %iv = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
150 %m = phi i32* [ @i, %entry ], [ %m, %for.inc ]
151 br i1 undef, label %if.else, label %if.then
152
153if.then:
154 unreachable
155
156if.else:
157 %cmp = icmp ult i32* %m, null
158 br i1 %cmp, label %cond.false, label %for.inc
159
160cond.false:
161 unreachable
162
163for.inc:
164 %inc = add nuw nsw i32 %iv, 1
165 %cmp2 = icmp ult i32 %inc, 10
166 br i1 %cmp2, label %for.body, label %for.end
167
168for.end:
169 ret void
170}
Michael Zolotukhin15e74512016-05-27 00:55:16 +0000171
172define void @index_too_large() {
173entry:
174 br label %for.body
175
176for.body:
177 %iv = phi i64 [ -73631599, %entry ], [ %iv.next, %for.inc ]
178 br i1 undef, label %for.body2, label %for.inc
179
180for.body2:
181 %idx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv
182 %x = load i32, i32* %idx, align 1
183 br label %for.inc
184
185for.inc:
186 %iv.next = add nsw i64 %iv, -1
187 br i1 undef, label %for.body, label %for.end
188
189for.end:
190 ret void
191}
Michael Zolotukhin19edbad2016-06-06 19:21:40 +0000192
193define void @cmp_type_mismatch() {
194entry:
195 br label %for.header
196
197for.header:
198 br label %for.body
199
200for.body:
201 %d = phi i32* [ null, %for.header ]
202 %cmp = icmp eq i32* %d, null
203 br i1 undef, label %for.end, label %for.header
204
205for.end:
206 ret void
207}
Michael Zolotukhin2d3592d2016-06-23 14:31:31 +0000208
209define void @load_type_mismatch() {
210entry:
211 br label %for.body
212
213for.body:
214 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.body ]
215 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
216 %bc = bitcast i32* %arrayidx1 to i64*
217 %x1 = load i64, i64* %bc, align 4
218 %x2 = add i64 10, %x1
219 %iv.1 = add nuw nsw i64 %iv.0, 1
220 %exitcond = icmp eq i64 %iv.1, 10
221 br i1 %exitcond, label %for.end, label %for.body
222
223for.end:
224 ret void
225}