Source file
test/loopbce.go
1
2
3
4 package main
5
6 import "math"
7
8 func f0a(a []int) int {
9 x := 0
10 for i := range a {
11 x += a[i]
12 }
13 return x
14 }
15
16 func f0b(a []int) int {
17 x := 0
18 for i := range a {
19 b := a[i:]
20 x += b[0]
21 }
22 return x
23 }
24
25 func f0c(a []int) int {
26 x := 0
27 for i := range a {
28 b := a[:i+1]
29 x += b[0]
30 }
31 return x
32 }
33
34 func f1(a []int) int {
35 x := 0
36 for _, i := range a {
37 x += i
38 }
39 return x
40 }
41
42 func f2(a []int) int {
43 x := 0
44 for i := 1; i < len(a); i++ {
45 x += a[i]
46 }
47 return x
48 }
49
50 func f4(a [10]int) int {
51 x := 0
52 for i := 0; i < len(a); i += 2 {
53 x += a[i]
54 }
55 return x
56 }
57
58 func f5(a [10]int) int {
59 x := 0
60 for i := -10; i < len(a); i += 2 {
61 x += a[i]
62 }
63 return x
64 }
65
66 func f6(a []int) {
67 for i := range a {
68 b := a[0:i]
69 f6(b)
70 }
71 }
72
73 func g0a(a string) int {
74 x := 0
75 for i := 0; i < len(a); i++ {
76 x += int(a[i])
77 }
78 return x
79 }
80
81 func g0b(a string) int {
82 x := 0
83 for i := 0; len(a) > i; i++ {
84 x += int(a[i])
85 }
86 return x
87 }
88
89 func g0c(a string) int {
90 x := 0
91 for i := len(a); i > 0; i-- {
92 x += int(a[i-1])
93 }
94 return x
95 }
96
97 func g0d(a string) int {
98 x := 0
99 for i := len(a); 0 < i; i-- {
100 x += int(a[i-1])
101 }
102 return x
103 }
104
105 func g0e(a string) int {
106 x := 0
107 for i := len(a) - 1; i >= 0; i-- {
108 x += int(a[i])
109 }
110 return x
111 }
112
113 func g0f(a string) int {
114 x := 0
115 for i := len(a) - 1; 0 <= i; i-- {
116 x += int(a[i])
117 }
118 return x
119 }
120
121 func g1() int {
122 a := "evenlength"
123 x := 0
124 for i := 0; i < len(a); i += 2 {
125 x += int(a[i])
126 }
127 return x
128 }
129
130 func g2() int {
131 a := "evenlength"
132 x := 0
133 for i := 0; i < len(a); i += 2 {
134 j := i
135 if a[i] == 'e' {
136 j = j + 1
137 }
138 x += int(a[j])
139 }
140 return x
141 }
142
143 func g3a() {
144 a := "this string has length 25"
145 for i := 0; i < len(a); i += 5 {
146 useString(a[i:])
147 useString(a[:i+3])
148 useString(a[:i+5])
149 useString(a[:i+6])
150 }
151 }
152
153 func g3b(a string) {
154 for i := 0; i < len(a); i++ {
155 useString(a[i+1:])
156 }
157 }
158
159 func g3c(a string) {
160 for i := 0; i < len(a); i++ {
161 useString(a[:i+1])
162 }
163 }
164
165 func h1(a []byte) {
166 c := a[:128]
167 for i := range c {
168 c[i] = byte(i)
169 }
170 }
171
172 func h2(a []byte) {
173 for i := range a[:128] {
174 a[i] = byte(i)
175 }
176 }
177
178 func k0(a [100]int) [100]int {
179 for i := 10; i < 90; i++ {
180 a[i-11] = i
181 a[i-10] = i
182 a[i-5] = i
183 a[i] = i
184 a[i+5] = i
185 a[i+10] = i
186 a[i+11] = i
187 }
188 return a
189 }
190
191 func k1(a [100]int) [100]int {
192 for i := 10; i < 90; i++ {
193 useSlice(a[:i-11])
194 useSlice(a[:i-10])
195 useSlice(a[:i-5])
196 useSlice(a[:i])
197 useSlice(a[:i+5])
198 useSlice(a[:i+10])
199 useSlice(a[:i+11])
200 useSlice(a[:i+12])
201
202 }
203 return a
204 }
205
206 func k2(a [100]int) [100]int {
207 for i := 10; i < 90; i++ {
208 useSlice(a[i-11:])
209 useSlice(a[i-10:])
210 useSlice(a[i-5:])
211 useSlice(a[i:])
212 useSlice(a[i+5:])
213 useSlice(a[i+10:])
214 useSlice(a[i+11:])
215 useSlice(a[i+12:])
216 }
217 return a
218 }
219
220 func k3(a [100]int) [100]int {
221 for i := -10; i < 90; i++ {
222 a[i+9] = i
223 a[i+10] = i
224 a[i+11] = i
225 }
226 return a
227 }
228
229 func k3neg(a [100]int) [100]int {
230 for i := 89; i > -11; i-- {
231 a[i+9] = i
232 a[i+10] = i
233 a[i+11] = i
234 }
235 return a
236 }
237
238 func k3neg2(a [100]int) [100]int {
239 for i := 89; i >= -10; i-- {
240 a[i+9] = i
241 a[i+10] = i
242 a[i+11] = i
243 }
244 return a
245 }
246
247 func k4(a [100]int) [100]int {
248 min := (-1) << 63
249 for i := min; i < min+50; i++ {
250 a[i-min] = i
251 }
252 return a
253 }
254
255 func k5(a [100]int) [100]int {
256 max := (1 << 63) - 1
257 for i := max - 50; i < max; i++ {
258 a[i-max+50] = i
259 a[i-(max-70)] = i
260 }
261 return a
262 }
263
264 func d1(a [100]int) [100]int {
265 for i := 0; i < 100; i++ {
266 for j := 0; j < i; j++ {
267 a[j] = 0
268 a[j+1] = 0
269 a[j+2] = 0
270 }
271 }
272 return a
273 }
274
275 func d2(a [100]int) [100]int {
276 for i := 0; i < 100; i++ {
277 for j := 0; i > j; j++ {
278 a[j] = 0
279 a[j+1] = 0
280 a[j+2] = 0
281 }
282 }
283 return a
284 }
285
286 func d3(a [100]int) [100]int {
287 for i := 0; i <= 99; i++ {
288 for j := 0; j <= i-1; j++ {
289 a[j] = 0
290 a[j+1] = 0
291 a[j+2] = 0
292 }
293 }
294 return a
295 }
296
297 func d4() {
298 for i := int64(math.MaxInt64 - 9); i < math.MaxInt64-2; i += 4 {
299 useString("foo")
300 }
301 for i := int64(math.MaxInt64 - 8); i < math.MaxInt64-2; i += 4 {
302 useString("foo")
303 }
304 for i := int64(math.MaxInt64 - 7); i < math.MaxInt64-2; i += 4 {
305 useString("foo")
306 }
307 for i := int64(math.MaxInt64 - 6); i < math.MaxInt64-2; i += 4 {
308 useString("foo")
309 }
310 for i := int64(math.MaxInt64 - 9); i <= math.MaxInt64-2; i += 4 {
311 useString("foo")
312 }
313 for i := int64(math.MaxInt64 - 8); i <= math.MaxInt64-2; i += 4 {
314 useString("foo")
315 }
316 for i := int64(math.MaxInt64 - 7); i <= math.MaxInt64-2; i += 4 {
317 useString("foo")
318 }
319 for i := int64(math.MaxInt64 - 6); i <= math.MaxInt64-2; i += 4 {
320 useString("foo")
321 }
322 }
323
324 func d5() {
325 for i := int64(math.MinInt64 + 9); i > math.MinInt64+2; i -= 4 {
326 useString("foo")
327 }
328 for i := int64(math.MinInt64 + 8); i > math.MinInt64+2; i -= 4 {
329 useString("foo")
330 }
331 for i := int64(math.MinInt64 + 7); i > math.MinInt64+2; i -= 4 {
332 useString("foo")
333 }
334 for i := int64(math.MinInt64 + 6); i > math.MinInt64+2; i -= 4 {
335 useString("foo")
336 }
337 for i := int64(math.MinInt64 + 9); i >= math.MinInt64+2; i -= 4 {
338 useString("foo")
339 }
340 for i := int64(math.MinInt64 + 8); i >= math.MinInt64+2; i -= 4 {
341 useString("foo")
342 }
343 for i := int64(math.MinInt64 + 7); i >= math.MinInt64+2; i -= 4 {
344 useString("foo")
345 }
346 for i := int64(math.MinInt64 + 6); i >= math.MinInt64+2; i -= 4 {
347 useString("foo")
348 }
349 }
350
351 func bce1() {
352
353 a := int64(9223372036854774057)
354 b := int64(-1547)
355 z := int64(1337)
356
357 if a%z == b%z {
358 panic("invalid test: modulos should differ")
359 }
360
361 for i := b; i < a; i += z {
362 useString("foobar")
363 }
364 }
365
366 func nobce2(a string) {
367 for i := int64(0); i < int64(len(a)); i++ {
368 useString(a[i:])
369 }
370 for i := int64(0); i < int64(len(a))-31337; i++ {
371 useString(a[i:])
372 }
373 for i := int64(0); i < int64(len(a))+int64(-1<<63); i++ {
374 useString(a[i:])
375 }
376 j := int64(len(a)) - 123
377 for i := int64(0); i < j+123+int64(-1<<63); i++ {
378 useString(a[i:])
379 }
380 for i := int64(0); i < j+122+int64(-1<<63); i++ {
381
382 useString(a[i:])
383 }
384 }
385
386 func nobce3(a [100]int64) [100]int64 {
387 min := int64((-1) << 63)
388 max := int64((1 << 63) - 1)
389 for i := min; i < max; i++ {
390 a[i] = i
391 }
392 return a
393 }
394
395 func issue26116a(a []int) {
396
397 for i := 3; i > 6; i++ {
398 a[i] = 0
399 }
400 for i := 7; i < 3; i-- {
401 a[i] = 1
402 }
403 }
404
405 func stride1(x *[7]int) int {
406 s := 0
407 for i := 0; i <= 8; i += 3 {
408 s += x[i]
409 }
410 return s
411 }
412
413 func stride2(x *[7]int) int {
414 s := 0
415 for i := 0; i < 9; i += 3 {
416 s += x[i]
417 }
418 return s
419 }
420
421
422 func useString(a string) {
423 }
424
425
426 func useSlice(a []int) {
427 }
428
429 func main() {
430 }
431
View as plain text