]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/issue-45222.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / issue-45222.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // compile-flags: -O
12
13 #![crate_type = "lib"]
14
15 // verify that LLVM recognizes a loop involving 0..=n and will const-fold it.
16
17 //------------------------------------------------------------------------------
18 // Example from original issue #45222
19
20 fn foo2(n: u64) -> u64 {
21     let mut count = 0;
22     for _ in 0..n {
23         for j in (0..=n).rev() {
24             count += j;
25         }
26     }
27     count
28 }
29
30 // CHECK-LABEL: @check_foo2
31 #[no_mangle]
32 pub fn check_foo2() -> u64 {
33     // CHECK: ret i64 500005000000000
34     foo2(100000)
35 }
36
37 //------------------------------------------------------------------------------
38 // Simplified example of #45222
39
40 fn triangle_inc(n: u64) -> u64 {
41     let mut count = 0;
42     for j in 0 ..= n {
43         count += j;
44     }
45     count
46 }
47
48 // CHECK-LABEL: @check_triangle_inc
49 #[no_mangle]
50 pub fn check_triangle_inc() -> u64 {
51     // CHECK: ret i64 5000050000
52     triangle_inc(100000)
53 }
54
55 //------------------------------------------------------------------------------
56 // Demo in #48012
57
58 fn foo3r(n: u64) -> u64 {
59     let mut count = 0;
60     (0..n).for_each(|_| {
61         (0 ..= n).rev().for_each(|j| {
62             count += j;
63         })
64     });
65     count
66 }
67
68 // CHECK-LABEL: @check_foo3r
69 #[no_mangle]
70 pub fn check_foo3r() -> u64 {
71     // CHECK: ret i64 500050000000
72     foo3r(10000)
73 }